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 ++++++++++++++++++++++--- ui.js | 5 ++++- 2 files changed, 26 insertions(+), 4 deletions(-) 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) diff --git a/ui.js b/ui.js index eb4a0a9..d9b652d 100644 --- a/ui.js +++ b/ui.js @@ -413,9 +413,12 @@ class AppElement extends FocusElement { } keyPressed(keyBuf) { - if (keyBuf[0] === 0x03) { + if (keyBuf[0] === 0x03) { // Ctrl-C this.shutdown() return + } else if (keyBuf[0] === 0x1a) { // Ctrl-Z + this.emit('suspendRequested') + return } if (telc.isRight(keyBuf)) { -- cgit 1.3.0-6-gf8a5