« get me outta code hell

Terminal resize detection - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-06-02 23:28:57 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-02 23:28:57 -0300
commit60131bd74b505803bba2db7bef78d9945d4087bd (patch)
tree790cf22c54ed02f03a426223c58aa4718a067610
parent662ab7324567e093ff432991cefbd3293a68cea6 (diff)
Terminal resize detection
-rw-r--r--index.js10
-rw-r--r--todo.txt3
m---------tui-lib0
3 files changed, 11 insertions, 2 deletions
diff --git a/index.js b/index.js
index ca62f17..b46edb6 100644
--- a/index.js
+++ b/index.js
@@ -23,8 +23,7 @@ async function main() {
   const size = await interfacer.getScreenSize()
 
   const flushable = new Flushable(process.stdout, true)
-  flushable.screenLines = size.lines
-  flushable.screenCols = size.cols
+  flushable.resizeScreen(size)
   flushable.shouldShowCompressionStatistics = process.argv.includes('--show-ansi-stats')
   flushable.write(ansi.clearScreen())
   flushable.flush()
@@ -33,6 +32,13 @@ async function main() {
   root.w = size.width
   root.h = size.height
 
+  interfacer.on('resize', newSize => {
+    root.w = newSize.width
+    root.h = newSize.height
+    flushable.resizeScreen(newSize)
+    root.fixAllLayout()
+  })
+
   const appElement = new AppElement()
   root.addChild(appElement)
   root.select(appElement)
diff --git a/todo.txt b/todo.txt
index b912de1..4b8f1e8 100644
--- a/todo.txt
+++ b/todo.txt
@@ -14,3 +14,6 @@ TODO: "Queue to play next"... maybe also a cursor in the queue list, which
 
 TODO: Scroll to the selected track once it starts playing when selected from
       the queue.
+
+TODO: process.on('SIGWINCH', () => ...) -- detect terminal resize!!
+      (Done!)
diff --git a/tui-lib b/tui-lib
-Subproject 23dc4b24d92eb2e19c55029522acabfccb70191
+Subproject 3386ff9428997fdcebab1f67cb83c82e4636be8