aboutsummaryrefslogtreecommitdiff
path: root/vt.c (follow)
Commit message (Collapse)AuthorAgeLines
* 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
|
* vt: remove dead codeDaniel Eklöf2019-12-20-495/+0
|
* vt: don't special case UTF-8 collect stateDaniel Eklöf2019-12-20-24/+55
|
* vt: convert SOS/PM/APC string from table lookup to switchDaniel Eklöf2019-12-20-2/+30
|
* vt: convert DCS from table lookup to switchDaniel Eklöf2019-12-20-7/+195
|
* vt: convert CSI ignore from table lookup to switchDaniel Eklöf2019-12-20-2/+34
|
* vt: convert CSI intermediate from table lookup to switchDaniel Eklöf2019-12-20-2/+35
|
* vt: convert CSI param from table lookup to switchDaniel Eklöf2019-12-20-2/+39
|
* vt: add missing 'entry' actions to 'anywhere' sectionsDaniel Eklöf2019-12-20-2/+2
|
* vt: convert CSI entry from table lookup to switchDaniel Eklöf2019-12-20-4/+39
|
* vt: re-align switchesDaniel Eklöf2019-12-20-67/+68
|
* vt: replace GROUND, ESCAPE and ESCAPE_INTERMEDIATE tables with switchesDaniel Eklöf2019-12-20-5/+115
|
* vt: use a switch instead of a top-level state lookup tableDaniel Eklöf2019-12-20-1/+26
| | | | | Remove the top-level state lookup table, which mapped from a state enum to a state transition table, and replace it with a switch.
* vt: add commented out cases for 8-bit C1 control charactersDaniel Eklöf2019-12-14-0/+35
| | | | | | | | | | XTerm seems to ignore these when in UTF-8 mode. Since we _only_ support UTF-8, we don't need to recognize these control characters at all. However, it may be good to have them here for reference. So add them, but commented out, along with their corresponding 7-bit versions (which we _do_ recognize and implement).
* vt: don't try to move cursor outside the terminalDaniel Eklöf2019-11-29-7/+11
| | | | | | | | | When we insert an auto-newline, we must make sure we don't try to move outside the terminal window. This can for example happen when a scrolling region have been configured, and the cursor is **outside** the scrolling region (i.e. it's in the bottom margin).
* vt: fix memory corruption: wcwidth() may return -1Daniel Eklöf2019-11-29-12/+14
| | | | | When it did, we called print_insert() with that, which in turn resulted in a too large size value passed to memmove.
* csi/vt: don't bad client data as errorsDaniel Eklöf2019-11-29-1/+1
| | | | This gets rid of spam when cat:ing binary data.
* vt: only define esc_as_string() when debug logging has been enabledDaniel Eklöf2019-11-29-0/+2
|
* vt: disable logging BELLDaniel Eklöf2019-11-29-2/+2
|
* csi/ocs/vt: log unhandled/unrecognized sequences as debug messagesDaniel Eklöf2019-11-29-1/+1
| | | | | | | | Having them as error messages was nice when we where still missing lots of sequences. Now we don't anymore, and these just spam stdout as well as syslog when e.g. cat:ing binary data.
* vt: there are actually many state transitions that are no-opsDaniel Eklöf2019-11-29-1/+0
| | | | | | In most states, most 8-bit values are no-ops. This is already handled; action() recognizes ACTION_NONE as a no-op. Thus, all we need to do is remove the assertion.
* Revert "vt: replace pre_print() with term_autowrap()"Daniel Eklöf2019-11-17-2/+14
| | | | This reverts commit fd8a3992745b9ec51b6e6c1dfc39faf01369b680.
* vt: replace pre_print() with term_autowrap()Daniel Eklöf2019-11-17-14/+2
|
* csi: fix bad implementation of CBT (back tab)Daniel Eklöf2019-11-17-0/+1
| | | | | | | * It takes a parameter, that indicates the number of tab stops to move through * Use the tab stops defined in the tab stops list, not hard coded mod 8 columns.
* vt: bug (tab regression): don't get stuck on the same tab stopDaniel Eklöf2019-11-17-2/+2
| | | | | | | | | | | There were actually two bugs here: * When checking for a tab stop, make sure the new tab stop is at a different column. Otherwise you can't tab away from a tab stop. * When there aren't any tab stops configured, or when we're already beyond the last tab stop, then tab to the last column (at least I think that's what we're supposed to do).
* term: save/restore charsets on save/restore cursor+attributesDaniel Eklöf2019-11-17-6/+2
|
* term: move charset variables into an anonymous structDaniel Eklöf2019-11-17-7/+13
|
* term: move lcf flag into 'cursor' structDaniel Eklöf2019-11-17-2/+2
|
* term: add struct cursorDaniel Eklöf2019-11-17-21/+21
|
* term: rename: print_needs_wrap -> lcf (Last Column Flag)Daniel Eklöf2019-11-17-2/+2
|
* vt: execute: \t: use tab stops from tab stop listDaniel Eklöf2019-11-16-3/+8
| | | | | Instead of assuming hardcoded 8-width tab stops, use the tab stops from the tab stop list.
* vt: implement ESC H - set tab stop at current columnDaniel Eklöf2019-11-16-0/+11
|
* vt: remove commented out codeDaniel Eklöf2019-11-16-37/+0
|
* vt: DECALN: render at bottom of terminal, not in viewDaniel Eklöf2019-11-14-1/+1
|
* vt: implement VT - Vertical TabDaniel Eklöf2019-11-05-0/+5
| | | | Despite its name, it always moves down exactly one line.
* vt: always use hex (not octal)Daniel Eklöf2019-11-05-2/+2
|
* vt: log hex version of printed character tooDaniel Eklöf2019-11-05-1/+1
|
* vt: always disable state_names[] arrayDaniel Eklöf2019-11-05-1/+1
| | | | It isn't used anywhere, even with LOG_ENABLE_DBG
* vt: esc dispatch: implement DECALNDaniel Eklöf2019-11-05-65/+118
| | | | | | | In esc dispatch: * Switch on private first, then final * Recognize ESC #8 (DECALN), and implement it
* scan-build: fix a couple of minor warnings from a scan-build runDaniel Eklöf2019-11-05-1/+1
|
* Rename: vt_to_slave() -> term_to_slave()Daniel Eklöf2019-11-02-20/+0
|
* vt: don't log ignored execute commandsDaniel Eklöf2019-09-28-1/+0
| | | | cat:ing a binary file would otherwise result in us spamming syslog.
* vt: implement 'insert mode'Daniel Eklöf2019-08-30-18/+27
|
* vt: remove unneeded includeDaniel Eklöf2019-08-30-1/+0
|
* vt: tidy lazy initialization of escape parametersDaniel Eklöf2019-08-27-6/+6
|
* vt: no need to reset OSC string in CLEAR actionDaniel Eklöf2019-08-27-1/+0
| | | | ... as this is done when a new OSC string is started
* vt: store alt charset characters as wcharsDaniel Eklöf2019-08-27-9/+6
|
* vt: bug: fix lazy initialization of sub parameter value (off-by-one)Daniel Eklöf2019-08-24-2/+1
|
* vt: clear CSI parameters lazilyDaniel Eklöf2019-08-24-3/+11
| | | | | | | | | The CLEAR action is so common, that explicitly clearing the entire params array, which is kind of big, is too slow. Clear it lazily instead. Meaning, we only set 'idx' (count) to 0 in CLEAR. Then whenever we parse a parameter, clear the value and sub parameters.
* vt: remove support for urxvt 'extended' line drawing character setDaniel Eklöf2019-08-16-12/+7
|
* vt: there is no default charset for \e0 and \eBDaniel Eklöf2019-08-16-2/+4
|