Skip to content

Commit

Permalink
feat(core): clear screen after recompile in watch mode
Browse files Browse the repository at this point in the history
- use '\033c' to clear the screen after fleck detects a file change in watch mode
- fleck watch mode now iterates every 100ms not 1s, feels like a lot less latency
  • Loading branch information
xNaCly committed Apr 19, 2023
1 parent 824879a commit 02f7d12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func WatchForChanges(fileName string, executor func(string)) {
logger.LError("failed to watch for changes: " + err.Error())
}

i := 0
for {
stat, err := os.Stat(fileName)
if err != nil {
Expand All @@ -44,11 +45,13 @@ func WatchForChanges(fileName string, executor func(string)) {

if stat.Size() != initialStat.Size() || stat.ModTime() != stat.ModTime() {
initialStat = stat
logger.LInfo("detected change, recompiling...")
i++
fmt.Print(logger.ANSI_CLEAR)
logger.LInfo("detected change, recompiling... (" + fmt.Sprint(i) + ")")
executor(fileName)
}

time.Sleep(1 * time.Second)
time.Sleep(100 * time.Millisecond)
}
}

Expand Down
1 change: 1 addition & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

const (
ANSI_RESET = "\033[0m"
ANSI_CLEAR = "\033c"
ANSI_RED = "\033[91m"
ANSI_YELLOW = "\033[93m"
ANSI_BLUE = "\033[94m"
Expand Down

0 comments on commit 02f7d12

Please sign in to comment.