-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
HAYAMA_Kaoru
committed
Oct 8, 2021
1 parent
892a3bd
commit 7156cc5
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/zat-kaoru-hayama/WatchTemp | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/mattn/go-colorable v0.1.11 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs= | ||
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= | ||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= | ||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= | ||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo= | ||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/mattn/go-colorable" | ||
) | ||
|
||
const ( | ||
_STAMP_STYLE = "15:04:05.000" | ||
) | ||
|
||
func mains() error { | ||
if dispose := colorable.EnableColorsStdout(nil); dispose != nil { | ||
defer dispose() | ||
} | ||
out := colorable.NewColorableStdout() | ||
|
||
tempPath := os.TempDir() | ||
previous := make(map[string]struct{}) | ||
filepath.Walk(tempPath, func(_path string, info fs.FileInfo, err error) error { | ||
path := _path[len(tempPath):] | ||
previous[path] = struct{}{} | ||
return nil | ||
}) | ||
|
||
tick := time.Tick(time.Second / 5) | ||
for next := range tick { | ||
current := make(map[string]struct{}) | ||
stamp := next.Format(_STAMP_STYLE) | ||
|
||
filepath.Walk(tempPath, func(_path string, info fs.FileInfo, err error) error { | ||
path := _path[len(tempPath):] | ||
if _, ok := previous[path]; ok { | ||
delete(previous, path) | ||
} else { | ||
fmt.Fprintf(out, "\x1B[32;1m%s Add %s\x1B[0m\n", stamp, path) | ||
} | ||
current[path] = struct{}{} | ||
return nil | ||
}) | ||
for path := range previous { | ||
fmt.Fprintf(out, "\x1B[31;1m%s Del %s\x1B[0m\n", stamp, path) | ||
} | ||
previous = current | ||
} | ||
return nil | ||
} | ||
|
||
func main() { | ||
if err := mains(); err != nil { | ||
fmt.Fprintln(os.Stderr, err.Error()) | ||
os.Exit(1) | ||
} | ||
} |