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
|
package windows
import (
. "github.com/gbin/goncurses"
)
const (
LEFT_PAD = 2
RIGHT_PAD = 2
)
func InputPrompt(
scr *Window,
title string,
prompt string,
input_length int,
) string {
height, length := 8, len(prompt)+input_length+LEFT_PAD+RIGHT_PAD
my, mx := scr.MaxYX()
w, err := NewWindow(
height,
length,
(my/2)-(height/2),
(mx/2)-(length/2),
)
if err != nil {
panic("Oh no sth went wrong in input!!")
}
w.Box(0, 0)
Echo(true)
w.MovePrint(0, 1, title)
w.MovePrint(2, 2, prompt)
w.Move(2, 2+len(prompt))
input, err := w.GetString(input_length) // character input box
if err != nil {
panic("Oh no sth went wrong in input 2!!")
}
w.MovePrintf(height-2, 2, "Press q to continue...")
w.Refresh()
Echo(false)
for {
ch := w.GetChar()
switch Key(ch) {
case 'q':
w.Erase()
w.Refresh()
w.Delete()
return input
}
}
}
|