From 6da245d2d0a55f64caaf2bb185b343d4f227d0c3 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 10 Mar 2019 10:51:29 -0300 Subject: Suspend support Should think about moving this into tui-lib! It'd fit the boilerplate function I have there already (I think), but we're not making use of that in mtui yet. --- index.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 6a71611..578fdc3 100755 --- a/index.js +++ b/index.js @@ -51,12 +51,26 @@ async function main() { process.exit(1) } - appElement.on('quitRequested', () => { + const cleanTerminal = () => { process.stdout.write(ansi.cleanCursor()) process.stdout.write(ansi.disableAlternateScreen()) + } + + const dirtyTerminal = () => { + process.stdout.write(ansi.enableAlternateScreen()) + process.stdout.write(ansi.startTrackingMouse()) + } + + appElement.on('quitRequested', () => { + cleanTerminal() process.exit(0) }) + appElement.on('suspendRequested', () => { + cleanTerminal() + process.kill(process.pid, 'SIGTSTP') + }) + let grouplike = { name: 'My ~/Music Library', comment: ( @@ -77,8 +91,13 @@ async function main() { root.h = size.height root.fixAllLayout() - process.stdout.write(ansi.enableAlternateScreen()) - process.stdout.write(ansi.startTrackingMouse()) + dirtyTerminal() + process.on('SIGCONT', () => { + flushable.resizeScreen({lines: flushable.screenLines, cols: flushable.screenCols}) + process.stdin.setRawMode(false) + process.stdin.setRawMode(true) + dirtyTerminal() + }) const flushable = new Flushable(process.stdout, true) flushable.resizeScreen(size) -- cgit 1.3.0-6-gf8a5