» Archive for September, 2010

Buffered text in dvtm

Friday, September 10th, 2010 by Niki

I love dvtm. I do a lot of development over ssh these days and having an application handle multiple terminals is practically a necessity. At first I was using gnu screen, however I found it a little cumbersome to use for my purposes. gnu screen doesn’t have many layout options – you are either looking at one terminal or several terminals arranged in a single stack. Switching between these is annoying as well. dvtm on the other hand has several different layouts and makes it easy to switch between them.

Gnu screen, however, does have several features that dvtm does not. For example, with screen you can detach from the controlling terminal and reattach later. Fortunately dtach takes care of that and it’s easy to run dvtm inside dtach. Another great feature of gnu screen is that it reflows text – when you resize the terminal screen will automatically word wrap the text. dvtm doesn’t do this and I haven’t found any unix shell that does this either. What’s worse is that dvtm will cut off the text when a terminal is made smaller and that text is gone – even if you later restore that terminal to its original size.

Reflowing is a fairly non-trivial thing to do so I opted for the next best thing – making sure that dvtm doesn’t permanently cut off the text. This actually turned out to be fairly easy – dvtm keeps a character array for each row in each terminal. This array is realloced every time a terminal is resized. When a terminal decreases in size, the arrays are realloced so they are smaller. I simply changed the behavior so that they arrays are only realloced when a terminal increases in size such that it’s larger than the previous largest. This means that dvtm’s memory usage is potentially greater, but it also means that it makes fewer memory allocations.

You can find my patch on the dvtm project page.