-
Notifications
You must be signed in to change notification settings - Fork 1
/
autopilot.go
54 lines (44 loc) · 1016 Bytes
/
autopilot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"io"
"strings"
"unicode/utf8"
"github.com/hymkor/csvi"
)
type _AutoPilot struct {
script string
}
func (ap *_AutoPilot) Size() (int, int, error) {
return 80, 25, nil
}
func (ap *_AutoPilot) Calibrate() error {
return nil
}
func (ap *_AutoPilot) next() (string, error) {
if ap.script == "" {
return "", io.EOF
}
var command string
command, ap.script, _ = strings.Cut(ap.script, "|")
return command, nil
}
func (ap *_AutoPilot) ReadLine(io.Writer, string, string, csvi.Candidate) (string, error) {
return ap.next()
}
func (ap *_AutoPilot) GetKey() (string, error) {
key, err := ap.next()
if err != nil || len(key) <= 1 || key[0] == '\x1B' {
return key, err
}
if utf8.RuneCountInString(key) != 1 {
return key, fmt.Errorf("%#v: too long string for getkey", key)
}
return key, nil
}
func (ap *_AutoPilot) GetFilename(out io.Writer, prompt string, defaultName string) (string, error) {
return ap.next()
}
func (ap *_AutoPilot) Close() error {
return nil
}