Skip to content

Commit 1995822

Browse files
authored
Merge pull request #212 from cosmtrek/clear_screen_when_rebuild
feat(*):support clear screen when rebuild
2 parents e4d3d83 + c643094 commit 1995822

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

runner/config.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ const (
2121
)
2222

2323
type config struct {
24-
Root string `toml:"root"`
25-
TmpDir string `toml:"tmp_dir"`
26-
TestDataDir string `toml:"testdata_dir"`
27-
Build cfgBuild `toml:"build"`
28-
Color cfgColor `toml:"color"`
29-
Log cfgLog `toml:"log"`
30-
Misc cfgMisc `toml:"misc"`
24+
Root string `toml:"root"`
25+
TmpDir string `toml:"tmp_dir"`
26+
TestDataDir string `toml:"testdata_dir"`
27+
Build cfgBuild `toml:"build"`
28+
Color cfgColor `toml:"color"`
29+
Log cfgLog `toml:"log"`
30+
Misc cfgMisc `toml:"misc"`
31+
Screen cfgScreen `toml:"screen"`
3132
}
3233

3334
type cfgBuild struct {
@@ -79,6 +80,10 @@ type cfgMisc struct {
7980
CleanOnExit bool `toml:"clean_on_exit"`
8081
}
8182

83+
type cfgScreen struct {
84+
ClearOnRebuild bool `toml:"clear_on_rebuild"`
85+
}
86+
8287
func initConfig(path string) (cfg *config, err error) {
8388
if path == "" {
8489
cfg, err = defaultPathConfig()

runner/engine.go

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package runner
22

33
import (
4+
"fmt"
45
"io"
56
"os"
67
"os/exec"
@@ -319,17 +320,24 @@ func (e *Engine) start() {
319320
continue
320321
}
321322
}
323+
// clean on rebuild https://stackoverflow.com/questions/22891644/how-can-i-clear-the-terminal-screen-in-go
324+
if e.config.Screen.ClearOnRebuild {
325+
fmt.Println("\033[2J")
326+
}
322327
e.mainLog("%s has changed", e.config.rel(filename))
323328
case <-firstRunCh:
324329
// go down
325330
break
326331
}
327332

333+
// already build and run now
328334
select {
329335
case <-e.buildRunCh:
330336
e.buildRunStopCh <- true
331337
default:
332338
}
339+
340+
// if current app is running, stop it
333341
e.withLock(func() {
334342
if e.binRunning {
335343
e.binStopCh <- true

0 commit comments

Comments
 (0)