6 months agoMerge branch utf8 into master master
Helmut Grohne [Fri, 22 Jan 2021 19:15:04 +0000 (20:15 +0100)]
Merge branch utf8 into master

6 months agoREADME.md: improve spelling and formatting
Helmut Grohne [Fri, 22 Jan 2021 18:53:44 +0000 (19:53 +0100)]
README.md: improve spelling and formatting

6 months agoignore bracketed pasted mode for now
Helmut Grohne [Fri, 22 Jan 2021 13:39:02 +0000 (14:39 +0100)]
ignore bracketed pasted mode for now

When asked to enable or disable bracketed paste mode, we simply do
nothing for now. It's not great, but at least it makes the escape
sequence not clutter the view.

3 years agoimplement "el" family properly
Helmut Grohne [Fri, 3 Nov 2017 21:23:59 +0000 (22:23 +0100)]
implement "el" family properly

el0 simply is el.

el1 was implemented improperly and missed clearing the character under
the cursor.

el2 clears the whole line.

3 years agofix writing of utf8 chars in the last column
Helmut Grohne [Fri, 3 Nov 2017 20:22:38 +0000 (21:22 +0100)]
fix writing of utf8 chars in the last column

Using insch is nice, because it does not update the cursor position, but
it does not work with utf8 chars and outputs garbage instead.

The problem can be avoided by using addch, but it creates a new problem:
addch moves the cursor. For all but the very last character on the
screen that's fine, but adding the last character on the screen means
scrolling. Thus we follow the advice from
http://stackoverflow.com/a/41923640/1626632 and disable scrolling and
catching the exception.

4 years agoinitial utf8 support
Helmut Grohne [Mon, 16 Jan 2017 19:39:20 +0000 (20:39 +0100)]
initial utf8 support

Derive a UTF8Terminal class from Terminal that handles utf8 byte
sequences. It only works on Python 3.x, because feed_utf8 relies on
addch handling unicode str objects. The whole utf8 support is also
conditional to Python 3.x, because the locale module was not safe to use
in Python 2.x.

A terminal is considered utf8 if the LC_* or LANG variables indicate

This branch still has known crashes. Writing non-ascii letter at the end
of a line or letting it scroll from one column to another causes
crashes. More problems may hide elsewhere.

4 years agoimplement cursor position reporting (u7)
Helmut Grohne [Tue, 10 Jan 2017 11:37:07 +0000 (12:37 +0100)]
implement cursor position reporting (u7)

This is used by a number of programs (including vim) to determine utf8
terminal capabilities.

The feed functions now return none or a bytes object. If a bytes object
is returned, it is sent back to the requesting program.

4 years agoimprove corner cases related to resizing and mode switching
Helmut Grohne [Thu, 5 Jan 2017 19:26:13 +0000 (20:26 +0100)]
improve corner cases related to resizing and mode switching

A few operations would previously fail unexpectedly:
 * Running tcvt with many columns and a small terminal width would crash
   instead of falling back to a simple screen.
 * After switching the mode, column ordering would be lost.
 * Switching the mode from simple to columns after resizing could result
   in a crash.

Instead of collecting the screen options and passing them down
individually, the Terminal class now asks for a preconfigured screen
factory. This should eliminate future potential for similar mistakes.

4 years agofix broken color handling
Helmut Grohne [Mon, 19 Dec 2016 19:13:21 +0000 (20:13 +0100)]
fix broken color handling

When printing "\e[32mx\e[33mx\e[32mx\e[0m", the expected outcome is that
the first and third x share the same color. Prior to clearing A_COLOR,
the colors would be ORed yielding three different colors. This breaks
e.g. usage with mutt.

4 years agoremove unused inch method
Helmut Grohne [Thu, 15 Dec 2016 09:21:42 +0000 (10:21 +0100)]
remove unused inch method

The last user got removed with 458ccd1cdc60 ("fix rendering of alternate
font for ncmpc").

4 years agofix SIGWINCH race condition during startup
Helmut Grohne [Wed, 14 Dec 2016 09:08:44 +0000 (10:08 +0100)]
fix SIGWINCH race condition during startup

Some programs (e.g. ncmpc) do not like receiving a terminal of unknown
size. Before we issue the resizepty method that would be the case. Since
there was no synchronisation between resizepty and execvp, a program
that starts quickly could run into this situation. Now we ensure that
resizepty is called before execvp using an extra pipe.

4 years agonote known breakage with FreeBSD's curses
Helmut Grohne [Mon, 12 Dec 2016 19:33:48 +0000 (20:33 +0100)]
note known breakage with FreeBSD's curses

On FreeBSD, curses.tigetstr('acsc') will return None unless Python is
built against ncurses.

Reported-By: Klaus Aehlig <aehlig@linta.de>
4 years agoMake tcvt aware of the OSC sequences
Klaus Aehlig [Tue, 28 Jun 2016 08:39:56 +0000 (10:39 +0200)]
Make tcvt aware of the OSC sequences

Ansi is vague about the meaning of the OSC sequences (i.e.,
the control sequences starting with <esc> ]): the interpretation is
up to the operating system. Nevertheless, some programs send these
sequences, most prominently the one to set the terminal title (OSC 0;).
So make tcvt aware of those sequences and pass them through.

Signed-off-by: Helmut Grohne <helmut@subdivi.de>
4 years agoconvert more branches into table lookups
Helmut Grohne [Sat, 10 Dec 2016 06:26:38 +0000 (07:26 +0100)]
convert more branches into table lookups

4 years agoprecompute lookup tables
Helmut Grohne [Sat, 10 Dec 2016 05:48:38 +0000 (06:48 +0100)]
precompute lookup tables

This improves performance of output-heavy workloads (e.g. the time it
takes to run find on a large tree) by 10% on CPython 2.7.

4 years agofix adding characters at the end of the window
Helmut Grohne [Fri, 9 Dec 2016 20:14:16 +0000 (21:14 +0100)]
fix adding characters at the end of the window

When the number of columns wasn't exactly 2 (the default), adding a
character at the end of the window could fail at scrolling thus yielding
corrupted output.

4 years agopush the refresh logic into the Terminal class
Helmut Grohne [Fri, 9 Dec 2016 10:54:25 +0000 (11:54 +0100)]
push the refresh logic into the Terminal class

One advantage of doing so is that the main function becomes simpler.
Another advantage is that the Terminal class has better knowledge of
when refreshes are actually needed. It also means that one more refresh
call can be coalesced into the logic. The major downside is that it
requires annotating all screen operations.

4 years agoimprove sub process handling: return child exit code
Helmut Grohne [Fri, 9 Dec 2016 09:29:55 +0000 (10:29 +0100)]
improve sub process handling: return child exit code

Wrap the management of the sub process in a new class ForkPty. This
reduces the length and number of variables in the main function. Turn it
into a context manager to allow closing the masterfd and actually
waiting for the forked child (rather than reparenting it to init on
exit). This also allows propagating the exit code. Document the new exit

4 years agosimplify Terminal start and stop using a context manager
Helmut Grohne [Fri, 9 Dec 2016 08:15:14 +0000 (09:15 +0100)]
simplify Terminal start and stop using a context manager

6 years agofix manual page syntax
Helmut Grohne [Thu, 7 May 2015 14:24:36 +0000 (16:24 +0200)]
fix manual page syntax

Reported-By: Alfredo Canziani <alfredo.canziani@gmail.com>
6 years agoAdd an option to reverse the column order
Klaus Aehlig [Tue, 5 May 2015 21:58:37 +0000 (23:58 +0200)]
Add an option to reverse the column order

In this way, for long dialoges (e.g., shell, ed) the focus
is in the lower left corner of the screen---the same as for
one-column terminals. Therefore, users used to that focus
can use this option to avoid changing reading habits.

6 years ago"\b" is also known as cub1
Helmut Grohne [Mon, 9 Feb 2015 22:06:31 +0000 (23:06 +0100)]
"\b" is also known as cub1

8 years agoname two more terminal functions hpa and vpa
Helmut Grohne [Sat, 22 Jun 2013 10:26:31 +0000 (12:26 +0200)]
name two more terminal functions hpa and vpa

8 years agosupport attributes blink and invis
Helmut Grohne [Sat, 22 Jun 2013 09:53:53 +0000 (11:53 +0200)]
support attributes blink and invis

8 years agoconfused terminfo "ind" and "ht"
Helmut Grohne [Thu, 20 Jun 2013 20:06:11 +0000 (22:06 +0200)]
confused terminfo "ind" and "ht"

8 years agouse terminfo capability names
Helmut Grohne [Thu, 20 Jun 2013 18:29:10 +0000 (20:29 +0200)]
use terminfo capability names

Implement terminfo capabilities as do_CAP on the Terminal class. This is
a bit more generic and might allow to pull the parsing from terminfo at
some point.

8 years agouse bytearrays
Helmut Grohne [Thu, 20 Jun 2013 11:47:46 +0000 (13:47 +0200)]
use bytearrays

With bytearrays there is no need for hacks specific to the Python
version such as byte_sequence.

8 years agoadd mappings for Fn keys
Helmut Grohne [Mon, 3 Jun 2013 06:43:08 +0000 (08:43 +0200)]
add mappings for Fn keys

We don't gain anything here, because the emulated terminal does not
support these keys. Should we switch the emulated terminal, this
immediately helps.

8 years agoclear screen on WINCH
Helmut Grohne [Mon, 3 Jun 2013 06:20:57 +0000 (08:20 +0200)]
clear screen on WINCH

Most applications do a full redraw on WINCH anyway. A shell doesn't and
looks ugly.

8 years agofix WINCH handling
Helmut Grohne [Sun, 2 Jun 2013 13:36:11 +0000 (15:36 +0200)]
fix WINCH handling

 * The switch to single column on WINCH was a bad idea.
 * The new window would get old dimensions, because we would
   reinitialize windows before curses noticed the new dimensions.

8 years agoallow specifying the number of columns
Helmut Grohne [Sun, 2 Jun 2013 12:03:09 +0000 (14:03 +0200)]
allow specifying the number of columns

8 years agomanpage: explain TCVT_DEVEL variable
Helmut Grohne [Sun, 2 Jun 2013 11:26:07 +0000 (13:26 +0200)]
manpage: explain TCVT_DEVEL variable

8 years agosupport python3.3
Helmut Grohne [Sun, 2 Jun 2013 11:19:30 +0000 (13:19 +0200)]
support python3.3

8 years agosupport not crashing on unsupported sequences
Helmut Grohne [Sun, 2 Jun 2013 10:44:27 +0000 (12:44 +0200)]
support not crashing on unsupported sequences

8 years agoimplement full alternate character set
Helmut Grohne [Sun, 2 Jun 2013 08:52:32 +0000 (10:52 +0200)]
implement full alternate character set

We now get the characters from terminfo "acsc".

8 years agoadd new input mode feed_graphics
Helmut Grohne [Sun, 2 Jun 2013 08:03:59 +0000 (10:03 +0200)]
add new input mode feed_graphics

Thereby we avoid accidentally treating graphics chars as regular chars,
just because they were not yet implemented.

8 years agoadded more line drawing characters
Helmut Grohne [Sat, 1 Jun 2013 19:36:00 +0000 (21:36 +0200)]
added more line drawing characters

This makes aptitude work.

Reported-By: Axel Beckert
8 years agoadded a README
Helmut Grohne [Sat, 1 Jun 2013 13:52:01 +0000 (15:52 +0200)]
added a README

8 years agoswallow exceptions for unknown keys
Helmut Grohne [Sat, 2 Feb 2013 00:22:42 +0000 (01:22 +0100)]
swallow exceptions for unknown keys

Most often this feature comes at an inconvenient time. If a key turns
out dysfunctional, export TCVT_DEVEL=1 to see the value of the key.

8 years agoif argv is empty, start a $SHELL
Helmut Grohne [Sat, 2 Feb 2013 00:09:08 +0000 (01:09 +0100)]
if argv is empty, start a $SHELL

8 years agosupport more than two columns
Helmut Grohne [Mon, 27 Aug 2012 12:39:24 +0000 (14:39 +0200)]
support more than two columns

The TwoColumn class is renamed to Columns since it now has a
configurable number of columns. Note that this support is not to the
command line yet.

9 years agomanpage: mention homepage
Helmut Grohne [Sun, 15 Apr 2012 12:53:44 +0000 (14:53 +0200)]
manpage: mention homepage

9 years agotcvt: code cleanup using properties
Helmut Grohne [Sun, 15 Apr 2012 12:28:45 +0000 (14:28 +0200)]
tcvt: code cleanup using properties

9 years agoMakefile: don't fail to install twice
Helmut Grohne [Sun, 15 Apr 2012 11:55:41 +0000 (13:55 +0200)]
Makefile: don't fail to install twice

9 years agoprint a reasonable error message when exec fails
Helmut Grohne [Sun, 15 Apr 2012 11:54:30 +0000 (13:54 +0200)]
print a reasonable error message when exec fails

9 years agoadded manual page tcvt.1
Helmut Grohne [Sun, 15 Apr 2012 11:25:21 +0000 (13:25 +0200)]
added manual page tcvt.1

9 years agosupport outputting ACS_VLINE
Helmut Grohne [Tue, 4 Oct 2011 16:46:48 +0000 (18:46 +0200)]
support outputting ACS_VLINE

This enables running tcvt inside tcvt resulting in four non-linearly
ordered columns.

9 years agoreduce screen.refresh()
Helmut Grohne [Fri, 30 Sep 2011 08:22:57 +0000 (10:22 +0200)]
reduce screen.refresh()

Previously it would refresh after at most 1024 bytes of output. With a
slow terminal and much output this can be very annoying. So now we only
refresh when there is no more output or a tenth of a second has passed
since the last output.

9 years agofixed enter key in vim
Helmut Grohne [Wed, 14 Sep 2011 20:47:16 +0000 (22:47 +0200)]
fixed enter key in vim

10 years agopass through \xb4 (some tick) and \xe9 (accent e)
Helmut Grohne [Fri, 22 Jul 2011 16:08:41 +0000 (18:08 +0200)]
pass through \xb4 (some tick) and \xe9 (accent e)

10 years agoimplement \t output
Helmut Grohne [Wed, 8 Jun 2011 08:43:59 +0000 (10:43 +0200)]
implement \t output

10 years agoadded Makefile for easy installation
Helmut Grohne [Sun, 27 Feb 2011 16:16:12 +0000 (17:16 +0100)]
added Makefile for easy installation

10 years agoadded optcvt.sh
Helmut Grohne [Sat, 26 Feb 2011 15:45:20 +0000 (16:45 +0100)]
added optcvt.sh

Executes tcvt iff the resulting width is at least 80 chars.

10 years agofix rendering of alternate font for ncmpc
Helmut Grohne [Sat, 26 Feb 2011 13:54:19 +0000 (14:54 +0100)]
fix rendering of alternate font for ncmpc

10 years agouse tigetstr to resolve ansi key sequences
Helmut Grohne [Sat, 26 Feb 2011 13:11:07 +0000 (14:11 +0100)]
use tigetstr to resolve ansi key sequences

10 years agoproperly process input keys with curses' getch
Helmut Grohne [Sat, 26 Feb 2011 12:57:53 +0000 (13:57 +0100)]
properly process input keys with curses' getch

10 years agoinitial checkin
Helmut Grohne [Sat, 26 Feb 2011 12:35:23 +0000 (13:35 +0100)]
initial checkin