Trowser: A graphical less command that is more

103

Author: Bruce Byfield

Translating a command line tool to a graphical interface usually means a loss of functionality. However, in the case of the newly released trowser text browser, while I wouldn’t swear that the transition has retained all the functionality of the less command that it is intended to replace, I doubt that anyone short of an expert is likely to notice the difference. Not only does trowser offer a comparable wealth of key bindings for moving about displayed text files, but it also adds such features as custom highlighting, a search history, and bookmarks as well. The result is an easy-to-use tool for developers who browse code listings, or anyone who browses log files, HTML pages, or other plain text files.

Trowser is currently available as a compressed tar file, with no installation script. Instead, users need to check that they have Tcl/Tk 8.4.0 installed on their system, then copy the executable to /usr/bin and the man page file to /usr/share/man. The first time you use trowser, the program creates a .trowserc file in your home directory. This arrangement may lack sophistication, but has the advantage of making the program easy to remove after a trial.

Trowser starts from the shell, with the command followed by the plain text file you want to edit. If you choose, you can use the -t or -h option to set the number of bytes to display, measured from either the start or the end of the file. You also have the option at any time of discarding all of the file above or below the current cursor position.

Your chosen file displays in a window that, as might be expected from the widget set, is quick to appear but blocky and antiquated by the standards of users accustomed to Qt or Gtk2. Fonts are decidedly unaliased, although you have the option of using any font installed on the system; for maximum readability, I recommend a bold sans serif font, set to 12 points instead of the default 9. Similarly, lines are not wrapped to the window, which can necessitate plenty of horizontal scrolling, and, in the middle of a search, sometimes causes the window’s content to look as though it is having a fit of epilepsy. Nor are the top menu items — Control, Search, and Bookmark — exactly conventional, although they are easy enough to figure out in context.

However, if you can overlook such limitations (and I suspect that many of the developers at whom the program is aimed at probably can), trowser offers a convenient, easy-to-use set of tools. You enter search items in the bottom of the main window, using regular expressions if you choose, and specify whether to search for the last, previous, or all instances of the search text, and whether to match letter case. All lines containing the search term are highlighted, and you can abstract them to a separate window by selecting Search -> List search matches so that you can compare them more easily. You can also highlight a line and add it to the Search Matches window without going through a search.

After a successful search, you can open Search -> Edit highlight patterns to add the search to the Color highlights list. There, you can right-click and select Edit markup from the popup menu to assign unique colors or shadings for the background and foreground of the currently selected search. In addition, you can give the results of a search one of half a dozen types of borders, and set the distance between search results and the lines above or below them — all of which allows you to create complex visual identities for as many search results as you choose, making them easy to identify in the main window.

At any time, too, you can open the Search history from the Search menu to repeat a search. This feature is especially welcome when using regular expressions, the more complex of which can be difficult to type.

In addition to searching, trowser supports adding bookmarks, which are indicated by a blue dot at the start of a line. As with search results, you can view bookmarks in a list in a separate window. You may also choose to save them to a file with a .bok extension for later use.

As you scroll through a selected file, you can use the scroll bars or the arrow keys if you prefer, but trowser also supports a wide variety of Vim-inspired keyboard shortcuts. According to the project’s home page, trowser is “designed to allow browsing via the keyboard at least to the same extent as less,” and it certainly appears to succeed.

Trowser does depart from Vim’s bindings in several places, such as using i to insert the current line into the Search Matches window. Other differences, such as standardizing that n searches backward and N searches forward, rather than using N to reverse the search direction as in Vim, may be harder to remember for advanced Vim users, even if they are more rational. However, such differences are relatively few, and are more than offset by the much larger number of similarities in keybindings.

The choice of widgets aside, my only real objection to trowser is that, with such features, it isn’t a text editor — even though it never claims to be one, its features would be welcome in a text editor. But, as a graphical substitute for the less utility, it succeeds on its own terms, offering not only the ease of use that is customary in a graphical tool, but also enhancements that would be difficult or impossible from the command line. That is a difficult accomplishment, and it makes version 1.0 of trowser, in its own modest way, one of the more promising official releases I’ve seen for a while.

Categories:

  • Tools & Utilities
  • Desktop Software