/
curses.winxed
157 lines (140 loc) · 2.84 KB
/
curses.winxed
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#! winxed
class Window
{
var win;
var panel;
function getmaxx()
{
using Curses.getmaxx;
int x= getmaxx(self.win);
return x;
}
function getmaxy()
{
using Curses.getmaxy;
int y= getmaxy(self.win);
return y;
}
function clear()
{
using Curses.wclear;
wclear(self.win);
}
function mvaddstr(int y, int x, string s)
{
using Curses.mvwaddstr;
mvwaddstr(self.win, y, x, s);
}
function getch()
{
using Curses.wgetch;
string s= wgetch(self.win);
return s;
}
function box(int verch, int horch)
{
using Curses.box;
box(self.win, verch, horch);
}
function new_panel(int lines, int cols, int y, int x)
{
using Curses.derwin;
using Curses.new_panel;
var newwindow= new Window;
var winscr = derwin(self.win, lines, cols, y, x);
var panel= new_panel(winscr);
newwindow.panel= panel;
newwindow.win= winscr;
return newwindow;
}
function top_panel()
{
using Curses.top_panel;
top_panel(self.panel);
}
}
class Screen : Window
{
function init [vtable]()
{
using extern Curses;
using Curses.initscr;
say('Hi');
var win= initscr();
self.win= win;
}
function endwin()
{
using Curses.endwin;
endwin();
}
}
function panel1(var p)
{
p.clear();
p.box(0, 0);
p.mvaddstr(2, 6, 'Uuuuh!');
}
function panel2(var p2, string s)
{
p2.clear();
p2.box(0, 0);
int width= p2.getmaxx();
p2.mvaddstr(1, 1, substr(s, 0, width-3));
}
function test(scr, string s)
{
int maxx= scr.getmaxx();
int maxy= scr.getmaxy();
int l= length(s);
int x = maxx - l;
if (x < 0) x= 0;
scr.mvaddstr(maxy / 2, x / 2, s);
scr.getch();
using Curses.update_panels;
using Curses.doupdate;
var p= scr.new_panel(maxy/2, maxx/2, maxy/4, maxx/4);
panel1(p);
update_panels();
doupdate();
p.getch();
int width= l + 3;
if( width > maxx) width= maxx;
var p2= scr.new_panel(3, width, (maxy - 3)/2, (maxx - width) / 2);
panel2(p2, s);
update_panels();
doupdate();
p2.getch();
p.top_panel();
panel1(p);
update_panels();
doupdate();
p.getch();
p2.top_panel();
panel2(p2, s);
update_panels();
doupdate();
p2.getch();
scr.endwin();
say(maxx, ", ", maxy);
}
function main(args)
{
using extern Curses;
using Curses.curses_version;
say('Curses version: ', curses_version());
string s;
int argc = args;
if (argc > 1) s= args[1];
else s= 'Hello, world!';
var scr;
try {
scr = new Screen;
test(scr, s);
}
catch (e)
{
scr.endwin();
throw e;
}
}