diff options
-rwxr-xr-x | notes_cli.js | 37 |
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() + } } }) } |