« get me outta code hell

Suspend support - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-03-10 10:51:29 -0300
committerFlorrie <towerofnix@gmail.com>2019-03-10 10:52:28 -0300
commit6da245d2d0a55f64caaf2bb185b343d4f227d0c3 (patch)
tree861037bdafd28ee82db065a14d0cd163544cf3a2 /index.js
parent94414a2456d5302305e8801200177e9313b76858 (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.
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js25
1 files changed, 22 insertions, 3 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)