~sircmpwn/hare-vt

60fe6eef36e82d75670212e15df7c28363424249 — Drew DeVault 1 year, 1 month ago 1c2e8c3
vt::print: restore previous pen
3 files changed, 11 insertions(+), 2 deletions(-)

M vt/draw.ha
M vt/driver.ha
M vt/xterm.ha
M vt/draw.ha => vt/draw.ha +2 -2
@@ 24,6 24,7 @@ export fn print(
	term: *term,
	args: (fmt::formattable | styled)...
) (void | error) = {
	const prev = term.driver.getpen(term);
	for (let i = 0z; i < len(args); i += 1) {
		match (args[i]) {
		case let f: fmt::formattable =>


@@ 33,6 34,5 @@ export fn print(
			print(term, t.args...)?;
		};
	};
	// TODO: Restore previous pen
	term.driver.chpen(term, &defaultpen)?;
	term.driver.chpen(term, &prev)?;
};

M vt/driver.ha => vt/driver.ha +3 -0
@@ 6,6 6,9 @@ export type driver = struct {
	// Changes the current pen for drawing.
	chpen: *fn(term: *term, pen: *pen) (void | error),

	// Returns the current pen for drawing.
	getpen: *fn(term: *term) pen,

	// Polls for the next input event from this driver.
	pollev: *fn(term: *term, block: bool) (void | event | io::EOF | error),


M vt/xterm.ha => vt/xterm.ha +6 -0
@@ 16,6 16,7 @@ type xterm = struct {

const xterm_driver = driver {
	chpen = &xterm_chpen,
	getpen = &xterm_getpen,
	pollev = &xterm_pollev,
	destroy = &xterm_destroy,
};


@@ 63,6 64,11 @@ fn xterm_pollev(term: *term, block: bool) (void | event | io::EOF | error) = {
	abort(); // TODO
};

fn xterm_getpen(term: *term) pen = {
	let term = term: *xterm;
	return term.pen;
};

fn xterm_chpen(term: *term, pen: *pen) (void | error) = {
	let term = term: *xterm;
	const old = term.pen;