-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterm_test.go
98 lines (85 loc) · 1.54 KB
/
term_test.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package term_test
import (
"fmt"
"log"
"strings"
"github.com/rwx-yxu/term"
)
func ExampleColor256() {
color := term.Color256(50)
fmt.Printf("%q \n", color)
//Output:
//"\x1b[38;5;50m"
}
func ExampleBkgColor256() {
bkg := term.BkgColor256(50)
fmt.Printf("%q \n", bkg)
//Output:
//"\x1b[48;5;50m"
}
func ExampleMvUp() {
out := term.MvUp(2)
fmt.Printf("%q\n", out)
//Output:
//"\x1b[2A"
}
func ExampleMvDown() {
out := term.MvDown(2)
fmt.Printf("%q\n", out)
//Output:
//"\x1b[2B"
}
func ExampleMvRight() {
out := term.MvRight(2)
fmt.Printf("%q\n", out)
//Output:
//"\x1b[2C"
}
func ExampleMvLeft() {
out := term.MvLeft(2)
fmt.Printf("%q\n", out)
//Output:
//"\x1b[2D"
}
func ExampleReadLine() {
//Turn string into standard input
//As if it is standard input
sr := strings.NewReader("Sample\r\n")
line, err := term.ReadLine(sr)
if err != nil {
log.Println(err)
return
}
//Using %s will pass
fmt.Printf("%q", line)
//Output:
//"Sample"
}
func ExamplePrompt_default() {
//Turn string into standard input
//As if it is standard input
sr := strings.NewReader("Sample\r\n")
line, err := term.Prompt(sr, "")
if err != nil {
log.Println(err)
return
}
//Using %s will pass
fmt.Printf("%q", line)
//Output:
//> "Sample"
}
func ExamplePrompt_explicit() {
//Turn string into standard input
//As if it is standard input
sr := strings.NewReader("Sample\r\n")
line, err := term.Prompt(sr, "--> ")
if err != nil {
log.Println(err)
return
}
//Using %s will pass
fmt.Printf("%q", line)
//Output:
//--> "Sample"
}