From 1d9f530b479b543ca3dad15e060d55ccdd536d8c Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 18 Jul 2019 12:01:40 +0900
Subject: [PATCH] Added on-screen docs

---
 desktop/sources/links/main.css       |  2 +-
 desktop/sources/scripts/commander.js | 37 +++++++++++++++++++++-------
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/desktop/sources/links/main.css b/desktop/sources/links/main.css
index f2d5491..8abe5c2 100644
--- a/desktop/sources/links/main.css
+++ b/desktop/sources/links/main.css
@@ -5,7 +5,7 @@ body { margin:0px; padding:0px; overflow:hidden; font-family:"input_mono_regular
 #ronin { height: calc(100vh - 60px); width:calc(100vw - 60px); -webkit-app-region: drag; padding: 30px;overflow: hidden; }
 #ronin #wrapper { overflow: hidden; position: relative; }
 #ronin #wrapper #commander { z-index: 9000;position: relative;width: 310px;height: calc(100vh - 60px);-webkit-app-region: no-drag;padding-right: 30px;transition: margin-left 250ms;}
-#ronin #wrapper #commander textarea { background: none; width: 100%; height: calc(100vh - 90px); resize: none; font-size: 12px;line-height: 15px; padding-right: 15px}
+#ronin #wrapper #commander textarea { background: none; width: 100%; height: calc(100vh - 105px); resize: none; font-size: 12px;line-height: 15px; padding-right: 15px}
 #ronin #wrapper #commander div#status { position: absolute; bottom: 0px; text-transform: lowercase;}
 #ronin.hidden #wrapper #commander { margin-left:-331px; }
 
diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js
index e645a9a..720de5b 100644
--- a/desktop/sources/scripts/commander.js
+++ b/desktop/sources/scripts/commander.js
@@ -8,15 +8,15 @@ function Commander (ronin) {
   this._log.id = 'log'
   this._source = document.createElement('div')
   this._source.id = 'source'
-  this._help = document.createElement('div')
-  this._help.id = 'help'
+  this._docs = document.createElement('div')
+  this._docs.id = 'help'
   this.isVisible = true
 
   this.install = function (host) {
     this.el.appendChild(this._input)
     this._status.appendChild(this._log)
     this._status.appendChild(this._source)
-    this._status.appendChild(this._help)
+    this._status.appendChild(this._docs)
     this.el.appendChild(this._status)
     host.appendChild(this.el)
     this._input.addEventListener('input', this.onInput)
@@ -64,10 +64,21 @@ function Commander (ronin) {
   }
 
   this.setStatus = function (msg) {
-    if (!msg || msg === this._log.textContent) { return }
-    this._log.textContent = `${msg}`
-    this._source.textContent = `${ronin.source} ${this._input.value.split('\n').length} lines`
-    console.log(msg)
+    // Logs
+    if (msg && msg !== this._log.textContent) {
+      this._log.textContent = `${msg}`
+      console.log(msg)
+    }
+    // Source
+    const _source = `${ronin.source} ${this._input.value.split('\n').length} lines`
+    if (_source !== this._source.textContent) {
+      this._source.textContent = _source
+    }
+    // Docs
+    const _docs = this.docs.print(this.getLastfn())
+    if (_docs !== this._docs.textContent) {
+      this._docs.textContent = `${_docs}`
+    }
   }
 
   this.update = function () {
@@ -75,11 +86,16 @@ function Commander (ronin) {
   }
 
   this.onInput = () => {
-    console.log('input', this._input.selectionStart)
+    this.setStatus()
   }
 
   this.onClick = () => {
-    console.log('click', this._input.selectionStart)
+    this.setStatus()
+  }
+
+  this.getLastfn = function () {
+    const pos = this._input.value.substr(0, this._input.selectionStart).lastIndexOf('(')
+    return this._input.value.substr(pos).split(' ')[0].replace(/\(/g, '').replace(/\)/g, '').trim()
   }
 
   // Mouse
@@ -223,6 +239,9 @@ function Commander (ronin) {
         }, '').trim()}`
         return `${acc}- \`(${example.trim()})\` ${this.dict[item].note}\n`
       }, '')
+    },
+    print: function (name) {
+      return this.dict[name] ? `(${name} ${this.dict[name].params.reduce((acc, item) => { return `${acc}${item} ` }, '').trim()})` : ''
     }
   }