aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/peterh/liner/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'Godeps/_workspace/src/github.com/peterh/liner/common.go')
-rw-r--r--Godeps/_workspace/src/github.com/peterh/liner/common.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/Godeps/_workspace/src/github.com/peterh/liner/common.go b/Godeps/_workspace/src/github.com/peterh/liner/common.go
index f8753a195..b6162b624 100644
--- a/Godeps/_workspace/src/github.com/peterh/liner/common.go
+++ b/Godeps/_workspace/src/github.com/peterh/liner/common.go
@@ -7,7 +7,6 @@ package liner
import (
"bufio"
- "bytes"
"container/ring"
"errors"
"fmt"
@@ -29,6 +28,10 @@ type commonState struct {
ctrlCAborts bool
r *bufio.Reader
tabStyle TabStyle
+ multiLineMode bool
+ cursorRows int
+ maxRows int
+ shouldRestart ShouldRestart
}
// TabStyle is used to select how tab completions are displayed.
@@ -174,7 +177,7 @@ func (s *State) SetCompleter(f Completer) {
return
}
s.completer = func(line string, pos int) (string, []string, string) {
- return "", f(line[:pos]), line[pos:]
+ return "", f(string([]rune(line)[:pos])), string([]rune(line)[pos:])
}
}
@@ -207,13 +210,28 @@ func (s *State) SetCtrlCAborts(aborts bool) {
s.ctrlCAborts = aborts
}
+// SetMultiLineMode sets whether line is auto-wrapped. The default is false (single line).
+func (s *State) SetMultiLineMode(mlmode bool) {
+ s.multiLineMode = mlmode
+}
+
+// ShouldRestart is passed the error generated by readNext and returns true if
+// the the read should be restarted or false if the error should be returned.
+type ShouldRestart func(err error) bool
+
+// SetShouldRestart sets the restart function that Liner will call to determine
+// whether to retry the call to, or return the error returned by, readNext.
+func (s *State) SetShouldRestart(f ShouldRestart) {
+ s.shouldRestart = f
+}
+
func (s *State) promptUnsupported(p string) (string, error) {
- if !s.inputRedirected {
+ if !s.inputRedirected || !s.terminalSupported {
fmt.Print(p)
}
linebuf, _, err := s.r.ReadLine()
if err != nil {
return "", err
}
- return string(bytes.TrimSpace(linebuf)), nil
+ return string(linebuf), nil
}