A little more progress with Gintro. I put the code I'm working on up on Codeberg.
https://codeberg.org/jeang3nie/pterm
The PtermWindow and Tab data structures are Gtk+ composite widgets. One of the benefits of doing it this way is that the parent widget can retain references to it's child widgets. For instance, the PtermWindow has a reference to it's internal Notebook, and so when a tab is removed the entire window can be passed into the closure which determines if there are any remaining tabs and if note closes the window. The Tab widget similarly gets associated with the Box, Label and Button making up it's label, so that when you press the close button on a tab that button is considered part of the tab. This is how a lot of Gtk+ programming is done in C, C++, Python etc and I wanted to see how well it translates to Nim using the bindings. It's pretty good but I'm finding a few quirks as I go along.
One little quirk is that when passing my own widgets into a callback I was getting unhelpful compile errors about the type of the data. After some head scratching I figured out that you have to cast the custom widget to it's parent class first, and then in the callback it can be cast back into it's subclass. For example when creating the "new-tab" action, it has to be called like this.
Code: Select all
discard action.connect("activate", onNewTab, Window(window))
Then when looking at the callback it then gets another cast so that any extra data associated with the subclass is available.
Code: Select all
proc onNewTab(action: SimpleAction, v: Variant, window: Window) =
let win = PtermWindow(window)
Even with quirks I like it. I'm already up to a usable program even at 168 lines of code, which includes comments and whitespace. Next step is going to be implementing multiple terminals per tab in panes. Not sure how far I'm going to take it after that unless there's community interest.