bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Colored output


From: Bruno Haible
Subject: Re: Colored output
Date: Sun, 24 Mar 2019 23:22:51 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; )

Hi Jim,

> > Or would it be better to separate the pure signal handling and tty cleanup
> > code from the code that looks up the appropriate escape sequences from
> > termlib/termcap, and create a module in gnulib with only the signal handling
> > and tty cleanup code?
> 
> I'm happy to use whichever approach you prefer, especially if you
> provide the patch.

I've taken the approach of adding a module in gnulib that does only the
signal handling and tty cleanup. Code review welcome!


2019-03-24  Bruno Haible  <address@hidden>

        term-style-control: Add tests.
        * tests/test-term-style-control-hello.c: New file.
        * tests/test-term-style-control-yes.c: New file.
        * modules/term-style-control-tests: New file.

        term-style-control: New module.
        * lib/term-style-control.h: New file, based on libtextstyle's
        term-ostream.oo.h and term-ostream.oo.c.
        * lib/term-style-control.c: New file, based on libtextstyle's
        term-ostream.oo.c.
        * modules/term-style-control: New file.


Now you can use this to make the color cleanup in 'grep', 'diff', and 'ls'
reliable.

Test case for 'grep':
$ yes | grep --color y
then interrupt with Ctrl-C. Retry 10 times.

Test case for 'diff':
$ for i in `seq 100000`; do { echo abc; echo x; echo def; }; done > i1
$ for i in `seq 100000`; do { echo abc; echo y; echo def; }; done > i2
$ diff --color -u i1 i2
then interrupt with Ctrl-C. Retry 20 times.

Test case for 'ls':
  - Create a directory with many files in it:
    $ for i in `seq 100000`; do touch xyz$i; done
    $ chmod a+x xyz*
  - Run 'ls' and interrupt is through Ctrl-C after 0.3 seconds. The result
    may end like this, with a stray 'C' on the screen:
xyz18858   xyz30106  xyz41357  xyz52607  xyz63858  xyz75107  xyz86358  xyz97608
xyz18859   xyz30107  C
xyz18914
  - Or run 'ls' and use Ctrl-Z to interrupt it. You may see
xyz19924   xyz31173  xyz42423  xyz53674  xyz64924  xyz76174  xyz87424  xyz98675
xyz19925   xyz31174  xy^Z
xyz19982
    That is, the output continues after it was interrupted through Ctrl-Z.

Bruno

Attachment: 0001-term-style-control-New-module.patch
Description: Text Data

Attachment: 0002-term-style-control-Add-tests.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]