Hi, here's an updated version of my xterm/screen title patch for less.
Christoph --- less-406.orig/less.nro +++ less-406/less.nro @@ -1311,6 +1311,10 @@ Usually used at the end of the string, but may appear anywhere. .IP "%x" Replaced by the name of the next input file in the list. +.IP "%[" +Causes the remaining part not to be considered for the total length of the +prompt. This is useful for setting the xterm title. See ?X below. (This is +analogous to \e[ in bash's $PS1, but lacks the corresponding \e].) .PP If any item is unknown (for example, the file size if input is a pipe), a question mark is printed instead. @@ -1361,6 +1365,8 @@ .IP "?x" True if there is a next input file (that is, if the current input file is not the last one). +.IP "?X" +True if the terminal has a title bar. ($TERM matches xterm* or screen*.) .PP Any characters other than the special ones (question mark, colon, period, percent, and backslash) @@ -1411,6 +1417,12 @@ .sp ?f%f\ .?m(file\ %i\ of\ %m)\ .?ltlines\ %lt-%lb?L/%L.\ . byte\ %bB?s/%s.\ ?e(END)\ :?pB%pB\e%..%t +.sp +.fi +To put the filename in the xterm title bar, append the following to a prompt: +.nf +.sp + ?X%[\e033]0;less\ ?f%f:stdin.\e007. .fi .PP The prompt expansion features are also used for another purpose: --- less-406.orig/prompt.c +++ less-406/prompt.c @@ -63,6 +63,7 @@ static char message[PROMPT_SIZE]; static char *mp; +static char *mp_nonprint; /* marker for end of printable part */ /* * Initialize the prompt prototype strings. @@ -186,6 +187,7 @@ int where; { POSITION len; + char *term; switch (c) { @@ -233,6 +235,10 @@ return (0); #endif return (next_ifile(curr_ifile) != NULL_IFILE); + case 'X': /* Return true for xterm* and screen* */ + if(!(term = lgetenv("TERM"))) + return 0; + return !strncmp(term, "xterm", 5) || !strncmp(term, "screen", 6); } return (0); } @@ -380,6 +386,12 @@ else ap_quest(); break; + case '[': /* The following part is non-printing */ + mp_nonprint = mp; + break; + /* TODO: implement a %] pattern + * at the moment only one %[ pattern is recognized, extending to the end of + * the string */ } } @@ -482,6 +494,7 @@ int where; mp = message; + mp_nonprint = NULL; if (*proto == '\0') return (""); @@ -534,6 +547,9 @@ if (mp == message) return (""); + if (mp_nonprint) /* stop marker is set */ + /* consider printable part for width calculation */ + mp = mp_nonprint; if (maxwidth > 0 && mp >= message + maxwidth) { /*
signature.asc
Description: Digital signature