Hello everyone!
I decided to learn ncurses a few days ago so I can do a project I’ve been thinking about lately, and in the process I figured since I’ll go to the trouble of solving a bunch of the problems with writing relatively complicated TUIs with ncurses, I might as well generalise the solutions into a library or two for future me and anyone else who will find them useful.
Anyway, enough introduction, heres what I want to do with the library:
I want it to dynamically manage size and position of ncurses windows. This means windows should be able to be added, and removed (just those for now, I don’t know if I’ll implement resizing windows from the perspective of someone using the library to have that functionality), and have the size and position of the windows update automatically.
Initially I thought a binary space partitioning tree situation might be a good way to tackle this, but I want it to be a bit more flexible. For example, the dev using the library should be able to set certain windows to behave differently than leaves in a bsp (think persistent status bar at the bottom of the application, taking up the entire width but only a couple lines in height for example, or toggle-able file explorer on the left/right of the application like neovim’s NERDTree).
How would you guys go about designing something like this, while still keeping the code relatively simple and efficient?
Here is a badly drawn diagram of what I mean:
Steps here refer to how someone using the library might go about creating each element (window) of their UI in their own project.
Until step 4 a bsp tree makes sense, but after that when I want to add a window which doesnt conform to the rules of a bsp tree, it gets a bit difficult.
Also, Im thinking there should be some way for windows to have some idea of their neighbours so that when a change occurs, they can adapt to it.
Anyways, essentially I’m looking for your thoughts on how you would go about implementing something like this.
Much appreciated!
Thanks! Ill take some time to look into what you said and try to really understand it, but if I need some help I’ll ask you. As for how many splits a TUI might have, I dont know because I need it to be quite general so that others can use it for their own purposes. Me personally and for this specific project, Ill mostly need a bunch of columns (like blue and green in step 2) as well as the “special” windows, for my application. I’m trying to make a trello/kanban style app with ncurses and C.