aboutsummaryrefslogtreecommitdiff
path: root/vt.c (follow)
Commit message (Collapse)AuthorAgeLines
* vt: add some unit tests for action_collect()Craig Barnes2021-07-02-0/+23
|
* config: rename at-most-2 (value for grapheme-width-method) to double-widthDaniel Eklöf2021-07-01-1/+1
|
* config: add tweak.grapheme-width-method=wcswidth|at-most-2Daniel Eklöf2021-07-01-5/+14
|
* vt: limit grapheme width to 2 cellsDaniel Eklöf2021-07-01-5/+3
| | | | | | | | | | | | All emoji graphemes are double-width. Foot doesn’t support non-latin scripts. Ergo, this should result in the Right Thing, even though we’re not doing it the Right Way. Note that we’re now breaking cursor synchronization with nearly all applications. But the way I see it, the applications need to be updated.
* vt: don’t reset utf8proc grapheme state when we’re not at a grapheme breakDaniel Eklöf2021-06-25-5/+8
|
* vt: utf8: rotate instead of just shifting when updating compose keyDaniel Eklöf2021-06-24-4/+7
| | | | This reduces the number of collisions in even more workloads.
* vt: improved key hash algorithm -> reduces number of key collisionsDaniel Eklöf2021-06-24-3/+10
|
* composed: insert: require key to be uniqueDaniel Eklöf2021-06-24-3/+5
|
* vt: codespell: bumb -> bumpDaniel Eklöf2021-06-24-1/+1
|
* composed: store compose chains in a binary search treeDaniel Eklöf2021-06-24-38/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation stored compose chains in a dynamically allocated array. Adding a chain was easy: resize the array and append the new chain at the end. Looking up a compose chain given a compose chain key/index was also easy: just index into the array. However, searching for a pre-existing chain given a codepoint sequence was very slow. Since the array wasn’t sorted, we typically had to scan through the entire array, just to realize that there is no pre-existing chain, and that we need to add a new one. Since this happens for *each* codepoint in a grapheme cluster, things quickly became really slow. Things were ok:ish as long as the compose chain struct was small, as that made it possible to hold all the chains in the cache. Once the number of chains reached a certain point, or when we were forced to bump maximum number of allowed codepoints in a chain, we started thrashing the cache and things got much much worse. So what can we do? We can’t sort the array, because a) that would invalidate all existing chain keys in the grid (and iterating the entire scrollback and updating compose keys is *not* an option). b) inserting a chain becomes slow as we need to first find _where_ to insert it, and then memmove() the rest of the array. This patch uses a binary search tree to store the chains instead of a simple array. The tree is sorted on a “key”, which is the XOR of all codepoints, truncated to the CELL_COMB_CHARS_HI-CELL_COMB_CHARS_LO range. The grid now stores CELL_COMB_CHARS_LO+key, instead of CELL_COMB_CHARS_LO+index. Since the key is truncated, collisions may occur. This is handled by incrementing the key by 1. Lookup is of course slower than before, O(log n) instead of O(1). Insertion is slightly slower as well: technically it’s O(log n) instead of O(1). However, we also need to take into account the re-allocating the array will occasionally force a full copy of the array when it cannot simply be growed. But finding a pre-existing chain is now *much* faster: O(log n) instead of O(n). In most cases, the first lookup will either succeed (return a true match), or fail (return NULL). However, since key collisions are possible, it may also return false matches. This means we need to verify the contents of the chain before deciding to use it instead of inserting a new chain. But remember that this comparison was being done for each and every chain in the previous implementation. With lookups being much faster, and in particular, no longer requiring us to check the chain contents for every singlec chain, we can now use a dynamically allocated ‘chars’ array in the chain. This was previously a hardcoded array of 10 chars. Using a dynamic allocated array means looking in the array is slower, since we now need two loads: one to load the pointer, and a second to load _from_ the pointer. As a result, the base size of a compose chain (i.e. an “empty” chain) has now been reduced from 48 bytes to 32. A chain with two codepoints is 40 bytes. This means we have up to 4 codepoints while still using less, or the same amount, of memory as before. Furthermore, the Unicode random test (i.e. write random “unicode” chars) is now **faster** than current master (i.e. before text-shaping support was added), **with** test-shaping enabled. With text-shaping disabled, we’re _even_ faster.
* vt: utf8: don’t scan *all* previous chainsDaniel Eklöf2021-06-24-1/+3
| | | | | | | | | | | | | | | | | | | | | | When checking if we already have a compose chain for the current sequence of characters, don’t search the list from the beginning, unless we have to. Taking the following things into consideration: * New compose chains are always appended at the end of the list * If the current sequence is 3 or more characters, it *must* consist of an existing compose chain, plus the new character. Thus, when searching, start at index 0 if we only have two characters, since then the base cell originally contained a regular base character, and not a compose chain. I.e. the new chain may be _anywhere_ in the chain list. If however we have a sequence of three or more characters, start at the index the *base* chain was at. If the chain we’re searching for exists, it *must* have been added *after* the base chain, and thus it *must* be located *after* the base chain in the chain list.
* vt: utf8: de-duplicate; jump to end of function to print to gridDaniel Eklöf2021-06-24-26/+25
|
* vt: utf8-print: don’t build a compose chain on a zero-width base characterDaniel Eklöf2021-06-24-87/+89
|
* vt: utf8-print: check base character before count when looking for existing compose chainDaniel Eklöf2021-06-24-2/+2
| | | | | Count is more likely to be the same for many chains. Thus we’re likely to fail sooner by checking the base character first.
* vt: don’t call wcwidth() on all combining characters every time we addDaniel Eklöf2021-06-24-11/+7
| | | | | | | We already have all the widths needed to calculate the new one; it’s the base characters width (base_width), or the previous combining chain’s width (composed->width) plus the new characters’s width (width).
* vt: presentation selectors may be anywhere in the clusterDaniel Eklöf2021-06-24-8/+10
|
* vt: don’t force cols=2 when we see an emoji variant selectorDaniel Eklöf2021-06-24-1/+3
| | | | | Fish appears to be the only shell expecting this. The rest probably just does wcswidth(), like usual.
* vt: cache grapheme cluster width in composed structDaniel Eklöf2021-06-24-4/+10
| | | | | | * Use regular wcswidth() to calculate the width * Explicitly set to ‘2’ if we see a emoji variant selector * Cache the result in the composed struct
* wip: grapheme shapingDaniel Eklöf2021-06-24-108/+128
|
* Merge branch 'charset-shift-fixes'Craig Barnes2021-06-09-8/+18
|\
| * terminal: add 'charset_designator' enum to make code more self-documentingCraig Barnes2021-06-09-8/+8
| | | | | | | | | | | | This commit also renames the term_set_single_shift_ascii_printer() function to term_single_shift(), since the former is overly verbose and not really even accurate.
| * vt: fix SS2/SS3 escape sequences to act correctly as single shiftsCraig Barnes2021-06-08-4/+2
| | | | | | | | | | | | These sequences are supposed to affect the next printable ASCII character and then reset to the previous character set, but before this commit they were behaving like locking shifts.
| * vt: add support for LS2 and LS3 locking shiftsCraig Barnes2021-06-08-0/+12
| |
* | vt: TAB: don’t print a ‘\t’ to the grid if the *current* cell isn’t emptyDaniel Eklöf2021-06-08-3/+4
| | | | | | | | | | | | | | | | If the cursor is already at the right edge, our logic that checked for non-empty cells failed; it didn’t check the current cell. Fix by initializing ‘emit_tab_char’ to true/false, depending on the contents of the current cell.
* | vt: emit a tab character if all cells between cursor and tab stop are emptyDaniel Eklöf2021-06-08-3/+40
|/ | | | | | | | | | | | | | | | | | | | | | TAB (\t) move the cursor to the next tab stop. That’s it, according to the specification. However, many terminal emulators try to keep tabs in the grid, to be able to e.g. copy them. That is, copying a text chunk containing tabs should result in tabs being pasted, not spaces. In order to do that, we need to print a tab character to the grid. To improve text reflow of tabs, we also print spaces to the subsequent cells, up until (but not including) the next tab stop. However, we can only do this if all the cells between the cursor and the next tab stop are empty, since (obviously), we cannot overwrite pre-existing characters. Finally, while some fonts render tabs as spaces (i.e. an empty glyph), some use a glyph representing “unprintable” characters, or similar. Thus, we need to exclude cells with tab characters when rendering.
* vt: fix buggy chains of ternary expressions in action_esc_dispatch()Craig Barnes2021-06-08-18/+9
| | | | | | | | | | Only the first character in the chain was being compared with `priv` and the rest were just being evaluated as simple expressions. This was causing the G2 and G3 operations to erroneously use the G1 index. Since the characters are a contiguous range, we can just subtract the start of the range to get the appropriate index. The outer switch statement already ensures the values are in range.
* vt: \E#8: print ‘E’ using the default attributesDaniel Eklöf2021-06-07-1/+1
|
* vt: remove action_utf8_print(term, 0) calls from UTF-8 state handlersCraig Barnes2021-05-25-6/+6
| | | | | These calls appear to be left over from a previous refactoring of the code. Calling this function with `wc == 0` is a no-op.
* vt: remove partial support for 8-bit C1 control charsCraig Barnes2021-05-25-20/+6
| | | | | | | | | | | | | | | | | These are part of the "anywhere" state in Paul Flo Williams' VT parser state diagram[1]. That means that they should be accepted *anywhere* in a byte sequence, including in the middle of other sequences or even in the middle of a multi-byte UTF-8 sequence. Adhering to this requirement makes them incompatible with the use of UTF-8 as a universal encoding. Not adhering to the aforementioned requirement by making a special case for UTF-8 sequences may seem tempting, but it's much more at odds with the relevant standards[2] than it appears on the surface. UTF-8 is not an "8-bit code", at least not according to the parlance of ECMA-43, nor does it map the C1 control range in a compatible way. [1]: https://vt100.net/emu/dec_ansi_parser [2]: ECMA-35, ECMA-43, ECMA-48
* Merge branch 'reflow-performance'Daniel Eklöf2021-05-16-1/+1
|\ | | | | | | Part of #504
| * term: rename CELL_MULT_COL_SPACER -> CELL_SPACER, and change its definitionDaniel Eklöf2021-05-14-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of using CELL_SPACER for *all* cells that previously used CELL_MULT_COL_SPACER, include the remaining number of spacers following, and including, itself. This is encoded by adding to the CELL_SPACER value. So, a double width character will now store the character itself in the first cell (just like before), and CELL_SPACER+1 in the second cell. A three-cell character would store the character itself, then CELL_SPACER+2, and finally CELL_SPACER+1. In other words, the last spacer is always CELL_SPACER+1. CELL_SPACER+0 is used when padding at the right margin. I.e. when writing e.g. a double width character in the last column, we insert a CELL_SPACER+0 pad character, and then write the double width character in the first column on the next row.
* | Update `term->vt.state` for each iteration of vt_from_slave() loopCraig Barnes2021-05-15-3/+2
|/ | | | Otherwise it may be stale when read by the anywhere() function.
* vt: make anywhere() function return `term->vt.state` by defaultCraig Barnes2021-05-13-14/+14
| | | | | Instead of passing a `default_return` parameter, which is always just the current state anyway.
* vt: clean up handling of "anywhere" actionsCraig Barnes2021-05-13-201/+44
|
* term/vt: only do reverse-wrapping (‘bw’) on cub1Daniel Eklöf2021-04-08-2/+15
| | | | | | | | | | | | | | Foot currently does reverse-wrapping (‘auto_left_margin’, or ’bw’) on everything that calls ‘term_cursor_left()’. This is wrong; it should only be done for cub1. From man terminfo: auto_left_margin | bw | bw | cub1 wraps from column 0 to last column This patch moves the reverse-wrapping logic from term_cursor_left() to the handling of BS (backspace). Closes #441
* term: runtime switch between a ‘fast’ and a ‘generic’ ASCII print functionDaniel Eklöf2021-03-16-16/+7
| | | | | | | | | | | | | | | | | | | | | | | term_print() is called whenever the client application “prints” something to the grid. It is called for both ASCII and UTF-8 characters, and needs to handle sixels, insert mode and ASCII vs. graphical charsets. Since it’s on the hot path, this becomes unnecessarily slow. This patch adds a “fast” version of term_print(), tailored for the common case: ASCII characters in non-insert mode, without any sixels and non-graphical charsets. A new function, term_update_ascii_printer(), has been added, and must be called whenever: * The currently selected charset *index* changes * The currently selected charset changes (from ASCII to graphical, or vice verse) * Sixels are added to the grid * Sixels are removed from the grid * Insert mode is enabled/disabled
* vt: remove xassert(), that cannot be optimized out, from action_print()Daniel Eklöf2021-02-07-2/+0
| | | | | | | | | | action_print() is in the hot path, and having if-statement here *does* have an impact on performance. Much more so when that if-statement involves a functional call to wcwidth(). Closes #330
* debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes2021-01-16-11/+11
|
* Print stack trace on assert() failure or when calling fatal_error()Craig Barnes2021-01-16-1/+1
| | | | | | Note: this uses the __sanitizer_print_stack_trace() function from the AddressSanitizer runtime, so it only works when AddressSanitizer is in use.
* Merge branch 'decset-1047-and-1048'Daniel Eklöf2021-01-16-5/+1
|\
| * term/vt/csi: break out cursor save/restore to dedicated functionsDaniel Eklöf2021-01-15-5/+1
| |
* | vt: document correct BS behavior, and why we do differentlyDaniel Eklöf2021-01-15-0/+12
|/
* Use wrappers from macros.h instead of bare GCC attributes/pragmasCraig Barnes2021-01-03-7/+2
|
* vt: codespell: ony -> onlyDaniel Eklöf2020-12-16-1/+1
|
* vt: don’t ignore extra private/intermediate charactersDaniel Eklöf2020-12-16-13/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Take ‘\E(#0’ for example - this is *not* the same as ‘\E(0’. Up until now, foot has however treated them as the same escape, because the handler for ‘\E(0’ didn’t verify there weren’t any _other_ private characters present. Fix this by turning the ‘private’ array into a single 4-byte integer. This allows us to match *all* privates with a single comparison. Private characters are added to the LSB first, and MSB last. This means we can check for single privates in pretty much the same way as before: switch (term->vt.private) { case ‘?’: ... break; } Checking for two (or more) is much uglier, but foot only supports a *single* escape with two privates, and no escapes with three or more: switch (term->vt.private) { case 0x243f: /* ‘?$’ */ ... break; } The ‘clear’ action remains simple (and fast), with a single write operation. Collecting privates is potentially _slightly_ more complex than before; we now need mask and compare, instead of simply comparing, when checking how many privates we already have. We _could_ add a counter, which would make collecting privates easier, but this would add an additional write to the ‘clean’ action which is really bad since it’s in the hot path.
* bell: optionally render margins in red when receiving BELDaniel Eklöf2020-10-08-2/+1
| | | | | | | | | | | Add anew config option, ‘bell=none|set-urgency’. When set to ‘set-urgency’, the margins will be painted in red (if the window did not have keyboard focus). This is intended as a cheap replacement for the ‘urgency’ hint, that doesn’t (yet) exist on Wayland. Closes #157
* vt: BS: *only* reset lcf if cursor is beyond right margin: don’t move cursorDaniel Eklöf2020-10-02-1/+4
| | | | | This is needed to make reverse auto-wrap work correctly. Without it, we’ll end up moving the cursor left one cell extra.
* vt: hide pedantic warnings around the VT state machine's switch casesDaniel Eklöf2020-08-23-0/+9
| | | | | | The switch statements use the GCC extension "case X ... Y", and here it doesn't really make any sense to convert it to "case X: case Y:", so hide the warnings instead.
* Fix spelling mistake in vt.cCraig Barnes2020-08-16-1/+1
|
* Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes2020-08-08-1/+2
|
* vt: never call term_print() with a width <= 0Daniel Eklöf2020-07-16-1/+2
|
* vt: ignore 0x7f (DEL) in ground stateDaniel Eklöf2020-07-16-1/+4
| | | | | | | This ensures *all* bytes mapped to action_print() have wcwidth == 1. DEL has wcwidth == -1, and would thus have been ignored by term_print() anwyway.
* vt: utf8: handle multi-column spacer values correctly when combiningDaniel Eklöf2020-07-16-6/+3
|
* term: rename COMB_CHARS_LO,HI -> CELL_COMB_CHARS_LO,HIDaniel Eklöf2020-07-14-6/+6
|
* vt: change HT (horizontal tab) to *not* clear LCFDaniel Eklöf2020-07-14-0/+6
| | | | | | According to the specification, HT **should** clear LCF. However, nearly all emulators do not. In particular, XTerm doesn't. So we follow suite.
* term: rename term_formfeed() -> term_carriage_return()Daniel Eklöf2020-07-14-2/+3
|
* vt: implement C0::FF - processed in the same way as C0::LFDaniel Eklöf2020-07-14-0/+2
|
* vt: process C0::VT the same way we process C0::LFDaniel Eklöf2020-07-14-6/+3
| | | | | | | | Previously, C0::VT was implemented as a simple 'cursor down'. I.e. it would behave as LF **until** it reached the bottom of the screen, where instead of scrolling, it became a no-op. See https://vt100.net/docs/vt102-ug/chapter5.html
* vt: sort C0's in the switch statement, and use escaped character possibleDaniel Eklöf2020-07-14-16/+16
|
* unicode combining: don't log overflow errors unless LOG_ENABLE_DBG == 1Daniel Eklöf2020-06-09-1/+2
|
* vt: utf8-print: check width == 0 first, when deciding whether to do combiningDaniel Eklöf2020-06-09-1/+1
|
* vt: initial version of UTF-8 decoding built-in into the VT parserDaniel Eklöf2020-06-07-33/+133
|
* vt: utf8: use mbtowc() instead of mbrtowc()Daniel Eklöf2020-05-31-8/+2
| | | | | | | | | This is slightly faster, since we don't need to initialize an mbstate_t struct (using mbrtowc() with a NULL-pointer for 'ps' also works). Also, avoid a branch by setting wc=0 and then ignoring the result/error code from mbtowc().
* vt: utf8: don't need one entry action for each UTF8 variantDaniel Eklöf2020-05-31-20/+6
|
* unicode-combine: simplify - remove -Dunicode-precompose optionDaniel Eklöf2020-05-10-2/+0
| | | | | | | | | | Since the pre-composing functionality is now part of fcft, it makes little sense to have a compile time option - there's no size benefit to be had. Furthermore, virtually all terminal emulators do pre-composing (alacritty being an exception), this really isn't that controversial.
* unicode-precompose: use fcft's precompose functionalityDaniel Eklöf2020-05-09-36/+25
| | | | | | | | | | | | | This allows us more options when determining whether to use a pre-composed character or not: We now only use the pre-composed character if it's from the primary font, or if at least one of the base or combining characters are from a fallback font. I.e. use glyphs from the primary font if possible. But, if one or more of the decomposed glyphs are from a fallback font, use the pre-composed character anyway.
* unicode-combining: limit maximum number of allowed composed chainsDaniel Eklöf2020-05-03-5/+12
|
* unicode-combining: detect when we've reached the chain limitDaniel Eklöf2020-05-03-0/+14
| | | | | | | | | | | We currently store up to 5 combining characters in any given base+combining chain. This adds a check for when that limit is about to be exceeded. When this happens, we log the chain + the new combining character. Since things will break anyway, we simply overwrite the last combining character.
* unicode-combining: store seen combining chains "globally" in the term structDaniel Eklöf2020-05-03-16/+43
| | | | | | | | | | | | | | | | | | | | Instead of storing combining data per cell, realize that most combinations are re-occurring and that there's lots of available space left in the unicode range, and store seen base+combining combinations chains in a per-terminal array. When we encounter a combining character, we first try to pre-compose, like before. If that fails, we then search for the current base+combining combo in the list of previously seen combinations. If not found there either, we allocate a new combo and add it to the list. Regardless, the result is an index into this array. We store this index, offsetted by COMB_CHARS_LO=0x40000000ul in the cell. When rendering, we need to check if the cell character is a plain character, or if it's a composed character (identified by checking if the cell character is >= COMB_CHARS_LO). Then we render the grapheme pretty much like before.
* vt: use signed integers to correctly detect when we're doneDaniel Eklöf2020-05-02-2/+2
|
* meson: don't generate pre-compose table when -Dunicode-precompose=falseDaniel Eklöf2020-05-02-0/+2
|
* unicode-combine: remove utf8proc dependencyDaniel Eklöf2020-05-02-17/+40
| | | | | | | | | | | | We only used utf8proc to try to pre-compose a glyph from a base and combining character. We can do this ourselves by using a pre-compiled table of valid pre-compositions. This table isn't _that_ big, and binary searching it is fast. That is, for a very small amount of code, and not too much extra RO data, we can get rid of the utf8proc dependency.
* unicode-combining: don't limit ourselves to the (western) diacritics blocksDaniel Eklöf2020-05-02-13/+19
|
* unicode-combine: only compose if we don't have any other combining charactersDaniel Eklöf2020-05-01-16/+24
| | | | | | | | | If the client sent the sequence SAB, where SA does NOT have a composed representation, but SB does, the old code would compose SB and throw away A. This patch fixes this by only allowing a compose if there aren't any pre-existing combining characters.
* vt: utf8: track combining characters that we failed to composeDaniel Eklöf2020-05-01-15/+37
| | | | | | | | | | | | | | | When we detect a combining character, we first try to compose it with the base character (like before). When this fails, we instead add the combining character to the base cell's combining characters array. The reason for using a composed character when possible is twofold: one, the rendered glyph will look better since it will be a single glyph instead of two separate glyphs (possibly from different fonts(!)). And two, for performance. A composed glyph is a single glyph to render, while a decomposed glyph sequence means the renderer has to render multiple glyphs for a single cell.
* util.h: new header file defining commonly used macrosDaniel Eklöf2020-05-01-3/+1
|
* vt: lazily reset utf8 in action_utf8_*_entryDaniel Eklöf2020-04-27-4/+3
| | | | | | | | action_clear() is in the super hot code path. Avoid resetting utf8 state there, as utf8 input is relatively uncommon. Instead, reset it when we explicitly enter any of the utf8 collecting states, as this is exactly the point where we need it.
* vt: action_utf8_print: idx is cleared in action_clear()Daniel Eklöf2020-04-27-3/+0
|
* vt: utf8-*-entry: idx is cleared in action_clear()Daniel Eklöf2020-04-27-3/+3
|
* term: remove unneeded utf8.left memberDaniel Eklöf2020-04-27-15/+0
|
* utf8: add support for unicode combining charactersDaniel Eklöf2020-04-27-2/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This feature lets foot combine e.g. "a\u0301" to "á". We first check if the current character (that we're about to print) is a combining character, by checking if it's in one of the following ranges: * Combining Diacritical Marks (0300–036F), since version 1.0, with modifications in subsequent versions down to 4.1 * Combining Diacritical Marks Extended (1AB0–1AFF), version 7.0 * Combining Diacritical Marks Supplement (1DC0–1DFF), versions 4.1 to 5.2 * Combining Diacritical Marks for Symbols (20D0–20FF), since version 1.0, with modifications in subsequent versions down to 5.1 * Combining Half Marks (FE20–FE2F), versions 1.0, with modifications in subsequent versions down to 8.0 If it is, we check if the last cell appears to contain a valid symbol, and if so, we attempt to compose (combine) the last cell with the current character, using utf8proc. If the result is a combined character, we replace the content in the previous cell with the new, combined character. Thus, if you select and copy the printed character, you would get e.g. "\u00e1" instead of "a\u0301". This feature can be disabled. By default, it is enabled if the utf8proc library is found, but can be explicitly disabled, or enabled, with 'meson -Dunicode-combining=disabled|enabled'.
* grid: move 'cursor' state from terminal to gridDaniel Eklöf2020-04-16-8/+8
| | | | | This way, the 'normal' and 'alt' grids have their own cursor state, and we don't need to switch between them.
* mbstate: fix compile warning on systems where mbstate_t isn't an integralDaniel Eklöf2020-04-13-1/+1
| | | | | An empty initializer still ensures the entire object is zero-initialized.
* alt-screen: use a custom 'saved' cursor when switching to alt screenDaniel Eklöf2020-03-16-1/+1
| | | | | | | | | | | | | This fixes an issue where we failed to restore the cursor correctly when exiting from the alternate screen, if the client had sent escapes to save the cursor position while inside the alternate screen. This was because we used the *same* storage for saving the cursor position through escapes, as for saving it when entering the alternate screen. Fix by using a custom variable dedicated to normal <--> alt screen switching.
* vt: tag cells that were form-feed:ed, to allow correct text reflowDaniel Eklöf2020-02-10-2/+2
| | | | | | | | | To handle text reflow correctly when a line has a printable character in the last column, but was still line breaked, we need to track the fact that the slave inserted a line break here. Otherwise, when the window width is increased, we'll end up pulling up the next line, when we really should have inserted a line break.
* vt: ensure we never step outside our parameter and sub-parameter arraysDaniel Eklöf2020-02-01-6/+70
| | | | | | | | | | | | | | | | | | | | We only support 16 parameters, and for each parameter, 16 sub-parameters. If we ever hit that limit (or rather, if the client writes 17 (sub) parameters), log this and stop incrementing the parameter index variable. For performance reason, we implement the following behavior: * We never increment the parameter index past the supported number. This ensures all code *accessing* the parameter list can do so without verifying the validity of the index. * The *first* time we see too many parameters, and the first time we see too many sub parameters, log this. Then *never* log again. Even if we see too many parameters in a completely different escape. This is so that we don't have to keep a "have warned" boolean in the terminal struct, but can use a simple function local static variable.
* vt: collect (intermediate): log a warning if user supplied more than two intermediatesDaniel Eklöf2020-02-01-1/+1
|
* vt: collect (intermediate): log _which_ character we collectedDaniel Eklöf2020-02-01-1/+1
|
* vt: bug: state machine: csi entry: handle 0x3a/0x3b correctlyDaniel Eklöf2020-01-25-1/+1
| | | | | | | | | | | 0x3a/0x3b are ':' and ';'. These should not only switch to the 'csi param' state, but also be parsed as a parameter. This fixes an issue where a multi-parameter escape with the first parameter omitted was parsed incorrectly - as if the first parameter wasn't there. I.e. "\e[;123r" was parsed as "\e[123r"
* vt: bug: fix check for error from mbrtowc()Daniel Eklöf2020-01-23-1/+4
| | | | | | | mbrtowc() returns an unsigned. Need to cast to signed before checking if less than zero. This fixes an issue where invalid utf-8 sequences where treated as valid.
* term: factor out character printing to new function term_print()Daniel Eklöf2020-01-20-90/+4
|
* dcs: initial handling of DCS in generalDaniel Eklöf2020-01-12-0/+4
| | | | | | | | | | | | | | | | | | | | | | Add data structure to term->vt. This structure tracks the free-form data that is passed-through, and the handler to call at the end. Intermediates and parameters are collected by the normal VT parser. Then, when we enter the passthrough state, we call dcs_hook(). This function checks the intermediate(s) and parameters, and selects the appropriate unhook handler (and optionally does some execution already). In passthrough mode, we simply append strings to an internal buffer. This might have to be changed in the future, if we need to support a DCS that needs to execute as we go. In unhook (i.e. when the DCS is terminated), we execute the unhook handler. As a proof-of-concept, handlers for BSU/ESU (Begin/End Synchronized Update) has been added (but are left unimplemented).
* Revert "vt: refactor"Daniel Eklöf2019-12-20-208/+201
| | | | This reverts commit a575204bc77c711047740d2328d26043e8c976cb.
* vt: refactorDaniel Eklöf2019-12-20-201/+208
|
* vt: visually compact the switch tablesDaniel Eklöf2019-12-20-271/+271
|
* vt: remove enum action; add separate functions for each action insteadDaniel Eklöf2019-12-20-524/+491
|
* vt: remove debug assertDaniel Eklöf2019-12-20-1/+0
|
* vt: use a pointer that we increment, instead of indexingDaniel Eklöf2019-12-20-21/+21
|
* vt: use break, not continueDaniel Eklöf2019-12-20-17/+17
|
* vt: no need to assign to term->vt.state for *every* input byteDaniel Eklöf2019-12-20-18/+20
|