summaryrefslogtreecommitdiff
path: root/tui/widget/text/text.ha
blob: d849661940460f1378493d6cbc3b908235879a3f (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
use io;
use unix::tty;
use tui;
use tui::widget;
use strings;

export type text = struct {
	widget: widget::widget,
	txt: str,
};

export fn newtext(state: *tui::tui, txt: str, pos: widget::coords, style: (*widget::style | void)) text = {
	return text {
		widget = widget::widget {
			state = state,
			print = &printtext,
			resize = &resizetext,
			pos = pos,
			sz = void,
			style = style,
			...
		},
		txt = txt,
	};
};

fn printtext(widget: *widget::widget) void = {
	const widget = widget: *text;
	widget.widget.buf = strings::dup(widget.txt);
	defer free(widget.widget.buf);
	widget::print(widget);
};

fn resizetext(widget: *widget::widget, ttysize: tty::ttysize) void = {
	return;
};

export fn settext(text: *text, txt: str) void = {
	text.txt = txt;
};