> I've written a patch to enable setting the xterm (screen) title from a
> less prompt. The standard prompting mechanism is unable to do that
> because 1) the terminal has to support titles and 2) less shortens the
> prompt to fit into a single row, but should not count the title
> characters.

Hi AnĂ­bal,

I'd like to throw in another coin for this wishlist item. I've been
using this patch locally for years, and config files with the new
prompt items even work with unpatched less binaries without problems.
Would you consider adding it to the less package in Debian?

Christoph
-- 
[EMAIL PROTECTED] | http://www.df7cb.de/
diff -u less-393/less.nro less-393/less.nro
--- less-393/less.nro
+++ less-393/less.nro
@@ -1298,6 +1298,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.
@@ -1348,6 +1352,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)
@@ -1398,6 +1404,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-393.orig/prompt.c
+++ less-393/prompt.c
@@ -60,6 +60,7 @@
 
 static char message[PROMPT_SIZE];
 static char *mp;
+static char *mp_nonprint;      /* marker for end of printable part */
 
 /*
  * Initialize the prompt prototype strings.
@@ -183,6 +184,7 @@
        int where;
 {
        POSITION len;
+       char *term;
 
        switch (c)
        {
@@ -230,6 +232,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);
 }
@@ -377,6 +383,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 */
        }
 }
 
@@ -479,6 +491,7 @@
        int where;
 
        mp = message;
+       mp_nonprint = NULL;
 
        if (*proto == '\0')
                return ("");
@@ -531,6 +544,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)
        {
                /*
# $Id: .lesskey 1415 2005-08-13 10:28:06Z cb $

#command
-       back-screen
=       toggle-option
\t      next-file
p       prev-file
^H      prev-file
       prev-file

#env
# ?X and %[ work with less >= 382
LESS=-aiMq -PM?f%f:stdin. ?n?m(file %i of %m) ..?ltlines %lt-%lb?L/%L. :byte 
%bB?s/%s. .?e(END) ?x- Next\\: %x.:?pB%pB\\%..%t?X%[\033]0;less ?f%f:stdin.?m 
[%i/%m].\007.
#LESSCHARSET=latin1

Attachment: signature.asc
Description: Digital signature

Reply via email to