use tui;
use tui::layout;
use tui::widget;
use tui::widget::list;
use unix::tty;
use io;
use fmt;
use time;

export fn main() void = {
	const state = tui::init()!;
	defer tui::finish(&state);
	let li = list::newscrolllist(&state, (1, 1), tty::ttysize {
		rows = 2u16,
		columns = 50u16,
	},
	&widget::style {
		border = false,
		colorfg = widget::color::BLUEFG,
		colorbg = widget::color::REDBG,
	},"hello", "world", "bye", "world")!;

	let l = layout::newvlayout(&li);
	defer l.layout.finish(&l);
	l.layout.print(&l);

	for (true) {
		const r = tui::read(&state)!;
		if (r == 'j') {
			list::down(&li);
		};
		if (r == 'k') {
			list::up(&li);
		};
		if (r == 'K') {
			list::frameup(&li);
		};
		if (r == 'J') {
			list::framedown(&li);
		};
		if (r == 'g') {
			list::top(&li);
		};
		if (r == 'G') {
			list::bottom(&li);
		};
		if (r == 'l') {
			fmt::println(li.items[li.cursor])!;
			break;
		};
		if (r == 'q') {
			break;
		};
		l.layout.print(&l);
	};
};
