Archive for September, 2009
Reduce the delay after ESC in ncurses
By chys on September 26th, 2009In ncurses-based programs, the default delay after the ESC key is way too long. (Such a delay is necessary to differentiate the ESC key from function keys.)
There seems to be no such delay in VIM. But with strace, we can find that VIM actually delays, but for only 25 milliseconds, shorter than 100ms – the minimal time interval that human can perceive:
read(0, "\33"..., 4096) = 1
select(6, [0 3 5], NULL, [0 3], {0, 0}) = 0 (Timeout)
gettimeofday({1253979790, 537775}, NULL) = 0
select(6, [0 3 5], NULL, [0 3], {0, 25000}) = 0 (Timeout)
If 25ms works reliably for VIM, so should it do for other programs. There seems to be no functions setting this interval in ncurses, but we can directly modify the global variable ESCDELAY. Ncurses also accepts the environment variable also named ESCDELAY, so we may also want to honor the user’s choice:
if (getenv ("ESCDELAY") == NULL)
ESCDELAY = 25;
Not confident in its portability, I detect this undocumented (it seems) feature with cmake in tiary (my project).
Update (Feb. 22, 2010): It’s preferable to use the function set_escdelay.
Ack is a good alternative to grep
By chys on September 6th, 2009When I grep -r something in a Subversion-controlled directory, I get a lot of results under the .svn.
In this sense, Git is better than Subversion. (Git creates only one .git directory, and stores data in some compressed format which gets ignored by grep -r.)
So I have switched to ack when working with Subversion. Ack is written in Perl, claimed to be “aimed at programmers with large trees of heterogeneous source code.”
