~sircmpwn/hare-vt

90b202cfd8db3e392b5708d2365faf90e0a04070 — Drew DeVault 1 year, 1 month ago 990c943
Add vt::clear
4 files changed, 15 insertions(+), 0 deletions(-)

M example.ha
M vt/draw.ha
M vt/driver.ha
M vt/xterm.ha
M example.ha => example.ha +1 -0
@@ 25,6 25,7 @@ export fn main() void = {
fn run() (void | vt::error) = {
	const term = vt::open();
	defer vt::close(term);
	vt::clear(term)?;

	const p1 = vt::newpen(void, color::RED, style::ULINE);
	const p2 = vt::newpen(color::YELLOW, color::RED);

M vt/draw.ha => vt/draw.ha +5 -0
@@ 36,3 36,8 @@ export fn print(
	};
	term.driver.chpen(term, &prev)?;
};

// Clears the terminal display and moves the cursor to the top left corner.
export fn clear(term: *term) (void | error) = {
	return term.driver.clear(term);
};

M vt/driver.ha => vt/driver.ha +3 -0
@@ 12,6 12,9 @@ export type driver = struct {
	// Polls for the next input event from this driver.
	pollev: *fn(term: *term, block: bool) (void | event | io::EOF | error),

	// Clears the screen and moves the cursor to the top-left corner.
	clear: *fn(term: *term) (void | error),

	// Releases state associated with the driver and cleans up the terminal.
	destroy: *fn(term: *term) void,
};

M vt/xterm.ha => vt/xterm.ha +6 -0
@@ 25,6 25,7 @@ const xterm_driver = driver {
	chpen = &xterm_chpen,
	getpen = &xterm_getpen,
	pollev = &xterm_pollev,
	clear = &xterm_clear,
	destroy = &xterm_destroy,
};



@@ 437,3 438,8 @@ fn xterm_chstyle(
		};
	};
};

fn xterm_clear(term: *term) (void | error) = {
	const term = term: *xterm;
	fmt::fprint(term.out, "\x1b[2J\x1b[1;1H")?;
};