blob: da6f041744774a612f47fc8f83cb5f2e98c6e84e (
plain)
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
|
use libtui;
use libtui::widget;
use io;
use unix::tty;
use fmt;
use os;
export type layout = struct {
widgets: []*widget::widget,
};
// Create and return a new layout from a list of widgets. [[finishall]] must be
// called to properly free the widget's nad layout's resources.
export fn newlayout(widgets: *widget::widget...) layout = {
return layout {
widgets = widgets,
};
};
// Display all the widgets contained in the given layout.
export fn print(layout: layout) (void | widget::error) = {
//libtui::clear(layout.widgets[0].ui);
libtui::doclear(&layout.widgets[0].ui);
for (let i = 0z; i < len(layout.widgets); i += 1) {
match (layout.widgets[i].print) {
case null =>
return;
case let f: *widget::print =>
f(layout.widgets[i])?;
};
};
};
// Finish and free the widgets in the given layout.
export fn finishall(layout: *layout) void = {
for (let i = 0z; i < len(layout.widgets); i += 1) {
match (layout.widgets[i].finish) {
case null =>
return;
case let f: *widget::finish =>
f(layout.widgets[i]);
};
};
};
// Notify all the widgets contained in the given layout. Returns true as soon as
// one of the widget's listeners returns true, false otherwise.
export fn notifyall(layout: layout, k: libtui::key) bool = {
for (let i = 0z; i < len(layout.widgets); i += 1) {
if (widget::notify(layout.widgets[i], k)) {
return true;
};
};
return false;
};
|