Jun 24

Daniel Burrows on cwidget-gtk

Category: Summer of Code, Uncategorized, debianObey Arthur Liu @ 5:28 am

Sometimes people propose other solutions to have the Aptitude-gtk project done, like :

I’d have thought that the most interesting way of doing aptitude-gtk would be to write a gtk backend for libcwidget. -Karellen

As this might be of interest to more people, I’ll repost Daniel Burrows‘ response :

Although I can see where you’re coming from, a GTK+ backend to cwidget would have no significant upsides and significant downsides.

The main upside to doing that from a practical point of view is that you would have only one piece of “driver” code for the GTK+ and curses interfaces. You wouldn’t have to rewrite the entire interface from scratch to create a GUI frontend.

But this is just an illusory benefit. cwidget is a terminal interface library and aptitude’s curses frontend is a terminal-based UI. From a practical point of view, this means that aptitude regularly assumes that, for instance, to clear out a line it’s sufficient to output $WIDTH space characters (ASCII 32) with the desired background style. A port of cwidget to GTK+ would have to introduce new, interface-independent abstractions for all operations like this and eliminate all direct use of terminal-based assumptions, at a significant cost in complexity for both cwidget and the aptitude frontend. In order to transition to these new conventions, I believe you would have to rewrite large portions of both cwidget *and* aptitude in order to make the interface abstraction layer work. (remember: the justification for doing this is to avoid having to rewrite aptitude!)

Furthermore, while this approach avoids reimplementing aptitude’s curses interface (sort of, except where it doesn’t — see above), it does so at the cost of requiring you to reimplement all of cwidget, for GTK+. I just did a quick line count (with “wc -l”): in all of cwidget there are 23,390 lines of code, while aptitude’s curses frontend has around 23,359 lines of code (some of which are actually shared with the other frontends but are in the curses directory due to the historical organization of the code tree). Not only is a rewrite of cwidget more involved, but the amount of code you’d have to replace is comparable to the amount implicated in a rewrite of aptitude itself!

Finally, even if these costs weren’t enough to eliminate the idea, it’s not at all clear to me that a GTK+ backend for cwidget is even desirable. Although aptitude has some superficial similarities to a GUI program, the process of designing an interface to run in a terminal (where the available input mechanisms are relatively restricted and all output is to a character-cell grid) is rather different from the process of designing a GUI. GUI programs can’t rely on some simplifying assumptions that terminal programs can, and at the same time they have a lot more options available to them (just to name a few: graphics, multiple windows, differing text sizes and rotated text). Trying to force everything through an abstraction designed for terminal output would require you to either

  1. eschew those options,
  2. provide abstract GUI components that somehow “fell back” to terminal rendering in a terminal, or
  3. add ways for the frontend to extend the abstract widgets with custom functionality.

1. is not an option because I (and, I think, Arthur) want to design a good GTK+ package manager, not a good GTK+ imitation of a console package manager. 2. and 3. amount, in my strong opinion, to writing two separate interfaces but intertwining their implementations in a mass of maintenance-resistant and extension-resistant spaghetti code.

At the end of the day, I think that having two separate frontends (sharing backend logic where appropriate, of course) is a far cleaner and more maintainable design, and also easier to create.

As I said earlier, I intend to go a little farther than just making a GTK+ “skin” over the curses interface. Think less like gvim and emacs and more like maybe ddd.

I should also add that the cwidget library is used by no major programs except Aptitude so few others would benefit from a GTK+ backend. As the cwidget library homepage says:

cwidget was originally an internal user interface library for the aptitude package manager. This means, on the one hand, that cwidget is known to work in the real world for a real application; on the other hand, it means that the feature set of cwidget is coextensive with the requirements of aptitude.

Leave a Reply