« get me outta code hell

Mark - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-07-05 17:34:01 -0300
committerFlorrie <towerofnix@gmail.com>2018-07-05 17:34:01 -0300
commita5ffe6a882598edc8b67fed12de78642fd6d1a5a (patch)
tree901c28052707f2f7f3d99a703ce2249d19e730ae /ui.js
parenta8fec45b10a4989a960d20e97761af742bc208da (diff)
Mark
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js47
1 files changed, 43 insertions, 4 deletions
diff --git a/ui.js b/ui.js
index c4c2307..0bddc64 100644
--- a/ui.js
+++ b/ui.js
@@ -32,9 +32,13 @@ class AppElement extends FocusElement {
     this.player = null
     this.recordStore = new RecordStore()
     this.undoManager = new UndoManager()
-    this.queueGrouplike = {isTheQueue: true, items: []}
+    this.queueGrouplike = {name: 'Queue', isTheQueue: true, items: []}
+    this.markGrouplike = {name: 'Marked', items: []}
     this.editMode = false
 
+    // Crude hack...
+    this.recordStore.app = this
+
     this.rootDirectory = process.env.HOME + '/.mtui'
 
     this.form = new Form()
@@ -143,6 +147,33 @@ class AppElement extends FocusElement {
       }
     })
 
+    grouplikeListing.on('mark', item => {
+      if (this.editMode) {
+        if (!this.markGrouplike.items.includes(item)) {
+          this.undoManager.pushAction({
+            activate: () => {
+              this.markGrouplike.items.push(item)
+            },
+            undo: () => {
+              // It SHOULD always be on the top, but juuust in case it isn't...
+              const index = this.markGrouplike.items.indexOf(item)
+              this.markGrouplike.items.splice(index, 1)
+            }
+          })
+        } else {
+          const index = this.markGrouplike.items.indexOf(item)
+          this.undoManager.pushAction({
+            activate: () => {
+              this.markGrouplike.items.splice(index, 1)
+            },
+            undo: () => {
+              this.markGrouplike.items.splice(index, 0, item)
+            }
+          })
+        }
+      }
+    })
+
     const handleSelectFromPathElement = item => {
       this.form.selectInput(grouplikeListing)
       if (isGroup(item)) {
@@ -674,7 +705,7 @@ class GrouplikeListingElement extends FocusElement {
     if (this.grouplike.items.length) {
       for (const item of this.grouplike.items) {
         const itemElement = new GrouplikeItemElement(item, this.recordStore)
-        for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)', 'queue (play next)']) {
+        for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)', 'queue (play next)']) {
           itemElement.on(evtName, () => this.emit(evtName, item))
         }
         form.addInput(itemElement)
@@ -809,7 +840,12 @@ class GrouplikeItemElement extends Button {
 
     const record = this.recordStore.getRecord(this.item)
 
-    writable.write(' ')
+    if (this.recordStore.app.editMode && this.recordStore.app.markGrouplike.items.includes(this.item)) {
+      writable.write('M')
+    } else {
+      writable.write(' ')
+    }
+
     if (isGroup(this.item)) {
       writable.write('G')
     } else if (record.downloading) {
@@ -819,6 +855,7 @@ class GrouplikeItemElement extends Button {
     } else {
       writable.write(' ')
     }
+
     writable.write(' ')
   }
 
@@ -837,8 +874,10 @@ class GrouplikeItemElement extends Button {
       }
     } else if (telc.isBackspace(keyBuf)) {
       this.emit('remove (backspace)')
-    } else if (telc.isCharacter(keyBuf, 'x')) {
+    } else if (telc.isCaselessLetter(keyBuf, 'x')) {
       this.emit('remove (x)')
+    } else if (telc.isCaselessLetter(keyBuf, 'm')) {
+      this.emit('mark')
     } else if (telc.isSpace(keyBuf)) {
       this.emit('select (space)')
     } else if (telc.isEnter(keyBuf)) {