aboutsummaryrefslogtreecommitdiff
path: root/vt.c (follow)
Commit message (Collapse)AuthorAgeLines
* vt: utf8: insert a REPLACEMENT CHARACTER when an invalid UTF-8 sequence is detectedDaniel Eklöf2025-03-18-6/+6
|
* vt: utf8: don't discard current byte when an invalid UTF-8 sequence is detectedDaniel Eklöf2025-03-18-6/+6
| | | | | | | | | | | | | | | | Example: printf "pok\xe9mon\n" would result in 'pokon' - the 'm' has been discarded along with E9. While correct, in some sense, it's perhaps not intuitive. This patch changes the VT parser to instead discard everything up to the invalid byte, but then try the invalid byte from the ground state. This way, invalid UTF-8 sequences followed by both plain ASCII, or longer (and valid) UTF-8 sequences are printed as expected instead of being discarded.
* term+vt: refactor: move "utf8" char processing to term_process_and_print_non_ascii()Daniel Eklöf2025-02-06-250/+1
| | | | | | | | | | | This function "prints" any non-ascii character (i.e. any character that ends up in the action_utf8_print() function in vt.c) to the grid. This includes grapheme cluster processing etc. action_utf8_print() now simply calls this function. This allows us to re-use the same functionality from other places (like the text-sizing protocol).
* composed: refactor: break out lookup with collision detectionDaniel Eklöf2025-02-06-51/+13
|
* composed: re-factor: break out key calculation from vt.cDaniel Eklöf2025-02-06-22/+2
|
* term: insert-mode: handle combining characters correctlyDaniel Eklöf2025-02-06-1/+3
| | | | | | | | | | | | | | | | | When the client application emits combining characters, for example multi-codepoint emojis, in insert-mode, we ended up pushing partial graphemes to the right, for each codepoint, resulting in too many cells (and with the wrong content) being inserted. The fix is fairly simple; don't "insert" when appending characters to an existing grapheme cluster. This isn't something we can detect easily in print_insert() (it would require us to do grapheme clustering again). Fortunately, we do have the required information in action_utf8_print(). So, pass this information as a boolean to term_print(). Closes #1947
* vt: combining chars: ensure 'key' is within rangeDaniel Eklöf2025-01-18-0/+2
| | | | | | When there's a key collision, we increment the key and check again. When doing this, we need to ensure the key is withing range, and wrap around to 0 if the key value is too large.
* vt: don't call fcft_precompose() if font is NULLDaniel Eklöf2024-11-02-3/+5
| | | | | This fixes a crash when doing a partial PGO build (where we don't have any fonts available).
* Remove a number of unused includesDaniel Eklöf2024-08-02-1/+0
|
* term: performance: use a bitfield to track which ascii printer to useDaniel Eklöf2024-06-26-0/+12
| | | | | | | | | | | The things affecting which ASCII printer we use have grown... Instead of checking everything inside term_update_ascii_printer(), use a bitfield. Anything affecting the printer used, must now set a bit in this bitfield. This makes term_update_ascii_printer() much faster, since all it needs to do is check if the bitfield is zero or not.
* vt: unittest: verify emoji_vs list is sortedDaniel Eklöf2024-06-25-0/+14
|
* vt: only apply VS-15/16 to valid sequencesDaniel Eklöf2024-06-25-5/+39
| | | | | | | | | | At compile time, build a lookup table from the Unicode data file 'emoji-variation-sequences.txt'. At run-time, when we detect a VS-15/16 sequence, do a lookup in this table, and enforce the variation selector iff the sequence is valid. Closes #1742
* vt: don't ignore VS-15 (text presentation)Daniel Eklöf2024-06-25-3/+4
| | | | | When we encounter either VS-15 or VS-16, set the grapheme width to 1 or 2 explicitly.
* vt: DECALN: erase sixels, reset margins, home the cursorDaniel Eklöf2024-03-07-0/+8
| | | | | | | | | https://vt100.net/docs/vt510-rm/DECALN.html: Notes on DECALN DECALN sets the margins to the extremes of the page, and moves the cursor to the home position.
* vt: update DECALN to use term_fill()Daniel Eklöf2024-03-07-9/+3
|
* vt: ignore VS16 (U+FE0F) when grapheme clustering is disabledDaniel Eklöf2024-02-16-1/+7
| | | | | | | | | | This fixes: a) a compilation error with -Dgrapheme-clustering=disabled b) ensures U+FE0F does *not* allocate a two cells when grapheme clustering has been disabled (either compile time, in config, or run-time).
* vt: VS16 - variation selector 16 (emoji representation) should only affect emojisDaniel Eklöf2024-02-15-2/+8
|
* Don't use fancy Unicode quotes, stick to ASCIIDaniel Eklöf2024-02-06-10/+10
|
* csi: implement DECSET/DECRST/DECRQM 2027 - grapheme cluster processingDaniel Eklöf2023-09-25-1/+1
| | | | | | | | | | | This implements private mode 2027 - grapheme cluster processing, as defined in the "Terminal Unicode Core"[1] specification. Internally, we just flip the already existing option "grapheme shaping". Since it's now runtime changeable, we need a copy of it in the terminal struct, rather than referencing the conf object. [1]: https://github.com/contour-terminal/terminal-unicode-core/blob/13fc5a8993a033ff10c1f3433d08cb618cde4ac2/spec/terminal-unicode-core.tex#L50-L53
* vt: fix ASAN UB warningDaniel Eklöf2023-08-05-1/+1
| | | | | | | ../vt.c:648:13: runtime error: signed integer overflow: 3924432811 * 2654435761 cannot be represented in type 'long' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../vt.c:648:13 in Closes #1456
* vt: detect and ignore invalid UTF-8 sequencesDaniel Eklöf2023-07-22-0/+21
| | | | | | | | | | | This patch detects invalid codepoints in the UTF-8 EDxxxx range, and the F4xxxxxx range. Note that we still allow the E0xxxx and F0xxxxxx ranges. These contains overlong encodings. We allow them, because they still decode into correct UTF-32. Closes #1423
* vt: improve handling of HTSCismonX2023-07-20-8/+22
| | | | | | | | | Do not insert existing positions into the tab stop list. This prevents a performance issue when iterating through an extremely long tab stop list. Also corrects the behaviour of CBT.
* vt: split up action_param() to three separate functionsDaniel Eklöf2023-06-16-66/+69
| | | | | | | | | | | | | | | | | | | | | | | | We’re already switching on the next VT input byte in the state machine; no need to if...else if in action_param() too. That is, split up action_param() into three: * action_param_new() * action_param_new_subparam() * action_param() This makes the code cleaner, and hopefully slightly faster. Next, to improve performance further, only check for (sub)parameter overflow in action_param_new() and action_param_subparam(). Add pointers to the VT struct that points to the currently active parameter and sub-parameter. When the number of parameters (or sub-parameters) overflow, warn, and then point the parameter pointer to a "dummy" value in the VT struct. This way, we don’t have to check anything in action_param().
* vt: tag collision-count check with ‘unlikely’Daniel Eklöf2022-06-15-1/+1
|
* vt: improve key calculation for compose sequencesDaniel Eklöf2022-06-15-4/+19
| | | | | | | | | | * Don’t assume 32 bits when rotating the old key. Use the number of actual bits available, as determined by CELL_COMB_CHARS_{HI,LO} * Multiply with magic hash constant This greatly reduces the number of collisions seen. For example, the Emoji test file (from the Unicode specification), now has zero collisions.
* vt: prevent potential endless loop when finding a slot for a composed characterDaniel Eklöf2022-06-15-0/+14
| | | | | | | | | | | | | | | | | | | | | Composed characters are stored in a tree structure, using a key as identifier. The key is calculated from the individual characters that make up the composed character sequence. Since the address space for keys is limited, collisions may occur. In this case, we simply increment the key and try again. It is theoretically possible to saturate the key space, in which case we’ll get stuck in an endless loop. Even if the key space isn’t fully saturated, we fairly easy reach a point where there are so many collisions for each insertion, that performance drops significantly. Since key space is limited (it’s not like a hash table that we can grow), our only option is to limit the number of collisions. If we can’t find a slot within a hard code amount of collisions, the character is simply dropped.
* vt: free OSC buffer after dispatch, if larger than 4KDaniel Eklöf2022-03-21-3/+12
|
* fcft: adapt to API changes in fcft-3.xDaniel Eklöf2022-02-05-13/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fcft no longer uses wchar_t, but plain uint32_t to represent codepoints. Since we do a fair amount of string operations in foot, it still makes sense to use something that actually _is_ a string (or character), rather than an array of uint32_t. For this reason, we switch out all wchar_t usage in foot to char32_t. We also verify, at compile-time, that char32_t used UTF-32 (which is what fcft expects). Unfortunately, there are no string functions for char32_t. To avoid having to re-implement all wcs*() functions, we add a small wrapper layer of c32*() functions. These wrapper functions take char32_t arguments, but then simply call the corresponding wcs*() function. For this to work, wcs*() must _also_ be UTF-32 compatible. We can check for the presence of the __STDC_ISO_10646__ macro. If set, wchar_t is at least 4 bytes and its internal representation is UTF-32. FreeBSD does *not* define this macro, because its internal wchar_t representation depends on the current locale. It _does_ use UTF-32 _if_ the current locale is UTF-8. Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is defined. Other fcft API changes: * fcft_glyph_rasterize() -> fcft_codepoint_rasterize() * font.space_advance has been removed * ‘tags’ have been removed from fcft_grapheme_rasterize() * ‘fcft_log_init()’ removed * ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
* config: add tweak.grapheme-width-method=maxDaniel Eklöf2021-11-23-0/+4
| | | | | | ‘max’ is a new value for ‘tweak.grapheme-width-method’. When enabled, the width of a grapheme cluster is that of the cluster’s widest codepoint.
* osc: use BEL terminator in OSC replies to BEL-terminated OSC queriesCraig Barnes2021-10-20-0/+1
| | | | | | | | | This matches the documented (and observed) behavior in xterm: > XTerm accepts either BEL or ST for terminating OSC sequences, and > when returning information, uses the same terminator used in a query -- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
* 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
|