delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/04/04/11:16:45

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Thorsten Kampe <thorsten AT thorstenkampe DOT de>
Subject: Re: Escape colour codes
Date: Wed, 4 Apr 2007 16:15:50 +0100
Lines: 116
Message-ID: <ev0ff8$bbu$1@sea.gmane.org>
References: <etlt2v$aq0$1 AT sea DOT gmane DOT org> <euuhri$f63$1 AT sea DOT gmane DOT org> <euuih2$iro$1 AT sea DOT gmane DOT org> <euvkme$hv0$1 AT sea DOT gmane DOT org> <4613A562 DOT 5090806 AT byu DOT net>
Mime-Version: 1.0
User-Agent: MicroPlanet-Gravity/2.70.2067
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

* Eric Blake (Wed, 04 Apr 2007 07:17:22 -0600)
> According to Thorsten Kampe on 4/4/2007 1:38 AM:
> > That's exactly the point. They actually do cope with the escapes - 
> > just not with the \001 and \002 used by readline to calculate the 
> > length of the line.
> > 
> >> (otherwise even bash would not work).
> > 
> > Yes, bash is the exception. Maybe bash doesn't use \001/\002?
> 
> I need a simple test case.

It's easy to show that one Cygwin application (lftp) has a problem 
with its prompt but it's rather lenghty to show that not lftp is the 
culprit but readline making output to Windows Terminals (Cmd, 4NT, 
Console, FAR manager, Poderosa)

1. Install lftp, start cygwin.bat

2. Start lftp. Type
set cmd:prompt "\[\e[1;36m\]>\[\e[m\] "
...you will see that the instead of a light cyan "> " prompt you will 
get "> " surrounded by white/cyan-cyan/white "Funny Faces" (control 
characters).
Conclusion: there is something wrong with lftp or readline or the 
Terminal.

3. Run lftp from rxvt: you see that the prompt displays fine
Conclusion: there is nothing wrong with lftp.

4. Read Matthew Woehlke's statement "Windows consoles don't understand 
escapes, period."
Conclusion: there is nothing wrong with the Windows Terminal, readline 
might have a bug.

--

5. install yafc (http://yafc.sourceforge.net/) - another popular Linux 
FTP client (from source because there is no package yet)

6. Insert
prompt1 "%{\e[1;36m%}>%{\e[m%} "
into your yafcrc and start yafc

7. You will see exactly the same as in 2. with lftp
Conclusion: there is nothing wrong with yafc, but with readline or Cmd

8. Repeat 3. with yafc and see the same result
Conclusion: there is nothing wrong but readline might have a bug.

--

9. Install Python and IPython (http://ipython.scipy.org/moin/)
set
prompt_in1 '\C_White[\#\C_White]\C_LightCyan>>> '
prompt_out '\C_White[\N\C_White]    '
in your ipythonrc and start IPython. Type 1 [Enter]
you will see exactly the same as in 2. And 7. for the out prompt

10. Repeat step 3. with IPython: you will see exactly the same as in 
3. and 8. 

11. Install Windows Python and pyreadline (Python readline for 
Windows) and use the same IPython from the Cygwin installation. Repeat 
step 3.: the prompt displays fine
Conclusion: pyreadline doesn't make the Windows Terminal show Control 
characters

12. Remove the \001/\002 constructs in line 88 and 89 from 
ColorANSI.py in Cygwin IPython 

from
        Normal = '\001\033[0m\002'   # Reset normal coloring
        _base  = '\001\033[%sm\002'  # Template for all other colors

to

        Normal = '\033[0m'   # Reset normal coloring
        _base  = '\033[%sm'  # Template for all other colors

See that Cygwin IPython with Windows terminal now displays correctly

--

13. Recompile yafc, comment out lines 167 and 172 in prompt.c

			case '{': /* begin non-printable character string */
#ifdef HAVE_LIBREADLINE
//				ins = "\001\001"; /* \001 + 
RL_PROMPT_START_IGNORE */
#endif
				break;
			case '}': /* end non-printable character string */
#ifdef HAVE_LIBREADLINE
//			ins = "\001\002"; /* \001 + RL_PROMPT_END_IGNORE */
#endif

Now see that yafc does not show the Control characters as "Funny 
Faces" anymore.

--

I tried to modify the lftp source, too, but my C knowledge was not 
sufficient

   char StartIgn[3], EndIgn[3];
   /* bash adds the extra \001 too, don't know why */
   StartIgn[0] = '\001';
   StartIgn[1] = RL_PROMPT_START_IGNORE;
   StartIgn[2] = 0;
   EndIgn[0] = '\001';
   EndIgn[1] = RL_PROMPT_END_IGNORE;
   EndIgn[2] = 0;


Thorsten


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019