Cleanup by moving various (mostly horrible) little bits handling UTF-8 grid
data into functions in a new file, grid-utf8.c, and use sizeof intead of
UTF8_DATA.
Also nuke trailing whitespace from tmux.1, reminded by jmc.
Add an explicit zero-length check for UTF-8 input data, prompted by a report
from parfait via deraadt.
While here, add a statement to set the width when filling with _s if not enough
space (width should never be high enough at the moment anyway), and wrap some
long lines.
Try to reduce the UTF-8 mess.
Get rid of passing around u_char[4]s and define a struct utf8_data which has
character data, size (sequence length) and width. Move UTF-8 character
collection into two functions utf8_open/utf8_append in utf8.c which fill in
this struct and use these functions from input.c and the various functions in
screen-write.c.
Space for rather more data than is necessary for one UTF-8 sequence is in the
utf8_data struct because screen_write_copy is still nasty and needs to reinject
the character (after combining) into screen_write_cell.
UTF-8 combined character fixes.
Thai can have treble combinations (1 x width=1 then 2 x width=0) so bump the
UTF-8 cell data size to 9 and alter the code to allow this.
Also break off the combining code into a separate function, handle any further
combining beyond the buffer size by replacing the character with _s, and when
redrawing the UTF-8 character don't assume the first part has just been
printed, redraw the entire line.
Move the check for whether to force a line wrapper lower down into the tty code
where it has access to the tty width, which is what should have been checked.
Instead of having a complicated check to see if the cursor is in the last
position to avoid an explicit wrap, actually move it there.
Some UTF-8 fixes to come.
When drawing lines that have wrapped naturally, don't force a newline but
permit them to wrap naturally again. This allows terminals that use this to
guess where lines start and end for eg mouse selecting (like xterm) to work
correctly.
This was another long-standing issue raised by several people over the last
while.
Thanks to martynas@ for much testing. This was not trivial to get right so
bringing it in for wider testing and adn to fix any further glitches in-tree.
When backspace is received at the beginning of a line and the previous line was
wrapped, move the cursor back up to the end of the previous line.
Another one of the forgotten persons requested this quite a while ago (I need
to start noting names on todo items...) when it was quite hard to
implement. Now it is easy and I don't see it can do any harm, so hey presto...
Stick line length to what is actually used (removing an optimization that
allowed it to be bigger), and use clear line/EOL sequences rather than spaces
in copy/scroll mode.
This fixes xterm copy/paste from tmux which treats trailing spaces differently
from clearing a line with the escape sequences. Reported by martynas@.
A few trivial optimisations: no need to check for zero size if calling
buffer_ensure in buffer.c; expand grid lines by a greater increase than one
each time; and don't read UTF-8 data unless it actually needs to be checked
when overwriting a cell.
It was originally intended that scroll mode would show content that was
currently off-screen due to resize, but somewhere along the way this got
lost. Restore this behaviour to scroll mode by fixing screen_write_copy to read
up to the saved line length rather than the current screen width. Copy mode
remains unaltered for now.
Add a flags member to the grid_line struct and use it to differentiate lines
wrapped at the screen edge from those terminated by a newline. Then use this
when copying to combine wrapped lines together into one.
enum tty_cmd is only used as an index into the array of command function
pointers, so remove it and use the function pointers directly to represent
themselves.
of characters which may be inserted or deleted is the screen width, not one
less (and similarly for lines and height); and if characters or lines are
deleted by moving the ones that follow, the space at the end needs to be
cleared.
This appears to solve long-standing redraw issues most visible when using the
force-width option then scrolling in view(1) or unwrapping lines in emacs.
done for UTF-8, limit to the maximum length correctly when printing, and always
print a space even if the left string is longer than the width available.
status-left/status-right work properly. At the moment any top-bit-set
characters are assumed to be UTF-8: a status-utf8 option to configure this will
come shortly.
as UTF-8 in a separate array, the code does a lookup into this every time it
gets to a UTF-8 cell. Zero width characters are just appended onto the UTF-8
data for the previous cell. This also means that almost no bytes extra are
wasted non-Unicode data (yay).
Still some oddities, such as copy mode skips over wide characters in a strange
way, and the code could do with some tidying.
Split grid into two arrays, one containing grid attributes/flags/colours (keeps
the name grid_cell for now) and a separate with the character data (called
text). The text is stored as a u_short but is treated as a uint64_t elsewhere;
eventually the grid will have two arrays.
I'm not happy with the naming so that might change.
Still need to decide where to go from here. I'm not sure whether to combine
the peek/set functions together, and also whether to continue to treat the
text as a uint64_t (and convert to/from Unicode) or make it a char array
(of size one when UTF-8 disabled, eight when enabled) and keep everything
as UTF-8.
Also since UTF-8 will eventually become an attribute of the grid itself it
might be nice to move all the padding crap into grid.c.