added notes feature

This commit is contained in:
Paul Wilde 2022-05-03 21:43:47 +01:00
parent cb180c4095
commit 912d413748

View file

@ -20,6 +20,7 @@ proc read_notes(): seq[string] =
proc write_notes(notes: seq[string]) =
try:
let f = open(note_file, fmWrite)
defer: f.close()
for note in notes:
f.writeLine(note)
except:
@ -43,6 +44,16 @@ proc write_note(note: string) =
except:
echo "write_note, Unable to write note :", getCurrentExceptionMsg()
proc replace_note(new_note: string, old_note: string) =
let notes = read_notes()
var new_notes: seq[string] = @[]
for a_note in notes:
if old_note == a_note:
new_notes.add(new_note)
else:
new_notes.add(a_note)
write_notes(new_notes)
proc get_notes(): (Info, seq[string]) =
var info = newInfo()
info.title = "Notes :"
@ -52,7 +63,7 @@ proc get_notes(): (Info, seq[string]) =
proc display_option_menu(option: string) =
var select = newInfo()
select.title = "Note :"
let args = concat(@["option"],note_choices)
let args = concat(@[option],note_choices)
let chosen = outputJSON(select,args)
if chosen in note_choices:
case chosen:
@ -61,9 +72,11 @@ proc display_option_menu(option: string) =
start_notes()
of "back":
start_notes()
else:
write_note(option)
elif chosen != "" and chosen != option:
replace_note(chosen, option)
display_option_menu(chosen)
else:
display_option_menu(option)
proc start_notes() =
let (info,notes) = get_notes()