Skip to content

Commit

Permalink
Allow clearing the terminal before each execution
Browse files Browse the repository at this point in the history
  • Loading branch information
bduffany committed Dec 5, 2023
1 parent 09721d4 commit 62efded
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ type Config struct {
// are complete.
Lockfile *string `json:"lockfile,omitempty"`

// Clear specifies whether to clear the terminal on each re-run.
//
// Note, this option is just for convenience. The same functionality can
// be achieved with the following command:
// godemon [ flags ... ] sh -c 'clear && exec {command}'
Clear bool `json:"clear,omitempty"`

// TODO: FollowSymlinks

// Private fields below
Expand Down
10 changes: 10 additions & 0 deletions godemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func parseConfig(args []string) (*Config, error) {
signal := ""
lockfile := ""
dryRun := false
clearTerminal := false
for i := 0; i < len(args); i++ {
arg := args[i]
if isParsingCommand {
Expand Down Expand Up @@ -92,6 +93,10 @@ func parseConfig(args []string) (*Config, error) {
logLevel -= len(arg) - 1
continue
}
if arg == "--clear" {
clearTerminal = true
continue
}

// Parse string flags
for _, spec := range []struct {
Expand Down Expand Up @@ -161,6 +166,7 @@ func parseConfig(args []string) (*Config, error) {
cfg.Command = cmdArgs
cfg.Ignore = ignore
cfg.Only = only
cfg.Clear = clearTerminal
if cfg.Watch != nil && len(cfg.Watch) == 0 {
return nil, fmt.Errorf("watch list in config is empty")
}
Expand Down Expand Up @@ -461,6 +467,10 @@ func (g *godemon) loopCommand(restart <-chan struct{}, shutdownCh chan<- struct{
nShutdownAttempts := 0
var mu sync.Mutex

if g.cfg.Clear {
// Clear terminal before starting the command.
fmt.Fprint(os.Stderr, "\033[2J\033[H")
}
cmd := newCommand(g.cfg)
if err := cmd.Start(); err != nil {
fatalf("Could not start command: %s", err)
Expand Down

0 comments on commit 62efded

Please sign in to comment.