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