Cigale: a simple journaling tool
Learning python and curses to make a small journal thing. 04022023
In the videogame Omori, you sometimes have access to a laptop. There is not much you can do on it. You can stare at the screen, or open your journal, which is some sort of calendar, with almost the same entry everyday. I wanted to try and recreate something similar.
Idea
The tool should display a calendar, with the option to add an entry for a given day. The entries should be saved in json format. I wanted to learn how to make curses based TUIs, and I used python to program the tool. The external library TinyDB is used to create the database.
Result
All the basic functionalities are implemented. This project is more meant as practice and is mainly for personal use. The keybindings might not translate well to other systems. For now, you can move in the calendar with the arrow keys, press enter to start editing, then press enter or esc to get out of edit mode and save the entry.
By pressing "[" (for now) a bar appears at the bottom of the terminal window where you can input a date in the format DDMMYYYY, and the screen will refresh the view to show the entries around this date. Some niceties: I tried to implement a different view for bigger or smaller screens. The boxes are generated as curses windows, which returns an error if out of the bounds of the terminal window. One could adjust the size of the terminal window with code (I think), or use curses pads, which can overflow the terminal window. For now, if the terminal window is too small to display the whole month (default view), it will display just a few days. Another thing that was interesting to implement was having the text wrap. Since the individual boxes are so small, you end up writing on multiple line, with the text breaking in the middle of words, which makes it harder to read. My solution was to use the python built-in library textwrap. The challenge was to make it fluid. By passing a validator to curses.textpad.Textbox.edit([validator]) we can have a function called for each keystroke. That way we can store the character in a buffer, apply text wrapping to it, and display the wrapped text in the curses window.
Conclusion
I am happy with the result, and it's good enough for me to start logging some entries. I do have a few improvements in mind:
- make it more portable, better standard for keyboard shortcuts
- fix some display bugs on linux
- revisit this in C or another low-level language
You can check out the code here: https://git.sr.ht/~nosach/cigale