aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar piotrruss <mail@pruss.it> 2022-05-07 19:25:34 +0100
committerGravatar piotrruss <mail@pruss.it> 2022-05-07 19:25:34 +0100
commit119ba1939f4c7d36dbf49347f7ab8322f51bfb18 (patch)
tree0e8b46c0949dfc1338dc6976fb86caf5fa0b7997
parentf3d9bf70794a7bed776b6e951ac2f10c9ca1b2f3 (diff)
downloadnotes_cli-119ba1939f4c7d36dbf49347f7ab8322f51bfb18.tar.gz
notes_cli-119ba1939f4c7d36dbf49347f7ab8322f51bfb18.tar.bz2
notes_cli-119ba1939f4c7d36dbf49347f7ab8322f51bfb18.zip
added help screen
-rwxr-xr-xnotes_cli.js37
1 files changed, 31 insertions, 6 deletions
diff --git a/notes_cli.js b/notes_cli.js
index dceccd2..db146be 100755
--- a/notes_cli.js
+++ b/notes_cli.js
@@ -52,6 +52,14 @@ const formatNote = note => {
: fixedStr(note.title, columns - note.title.length-2)
}
+const showHelp = () => {
+ const prev = draw.v
+ draw = { t: 'h', prev, v: () => ['[q] - Quit','[h] - Help','[up/k] - Previous note','[down/j] - Next note',
+ '[enter/o] - Open note','','Options not yet added:','[c] - Create note','[r] - Rename note','[s] - Sort note']};
+ menu = 'Press any key to exit help'
+ drawApp()
+}
+
const showList = (notes, status) => {
if (status !== 200) {
cls()
@@ -161,7 +169,7 @@ const drawApp = (lastLine = true) => {
break
default:
const max = Math.max(...(draw.v().map(el => el.length)))
- if (draw.t === 'p') {
+ if (['p','h'].includes(draw.t)) {
if (i === (Math.floor((lines - draw.v().length) / 2) - 2)){
cl('║'+' '.repeat(dist(max+4)[0])+'┌'+'─'.repeat(max+2)+'┐'+' '.repeat(dist(max+4)[1])+'║')
} else if (i === (Math.floor((lines + draw.v().length) / 2) + 1)) {
@@ -175,7 +183,9 @@ const drawApp = (lastLine = true) => {
const t = draw.v()[n]
const tLength = t.indexOf('\x1b') > -1 ? t.length - 9 : t.length
const s = [Math.floor((max+2-tLength) / 2), Math.ceil((max+2-tLength) / 2)]
- cl('║'+' '.repeat(dist(max+4)[0])+'│'+' '.repeat(s[0])+t+' '.repeat(s[1])+'│'+' '.repeat(dist(max+4)[1])+'║')
+ draw.t === 'h'
+ ? cl('║'+' '.repeat(dist(max+4)[0])+'│'+' '+t+' '.repeat(s[0]+s[1]-1)+'│'+' '.repeat(dist(max+4)[1])+'║')
+ : cl('║'+' '.repeat(dist(max+4)[0])+'│'+' '.repeat(s[0])+t+' '.repeat(s[1])+'│'+' '.repeat(dist(max+4)[1])+'║')
}
} else if (draw.t === 'l') {
const l = draw.v()[i-5+scroll] && draw.v()[i-5+scroll].substring(0,columns-4)
@@ -205,9 +215,11 @@ const getKey = () => {
switch(key.name) {
case 'up':
case 'k':
- active > 0 && active--
- active < scroll && scroll--
- drawApp()
+ if (draw.t === 'l') {
+ active > 0 && active--
+ active < scroll && scroll--
+ drawApp()
+ }
break
case 'down':
case 'j':
@@ -221,9 +233,22 @@ const getKey = () => {
case 'o':
fetchNote(notesList[active])
break
+ case 'h':
+ if (draw.t === 'l') {
+ showHelp()
+ break
+ }
case 'q':
- process.exit()
+ if (draw.t === 'l') {
+ process.exit()
+ }
default:
+ if (draw.t === 'h') {
+ const v = draw.prev
+ draw = { t: 'l', v }
+ menu = 'Press [h] for help'
+ drawApp()
+ }
}
})
}