Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HAYAMA_Kaoru committed Oct 8, 2021
1 parent 892a3bd commit 7156cc5
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
9 changes: 9 additions & 0 deletions go.mod
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
)
7 changes: 7 additions & 0 deletions go.sum
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=
59 changes: 59 additions & 0 deletions main.go
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)
}
}

0 comments on commit 7156cc5

Please sign in to comment.