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

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

export fn newtext(out: io::file, txt: str, pos: widget::coords, style: (*widget::style | void)) text = {
	return text {
		widget = widget::widget {
			out = out,
			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;
};