aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/chzyer/readline/readline.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/chzyer/readline/readline.go')
-rw-r--r--vendor/github.com/chzyer/readline/readline.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/vendor/github.com/chzyer/readline/readline.go b/vendor/github.com/chzyer/readline/readline.go
index 0e7aca06d..63b917101 100644
--- a/vendor/github.com/chzyer/readline/readline.go
+++ b/vendor/github.com/chzyer/readline/readline.go
@@ -17,7 +17,9 @@
//
package readline
-import "io"
+import (
+ "io"
+)
type Instance struct {
Config *Config
@@ -270,14 +272,24 @@ func (i *Instance) ReadSlice() ([]byte, error) {
}
// we must make sure that call Close() before process exit.
+// if there has a pending reading operation, that reading will be interrupted.
+// so you can capture the signal and call Instance.Close(), it's thread-safe.
func (i *Instance) Close() error {
+ i.Config.Stdin.Close()
+ i.Operation.Close()
if err := i.Terminal.Close(); err != nil {
return err
}
- i.Config.Stdin.Close()
- i.Operation.Close()
return nil
}
+
+// call CaptureExitSignal when you want readline exit gracefully.
+func (i *Instance) CaptureExitSignal() {
+ CaptureExitSignal(func() {
+ i.Close()
+ })
+}
+
func (i *Instance) Clean() {
i.Operation.Clean()
}