-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample.go
125 lines (103 loc) · 2.63 KB
/
sample.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import . "curses"
import "os"
import "fmt"
func main() {
startGoCurses()
defer stopGoCurses()
Init_pair(1, COLOR_RED, COLOR_BLACK)
x := *Cols / 2
y := *Rows / 2
loop(x, y)
}
func startGoCurses() {
Initscr()
if Stdwin == nil {
stopGoCurses()
os.Exit(1)
}
Noecho()
Curs_set(CURS_HIDE)
Stdwin.Keypad(true)
Stdwin.Addstr( 0, 3, "Cols %v / Rows %v ", 0, *Cols, *Rows )
if err := Start_color(); err != nil {
fmt.Printf("%s\n", err.String())
stopGoCurses()
os.Exit(1)
}
}
func stopGoCurses() {
Endwin()
}
func loop(x, y int) {
Stdwin.Addstr(0, 0, "Hello,", A_NORMAL)
Stdwin.Addstr(0, 1, "world!", A_NORMAL)
Stdwin.Addstr(3, 2, "Press p for panels or the famous 'any' for a moving cursor test.", A_NORMAL)
if inp := Stdwin.Getch(); inp == 'p' {
Stdwin.Clear()
// The moving panel
w, _ := Newwin( 20, 12, x, y )
w.Box( '|', '-' )
p, _ := NewPanel( w )
w.AddstrAlign(1, 1, "Press q to quit.", A_NORMAL)
w.AddstrAlign(1, 2, "Press any of the Arrow-Keys to move this window.\nPress t to toggle if this window is on the top or not.", A_NORMAL)
// The other panel
w2, _ := Newwin( 30, 20, 2, 2 )
w2.Box( '|', '-' )
p2, _ := NewPanel( w2 )
w2.AddstrAlign(1, 1, "This is another window for you to look at...", A_NORMAL)
w2.AddstrAlign(1, 3, "Press h to hide this window", A_NORMAL)
w2.AddstrAlign(1, 0, "YET-ANOTHER-WINDOW", A_NORMAL)
w2.AddstrAlign(1, 4, "Below: %v\nAbove: %v", 0, p2.Below(), p2.Above() )
DoUpdate()
top := false
for ; inp != 'q'; inp = Stdwin.Getch() {
switch inp {
case KEY_LEFT: x -= 1
case KEY_RIGHT: x += 1
case KEY_UP: y -= 1
case KEY_DOWN: y += 1
case 't':
top = ! top
if top {
p.ToBottom()
} else {
p.ToTop()
}
case 'h':
p2.Hide( !p2.Hidden() )
case 'r':
p2.Delete()
}
maxx,maxy := Stdwin.Getmax()
winx,winy := w.Getmax()
maxx-= winx-1
maxy-= winy-1
x=(x+maxx)%maxx
y=(y+maxy)%maxy
p.Move( x, y )
UpdatePanels()
DoUpdate()
//Stdwin.Refresh()
}
} else {
Stdwin.Clear()
for ; inp != 'q'; inp = Stdwin.Getch() {
switch inp {
case KEY_LEFT: x -= 1
case KEY_RIGHT: x += 1
case KEY_UP: y -= 1
case KEY_DOWN: y += 1
}
maxx,maxy := Stdwin.Getmax()
x=(x+maxx)%maxx
y=(y+maxy)%maxy
Stdwin.Clear()
Stdwin.Addstr(10, 1, "Press q to quit.", A_NORMAL)
Stdwin.Addstr(10, 2, "Press any of the Arrow-Keys\n to move the cursor. (Using Addstr)", A_NORMAL)
Stdwin.AddstrAlign(10, 5, "Press any of the Arrow-Keys\n to move the cursor. (Using Align)", A_NORMAL)
Stdwin.Addch(x, y, '@', Color_pair(1))
Stdwin.Refresh()
}
}
}