-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from dnephin/watch-retest
Add rerun for --watch mode
- Loading branch information
Showing
6 changed files
with
122 additions
and
5 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
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,8 @@ | ||
// +build darwin dragonfly freebsd netbsd openbsd | ||
|
||
package filewatcher | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
const tcGet = unix.TIOCGETA | ||
const tcSet = unix.TIOCSETA |
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,6 @@ | ||
package filewatcher | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
const tcGet = unix.TCGETS | ||
const tcSet = unix.TCSETS |
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,67 @@ | ||
// +build !windows | ||
|
||
package filewatcher | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
"gotest.tools/gotestsum/log" | ||
) | ||
|
||
func enableNonBlockingRead(fd int) (func(), error) { | ||
term, err := unix.IoctlGetTermios(fd, tcGet) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
state := *term | ||
reset := func() { | ||
if err := unix.IoctlSetTermios(fd, tcSet, &state); err != nil { | ||
log.Debugf("failed to reset fd %d: %v", fd, err) | ||
} | ||
} | ||
|
||
term.Lflag &^= unix.ECHO | unix.ICANON | ||
term.Cc[unix.VMIN] = 1 | ||
term.Cc[unix.VTIME] = 0 | ||
if err := unix.IoctlSetTermios(fd, tcSet, term); err != nil { | ||
reset() | ||
return nil, err | ||
} | ||
return reset, nil | ||
} | ||
|
||
func (r *redoHandler) run(ctx context.Context) { | ||
fd := int(os.Stdin.Fd()) | ||
reset, err := enableNonBlockingRead(fd) | ||
if err != nil { | ||
log.Debugf("failed to put terminal (fd %d) into raw mode: %v", fd, err) | ||
return | ||
} | ||
defer reset() | ||
|
||
in := bufio.NewReader(os.Stdin) | ||
for { | ||
if ctx.Err() != nil { | ||
return | ||
} | ||
|
||
char, err := in.ReadByte() | ||
if err != nil { | ||
log.Warnf("failed to read input: %v", err) | ||
return | ||
} | ||
log.Debugf("received byte %v (%v)", char, string(char)) | ||
|
||
switch char { | ||
case 'r': | ||
r.ch <- r.prevPath | ||
case '\n': | ||
fmt.Println() | ||
} | ||
} | ||
} |
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 @@ | ||
package filewatcher | ||
|
||
import "context" | ||
|
||
func (r *redoHandler) run(_ context.Context) { | ||
return | ||
} |
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