aboutsummaryrefslogtreecommitdiff
path: root/grid.h (follow)
Commit message (Collapse)AuthorAgeLines
* grid: refactor reflowDaniel Eklöf2025-02-10-1/+1
| | | | | | | | | | | | We've been trying to performance optimize reflow by "chunking" cells; try to gather as many as possible, and memcpy a chunk at once. The problem is that a) this quickly becomes very complex, and b) is very hard to get right for multi-column characters, especially when we need to truncate long ones due to the window being too small. Refactor, and once again walk and copy all cells one by one. This is slower, but at least it's correct.
* Rename various uses of "curly" in the source code with "underline"Craig Barnes2024-07-01-7/+7
| | | | | Since "curly" could make it seem as if all underline styles are curled (to people unfamiliar with the codebase), whereas in reality only 1 is.
* csi: wip: styled underlinesDaniel Eklöf2024-06-26-2/+13
| | | | | | | | | | | | | This is work in progress, and fairly untested. This adds initial tracking of styled underlines. Setting attributes seems to work (both color and underline style). Grid reflow has *not* been tested. When rendering, style is currently ignored (all styles are rendered as a plain, legacy underline). Color however, *is* applied.
* grid: refactor: first step towards a more generic range handlingDaniel Eklöf2024-06-26-2/+18
|
* grid: remove prototype for non-existing functionDaniel Eklöf2024-03-07-1/+0
|
* osc: add support for OSC 133;A (prompt markers)Daniel Eklöf2022-06-16-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds support for the OSC-133;A sequence, introduced by FinalTerm and implemented by iTerm2, Kitty and more. See https://iterm2.com/documentation-one-page.html#documentation-escape-codes.html. The shell emits the OSC just before printing the prompt. This lets the terminal know where, in the scrollback, there are prompts. We implement this using a simple boolean in the row struct ("this row has a prompt"). The prompt marker must be reflowed along with the text on window resizes. In an ideal world, erasing, or overwriting the cell where the OSC was emitted, would remove the prompt mark. Since we don't store this information in the cell struct, we can't do that. The best we can do is reset it in erase_line(). This works well enough in the "normal" screen, when used with a "normal" shell. It doesn't really work in fullscreen apps, on the alt screen. But that doesn't matter since we don't support jumping between prompts on the alt screen anyway. To be able to jump between prompts, two new key bindings have been added: prompt-prev and prompt-next, bound to ctrl+shift+z and ctrl+shift+x respectively. prompt-prev will jump to the previous, not currently visible, prompt, by moving the viewport, ensuring the prompt is at the top of the screen. prompt-next jumps to the next prompt, visible or not. Again, by moving the viewport to ensure the prompt is at the top of the screen. If we're at the bottom of the scrollback, the viewport is instead moved as far down as possible. Closes #30
* grid: add abs-to-sb and sb-to-abs utility functionDaniel Eklöf2022-04-25-0/+5
| | | | | | | | | | | | | | | | | These functions convert row numbers between absolute coordinates and “scrollback relative” coordinates. Absolute row numbers can be used to index into the grid->rows[] array. Scrollback relative numbers are ordered with the *oldest* row first, and the *newest* row last. That is, in these coordinates, row 0 is the *first* (oldest) row in the scrollback history, and row N is the *last* (newest) row. Scrollback relative numbers are used when we need to sort things after their age, when determining if something has scrolled out, or when limiting an operation to ensure we don’t go past the scrollback wrap-around.
* osc8: uri ranges: use a dynamically re-sizable array instead of a tllistDaniel Eklöf2021-11-26-6/+7
|
* osc8: update URI ranges as we print data, *not* when the URI is closedDaniel Eklöf2021-11-25-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | At first, an OSC-8 URI range was added when we received the closing OSC-8 escape (i.e. with an empty URI). But, this meant that cursor movements while the OSC-8 escape was in effect wasn’t handled correctly, since we’d add a range that spanned the cursor movements. Attempts were made to handle this in the cursor movement functions, by closing and re-opening the URI. However, there are too many corner cases to make this a viable approach. Scrolling is one such example, line-wrapping another. This patch takes a different approach; emit, or update the URI range when we print to the grid. This models the intended behavior much more closely, where an active OSC-8 URI act like any other SGR attribute - it is applied to all cells printed to, but otherwise have no effect. To avoid killing performance, this is only done in the “generic” printer. This means OSC-8 open/close calls must now “switch” the ASCII printer. Note that the “fast” printer still needs to *erase* pre-existing OSC-8 URIs. Closes #816
* grid: add grid_row_uri_range_erase()Daniel Eklöf2021-11-21-1/+2
| | | | | | | | | This function handles erasing of an URI range. That is, a range of the row is being either erased, or overwritten (from the URI perspective, these two are the same thing). We handle both partial overwrites (split up, or truncate URI), as well as complete overwrites (remove URI).
* composed: store compose chains in a binary search treeDaniel Eklöf2021-06-24-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* grid: add grid_row_uri_range_destroy()Daniel Eklöf2021-05-23-1/+7
|
* grid: add grid_snapshot()Daniel Eklöf2021-02-26-0/+1
| | | | This function deep copies a grid into a newly *allocated* grid struct.
* grid: add grid_free()Daniel Eklöf2021-02-26-0/+2
|
* grid: add new function grid_row_add_uri_range()Daniel Eklöf2021-02-21-0/+2
|
* grid: add new function, grid_row_reset_extra()Daniel Eklöf2021-02-21-0/+15
| | | | This function resets (free:s) all ‘extra’ data associated with a row.
* debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes2021-01-16-4/+5
|
* resize: don’t reflow text on alt screenDaniel Eklöf2020-11-25-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Alt screen applications normally reflow/readjust themselves on a window resize. When we do it too, the result is graphical glitches/flashes since our re-flowed text is rendered in one frame, and the application re-flowed text soon thereafter. We can’t avoid rendering some kind of re-flowed frame, since we don’t know when, or even if, the application will update itself. To avoid glitches, we need to render, as closely as possible, what the application itself will render shortly. This is actually pretty simple; we just need to copy the visible content over from the old grid to the new grid. We don’t bother with text re-flow, but simply truncate long lines. To simplify things, we simply cancel any active selection (since often times, it will be corrupted anyway when the application redraws itself). Since we’re not reflowing text, there’s no need to translate e.g. the cursor position - we just keep the current position (but bounded to the new dimensions). Fun thing: ‘less’ gets corrupted if we don’t leave the cursor at the (new) bottom row. To handle this, we check if the cursor (before resize) is at the bottom row, and if so, we move it to the new bottom row. Closes #221
* grid: reflow: calculate width of composed characters correctlyDaniel Eklöf2020-09-06-1/+3
| | | | | Before this patch, reflow called `wcwidth()` on our magic values for composed characters.
* grid: swap_row: remove unused parameter 'initialize'Daniel Eklöf2020-05-16-1/+1
|
* grid: reflow: make tracking_points array 'const'Daniel Eklöf2020-04-17-1/+1
| | | | | The elements aren't, and cannot be, const. But the array itself can, and should be.
* grid: reflow: caller may now pass a list of coordinates that should be translatedDaniel Eklöf2020-04-17-1/+3
|
* grid: grid_reflow() now translates cursor coordinatesDaniel Eklöf2020-04-16-1/+1
|
* render/grid: move grid reflow code to grid.cDaniel Eklöf2020-02-15-0/+3
|
* search: wip: initial search matchingDaniel Eklöf2019-08-27-2/+14
| | | | | | | | * match search buffer against scrollback content * adjust view to ensure matched content is visible * create selection on a successful match * finalize selection when user presses enter (to "commit" the search) * ctrl+r searches for the next match. Needs more work though.
* scrolling: optimize row access by assuming number of rows is a power of 2Daniel Eklöf2019-08-22-8/+20
| | | | | | | | | | | | | | | | | | | With this assumption, we can replace 'a % b' with 'a & (b - 1)'. In terms of instructions, this means a fast 'and' instead of a slow 'div'. Further optimize scrolling by: * not double-initializing empty rows. Previously, grid_row_alloc() called calloc(), which was then followed by a memset() when scrolling. This is of course unnecessary. * Don't loop the entire set of visible rows (this was done to ensure all visible rows had been allocated, and to prefetch the cell contents). This isn't necessary; only newly pulled in rows can be NULL. For now, don't prefetch at all.
* grid: prefetch cells in grid_row()Daniel Eklöf2019-07-10-0/+1
|
* grid: repair grid_row_in_view(): use 'view', not 'offset'Daniel Eklöf2019-07-10-1/+1
|
* grid: don't pre-allocate the entire grid (with all scrollback lines)Daniel Eklöf2019-07-10-6/+22
| | | | | | | | | | The row array may now contain NULL pointers. This means the corresponding row hasn't yet been allocated and initialized. On a resize, we explicitly allocate the visible rows. Uninitialized rows are then allocated the first time they are referenced.
* grid: don't implement grid_swap_row() in the header fileDaniel Eklöf2019-07-10-24/+1
|
* wip: initial scroll back supportDaniel Eklöf2019-07-09-0/+7
| | | | | | | | | | | | | | | | | | | | | | | Can scroll up and down, and stops when the beginning/end of history is reached. However, it probably breaks when the entire scrollback buffer has been filled - we need to detect when the view has wrapped around to the current terminal offset. The detection of when we've reached the bottom of the history is also flawed, and only works when we overshoot the bottom with at least a page. Resizing the windows while in a view most likely doesn't work. The view will not detect a wrapped around scrollback buffer. I.e. if the user has scrolled back, and is stationary at a view, but there is still output being produced. Then eventually the scrollback buffer will wrap around. In this case, the correct thing to do is make the view start following the beginning of the history. Right now it doesn't, meaning once the scrollback buffer wraps around, you'll start seeing command output...
* wip: grid is now represented as a grid, not a linear arrayDaniel Eklöf2019-07-08-0/+28
| | | | | | | | | | | | The grid is now represented with an array of row *pointers*. Each row contains an array of cells (the row's columns). The main point of having row pointers is we can now move rows around almost for free. This is useful when scrolling with scroll margins for example, where we previously had to copy the lines in the margins. Now it's just a matter of swapping two pointers.
* grid: grid_memset() -> grid_memclear()Daniel Eklöf2019-07-07-1/+1
|
* scrolling: initial reverse scrolling support - no scroll regionsDaniel Eklöf2019-07-03-3/+3
|
* grid: implement a memmove-sort-of functionDaniel Eklöf2019-07-01-0/+1
| | | | | grid_memmove() moves cell data from one index to another, taking the grid offset into account.
* wip: use a sliding window instead of memmove() to scrollDaniel Eklöf2019-07-01-0/+4
| | | | | Instead of memmoving a large amount of data on every scroll, use a sliding window. That is, each time we scroll, we offset origin.
* Rename grid_* functions to term_*Daniel Eklöf2019-06-29-29/+0
|
* scroll-region: don't clear damage queue when changing scroll regionDaniel Eklöf2019-06-25-3/+7
| | | | | | | | | | | | | | | | | | | | | | Vim, for example, changes the scroll region every time you scroll a single line. Thus, resetting the damage queue is slow. This reworks the damage handling of scroll updates: * Split damage queue into two: one for scroll operations and one for update/erase operations. * Don't separate update/erase operations inside/outside the scroll region * Store the current scroll region in the scroll damage operation. This allows us to stack multiple scroll operations with different scroll regions. * When updating update/erase operations after a scroll operation, split the update/erase operations if necessary (the current scroll operation may have a scroll region different from before, thus forcing us to split existing update/erase operations. * The renderer no longer erases after a scroll. The scroll operation also adds an erase operation. This also means that erase operation are subject to adjustments by later scroll operations.
* scrolling region: wipDaniel Eklöf2019-06-23-1/+4
|
* vt: wip: implement scrolling regionDaniel Eklöf2019-06-23-2/+1
| | | | | | | | | | This is largely untested, but existing scrolling code has been converted to using a terminal-global scrolling region that is defined as start-end of the scrollable region. This is compared to the old code where the scrolling region where defined in terms of marginals, counted in lines from top and from bottom.
* vt: implement reverse scrolling (terminfo 'ri')Daniel Eklöf2019-06-23-1/+3
| | | | | This currently duplicates the code paths for DAMAGE_SCROLL; there are many similarities between the two, but also major differences...
* grid: implement DAMAGE_SCROLLDaniel Eklöf2019-06-21-0/+2
|
* Use a 'damage' list to communicate what needs to be updatedDaniel Eklöf2019-06-19-0/+3
| | | | | | | | | | Instead of having each cell in the grid track it's own dirtiness, grid operations now append "damage" to a list. This list is consumed every time we render the grid. This allows us to special case some operations, like erase (and in the future, scroll).
* wip: initial scrolling support (no scrollback though)Daniel Eklöf2019-06-19-0/+3
|
* wip: initial input handlingDaniel Eklöf2019-06-19-0/+2
|
* grid: track both linear and row,col cursorDaniel Eklöf2019-06-17-2/+8
|
* wip: vt parsing: break out grid operating functionsDaniel Eklöf2019-06-17-0/+8