summaryrefslogtreecommitdiffstats
path: root/libgo/go/exp/terminal/terminal.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/exp/terminal/terminal.go')
-rw-r--r--libgo/go/exp/terminal/terminal.go64
1 files changed, 34 insertions, 30 deletions
diff --git a/libgo/go/exp/terminal/terminal.go b/libgo/go/exp/terminal/terminal.go
index 809e88cacfa..c3ba5bde2ee 100644
--- a/libgo/go/exp/terminal/terminal.go
+++ b/libgo/go/exp/terminal/terminal.go
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build linux
-
package terminal
import (
@@ -463,6 +461,31 @@ func (t *Terminal) readLine() (line string, err error) {
}
for {
+ rest := t.remainder
+ lineOk := false
+ for !lineOk {
+ var key int
+ key, rest = bytesToKey(rest)
+ if key < 0 {
+ break
+ }
+ if key == keyCtrlD {
+ return "", io.EOF
+ }
+ line, lineOk = t.handleKey(key)
+ }
+ if len(rest) > 0 {
+ n := copy(t.inBuf[:], rest)
+ t.remainder = t.inBuf[:n]
+ } else {
+ t.remainder = nil
+ }
+ t.c.Write(t.outBuf)
+ t.outBuf = t.outBuf[:0]
+ if lineOk {
+ return
+ }
+
// t.remainder is a slice at the beginning of t.inBuf
// containing a partial key sequence
readBuf := t.inBuf[len(t.remainder):]
@@ -476,38 +499,19 @@ func (t *Terminal) readLine() (line string, err error) {
return
}
- if err == nil {
- t.remainder = t.inBuf[:n+len(t.remainder)]
- rest := t.remainder
- lineOk := false
- for !lineOk {
- var key int
- key, rest = bytesToKey(rest)
- if key < 0 {
- break
- }
- if key == keyCtrlD {
- return "", io.EOF
- }
- line, lineOk = t.handleKey(key)
- }
- if len(rest) > 0 {
- n := copy(t.inBuf[:], rest)
- t.remainder = t.inBuf[:n]
- } else {
- t.remainder = nil
- }
- t.c.Write(t.outBuf)
- t.outBuf = t.outBuf[:0]
- if lineOk {
- return
- }
- continue
- }
+ t.remainder = t.inBuf[:n+len(t.remainder)]
}
panic("unreachable")
}
+// SetPrompt sets the prompt to be used when reading subsequent lines.
+func (t *Terminal) SetPrompt(prompt string) {
+ t.lock.Lock()
+ defer t.lock.Unlock()
+
+ t.prompt = prompt
+}
+
func (t *Terminal) SetSize(width, height int) {
t.lock.Lock()
defer t.lock.Unlock()
OpenPOWER on IntegriCloud