Chad Perrin: SOB

2 February 2010

How I Use XTerm

Filed under: Geek — apotheon @ 05:14

I thought I had already posted something about this to SOB, but I just realized that I had only talked about it on a mailing list.

Basically . . . one of the things I dislike about XTerm is the way it handles multi-click text highlighting by default. Another is the fact that it doesn’t do Unicode by default. Of course, XTerm does everything, one way or another — or so it seems. It just takes working around the defaults somehow.

To solve the Unicode problem, just set the “UXTerm” X resource, which includes applying the effects of XTerm’s -class and -u8 options. On at least most systems, entering the command uxterm (instead of xerm) should do the trick there. It seems that someone somewhere along the way came up with the brilliant idea of providing a standard UXTerm resource-active wrapper for XTerm.

To solve the multi-click highlighting problem, your XTerm app-defaults file (on FreeBSD, that’d be /usr/local/lib/X11/app-defaults/XTerm) can be edited to include some lines to specify exactly what characters are considered valid highlighting characters for a given number of clicks. Anything up to five clicks can be defined this way.

There are specific terms with specific meanings that can be used here, and the default for two clicks is XTerm’s concept of a “word” — which is fine by me. The defaults for three through five clicks, however, don’t work so well for me. In fact, by default, three clicks will match a “line”, and both four and five clicks have no default at all. Other than “word” and “line”, though, none of the options (which are listed in the XTerm manpage under the on5Clicks resource) match any of the things I’d really like to see highlighted on a given number of clicks. Luckily, the XTerm app-defaults file also supports a (limited) regex syntax for the onNClicks resources, where N is the number of clicks.

Keeping the on2Clicks default, the configuration I use to customize multi-click highlighting is:

xterm*on3Clicks:  regex [^ \n]+
xterm*on4Clicks:  regex .*
xterm*on5Clicks:  line

So. That’s the long and the short of it. Other than that, all I use that isn’t an XTerm default on my FreeBSD systems is a pair of options — specifically, the -r and -sb options (for “reverse video” and “scroll bar”, respectively).

addenda:

If you wish these changes to apply only to UXTerm on FreeBSD, the appropriate file to edit is /usr/local/lib/X11/app-defaults/UXTerm. The proper location for this file may vary among Linux distributions.

5 Comments

  1. While I don’t particularly care for the onclick crap (too much experience with M$s implementation to want to use it anywhere), the UTF support would be nice. Thanks!

    Comment by Joseph A nagy Jr — 2 February 2010 @ 08:35

  2. Do you not ever click on text twice to highlight a word, or three times to get the whole line (for instance)? Considering how easy it is to copy/paste within X by highlighting some text then middle-clicking where I want to paste that text, the multi-click highlight functionality of a terminal emulator is extremely handy for me.

    Comment by apotheon — 2 February 2010 @ 09:08

  3. I just click, highlight, middle-click where I need it to be. I actually find the click-select to be more annoying than anything else. It’s good that people find it useful, but I got so annoyed by it’s use in windows (especially in IE and Windows Explorer’s address/location bar, when I’m trying to position the cursor and a word or the whole url is completely highlighted). Maybe in time I’ll find it handy, too, but right now I still remember the horror of just trying to position a cursor without that function executing so I could select a section of URL or even highlight one particular letter. I often had to resort to using shift+arrow-key to do what should have easily been done via mouse.

    Since most of my time in an terminal emulator or even the console (I love having a real mouse cursor @ the console) is either in vim (where I don’t think you can use the mouse to position the cursor unless using gvim) editing HTML or some other document or installing/updating a piece of software, at which point such functionality never comes into play. at least for me. The other options – such as for unicode support – are really useful to know. I’ll be editing the appropriate wmaker conf files to execute uxterm instead of normal xterm. Not sure what reverse video and a scroll bar would truly be useful.

    Comment by Joseph A nagy Jr — 2 February 2010 @ 11:16

  4. Well, yeah — the way MS Windows handles click-to-highlight is incredibly annoying. One click should never highlight an entire line. It’s completely bass-ackwards.

    As I said, I was talking about highlighting for purposes of copy/paste, and not cursor positioning. One of the things I rather like about console-based Vim is the fact that I don’t have to aim the mouse cursor when using middle-click to paste something I’ve highlighted elsewhere; no matter where in the terminal emulator window I middle-click, the text automatically pastes wherever the console cursor was left.

    Outside of Vim, I find that kind of functionality handy in cases such as when I use ls to see the contents of a directory, then want to open a file that’s in that directory without typing the whole thing, even if the name of the file I want to open is substantially similar to the names of a bunch of other files in the same directory. For instance, if I have files named foobarbaz00.txt through foobarbaz87.txt, and I also have files named foobarbaz1.txt through foobarbaz4.txt, and filenames foobarbazqux12.txt through foobarbazqux33.txt, not to mention the foo0.txt through foo9.txt and foobar00.txt through foobar99.txt files, but the one I want happens to be foobarbaz72.txt (yes, this is an intentionally extreme hypothetical case), using tab completion can get kind of annoying. With XTerm’s onNClicks resources set up the way I have them configured, I can just triple-click the specific filename I want then middle-click to paste it.

    The times when the multi-click highlight capabilities are most useful, though, are probably those times when I need to copy something from a terminal emulator window (such as some snippet from a text file opened in Vim) and paste it in some other application such as Firefox. This is one of those cases where it can be easier to just use the mouse to highlight than to first exit the file then type something like grep "Ruby.*Ruby" filename.txt|head -n 1|xclip, as long as I don’t have to do some annoying click-and-drag operation. I guess your mileage may vary, though.

    Reverse video just reverses the foreground and background colors. Staring at a white background with black text for too long fatigues the eyes a lot, and I find it much easier to work with white text on a black background. I could specify colors more specifically than by using -r, but -r is a lot quicker and easier for much the same result, so I just use that.

    The scrollbar is handy for when I want to be able to view the output of some program that fills up more than one screen and, for whatever reason, piping to less doesn’t work (some programs’ output for some reason doesn’t play well under such circumstances). The scrollbar can also be handy when I want to see previous output that’s off the top of the screen while I’m using tail -f to monitor constant output from some program that is still periodically generating more output. I’m not the world’s biggest fan of XTerm’s scrollbars (yet?), but they’re occasionally better than nothing.

    Comment by apotheon — 3 February 2010 @ 10:02

  5. I see what you are getting at. Yeah, that would be useful and more convenient then click-drag. Perhaps I’ll set those rules up and test them out for a while before I make a final choice with regard to xterm. It’s going to take a while, though, as you’ve confirmed, the behavior most people are used to (click and it highlights the whole url) is very annoying, and there is no multiple click settings (at least not in FF (and not that I’ve found, I bet they are hidden in about:config), seeing as how I don’t use IE anymore).

    Comment by Joseph A Nagy Jr — 4 February 2010 @ 09:06

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

All original content Copyright Chad Perrin: Distributed under the terms of the Open Works License