diff options
author | Florrie <towerofnix@gmail.com> | 2019-03-10 10:51:29 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-03-10 10:52:28 -0300 |
commit | 6da245d2d0a55f64caaf2bb185b343d4f227d0c3 (patch) | |
tree | 861037bdafd28ee82db065a14d0cd163544cf3a2 | |
parent | 94414a2456d5302305e8801200177e9313b76858 (diff) |
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.
-rwxr-xr-x | index.js | 25 | ||||
-rw-r--r-- | 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)) { |