~sircmpwn/hare-vt

886ef581a6608588ae698aeee378d199e444e3d9 — Curtis Arthaud a month ago 98e522b master
add resumeraw() and suspendraw()

Needed eg. to print the output of a subprocess correctly
(output of exec::start when running inside a program that is using vt).

Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
2 files changed, 26 insertions(+), 0 deletions(-)

M vt/driver.ha
M vt/xterm.ha
M vt/driver.ha => vt/driver.ha +13 -0
@@ 18,6 18,9 @@ export type driver = struct {
	// Enable or disable the alternate screen buffer, if supported.
	chalt: *fn(term: *term, alt: bool) (void | error),

	// Enable or disable raw mode.
	chraw: *fn(term: *term, enable: bool) (void | error),

	// Enable or disable the cursor display.
	chcur: *fn(term: *term, enable: bool) (void | error),



@@ 77,6 80,16 @@ export fn disablealt(term: *term) (void | error) = {
	return term.driver.chalt(term, false);
};

// Suspends raw mode.
export fn suspendraw(term: *term) (void | error) = {
	return term.driver.chraw(term, false);
};

// Resumes raw mode.
export fn resumeraw(term: *term) (void | error) = {
	return term.driver.chraw(term, true);
};

// Enables the cursor display.
export fn enablecur(term: *term) (void | error) = {
	return term.driver.chcur(term, true);

M vt/xterm.ha => vt/xterm.ha +13 -0
@@ 36,6 36,7 @@ const xterm_driver = driver {
	pollev = &xterm_pollev,
	clear = &xterm_clear,
	chalt = &xterm_chalt,
	chraw = &xterm_chraw,
	chcur = &xterm_chcur,
	movecur = &xterm_movecur,
	getcur = &xterm_getcur,


@@ 475,6 476,18 @@ fn xterm_chalt(term: *term, alt: bool) (void | error) = {
	};
};

fn xterm_chraw(term: *term, enable: bool) (void | error) = {
	let term = term: *xterm;
	if (enable) {
		if (tty::isatty(term.in)) {
			tty::makeraw(&term.termios)?;
			tty::noecho(&term.termios)?;
		};
	} else {
		tty::termios_restore(&term.termios);
	};
};

fn xterm_chcur(term: *term, enable: bool) (void | error) = {
	let term = term: *xterm;
	if (enable) {