aboutsummaryrefslogtreecommitdiff
path: root/grid.c (unfollow)
Commit message (Collapse)AuthorLines
2026-09-18grid: reflow: fix two issues when truncating wide charactersDaniel Eklöf-12/+26
When resizing to a very small grid, it may be impossible to fit a wide character (for example, a 6-cell character won't ever fit in a 5-cell grid). What we do is replace with wide character with a space. There were however two issues: 1. We never set the attributes of the space cell, only the wc member 2. We breaked out of the loop, causing any tracking points associated with any of the SPACER cells to never be matched. The last point is very real, since e.g. OSC-8 links cover the spacer cells. The first point is easy to fix; we first copy the entire cell from the old grid, then replace wc with 0. The second point is somewhat more complex. We remove the break, to ensure we run all the tracking point logic. Then, we only write the empty cell in the first iteration. Subsequent iterations do nothing (to the new grid). Then, to ensure tracking points associated with the spacer cells point to a valid cell, we keep the new_col_idx value at the first (now empty) cell. Only when we've processed the last SPACER cell do we increment new_col_idx once. This ensures consistency (the wide character was replaced with a single-cell character, thus new_col_idx should only be incremented by one).
2026-09-10grid: reflow: Preserve cells with background colorCelina Sophie Kalus-1/+1
A cell was previously considered empty if its content is empty. When an empty cell has a non-default background color, truncating such cells from the end of the line when reflowing is unexpected. Instead, treat such cells as non-empty to preserve them. Closes #2462 Signed-off-by: Celina Sophie Kalus <hello@celinakalus.de>
2025-03-29grid: reflow: fix empty line coalescingDaniel Eklöf-4/+2
If a range of empty lines ended with a non-empty line at the very bottom of the to-be-resized grid, all those empty lines were removed. Closes #2011
2025-03-05grid: set linebreak=false when printing to a line, not when allocating itDaniel Eklöf-9/+11
This ensures empty lines are treated correctly, and is also more in line with how lines are handled at runtime, when filling the scrollback. For now, set linebreak=false as soon as something is printed on a line. It will remain like that *until* we reach the end of an old row with linebreak=true, at which point we set linebreak=true on the current new line.
2025-03-05grid: change default value of linebreak to trueDaniel Eklöf-26/+59
This way, all lines are treated as having a hard linebreak, until it's cleared when we do an auto-wrap. This change alone causes issues when reflowing text, as now all trailing lines in an otherwise empty window are treated as hard linebreaks, causing the new grid to insert lots of unwanted, empty lines. Fix by doing two things: * *clear* the linebreak flag when we pull in new lines for the new grid. We only want to set it explicitly, when an old row has its linebreak flag set. * Coalesce empty lines with linebreak=true, and only "emit" them as new liens in the new grid if they are followed by non-empty lines.
2025-02-13grid: reflow: fix cursor reflow when LCF is setDaniel Eklöf-3/+14
When the cursor is at the end of the line, with a pending wrap (LCF set), the lcf flag should be cleared *and* the cursor moved one cell to the right. Before this patch, we cleared LCF, but didn't move the cursor. Closes #1954
2025-02-10grid: reflow: shell integration: no need to check for >= 0Daniel Eklöf-8/+2
2025-02-10grid: reflow: don't special case the first cell in a multi-column characterDaniel Eklöf-54/+56
Wrap *all* cell copying logic in a for-loop for the characters width. This _should_, in theory, mean reflow of e.g. cursor coordinates in the middle of a multi-column character works correctly. Also fix reflow of cmd start/end integration.
2025-02-10grid: performance: check for non-NULL before comparing with terminatorDaniel Eklöf-2/+2
This should be slightly faster in the normal(?) case (no styled underlines or OSC-8).
2025-02-10grid: refactor reflowDaniel Eklöf-147/+84
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.
2025-02-10grid: pull in misc.h when TIME_REFLOW is definedDaniel Eklöf-0/+4
2025-02-06grid: reflow: get number of spacers to insert from the old gridDaniel Eklöf-1/+1
When checking if we're breaking in the middle of a multi-column character, we counted spacers starting from the break point. But, the character may be wider than that. Use the fact that the spacers cells encode how many *more* there are after them; when we get to the first one, we know exactly how wide the character is.
2025-02-06grid: reflow: handle composed characters longer than 2 cellsDaniel Eklöf-5/+3
The logic that tries to ensure we don't break a line in the middle of a multi-cell character was flawed when the number of cells were larger than 2. In particular, if the number of cells to copy were limited by the number of cells left on the current (new) line, and were less than the length of the multi-cell character, then we failed to insert the correct number of spacers, and also ended up misplacing the multi-cell character; instead of pushing it to the next line, it was inserted on the current line, even though it doesn't fit. Also change how trailing SPACER cells are rendered (cells that are "fillers" at then end of a line, when a multi-column character was pushed over to the next line): don't copy the previous cell's attributes (which may be wrong anyway), use default attributes instead.
2025-02-05grid: typoDaniel Eklöf-1/+2
2025-01-25grid: reflow: regression: remove (truncate) SPACER cells at the end of lineDaniel Eklöf-1/+2
When printing a double-width glyph at the end of the line, it will get pushed to the next line if there's only one cell left on the current line. That last cell on the current line is filled with a SPACER value. When reflowing the text, the SPACER cell should be "removed", so that the double-width glyph continues directly after the text on the previous line. 9567694bab7149afbb4e4fcc4c754272a8d25aba fixed an issue where reflowing e.g. neofetch output incorrectly removed spaces between the logo, and the system info. But also introduced a regression where SPACER values no longer are removed. This patch tries to fix it, by adding back empty cells, but NOT SPACER cells.
2024-07-01Rename various uses of "curly" in the source code with "underline"Craig Barnes-72/+72
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.
2024-06-27grid: merge reflow_{uri,curly}_range_start(), and reflow_{uri,curly}_range_end()Daniel Eklöf-41/+47
2024-06-26grid: refactor: replace {uri,curly}_range_append() with range_append()Daniel Eklöf-49/+70
Also add range_append_by_ref(), with replaces uri_range_append_no_strdup().
2024-06-26grid: row_range_put(): use correct type in call to range_delete()Daniel Eklöf-1/+1
2024-06-26grid: refactor: remove union range_data_for_insertionDaniel Eklöf-49/+25
This union is identical to row_range_data, except the URI char pointer is const. Let's ignore that, and re-use row_range_data, casting the URI pointer when necessary. Also remove uri_range_insert() and curly_range_insert(), and use the generic version of range_insert() everywhere.
2024-06-26grid: grid_row_{uri,curly}_range_put(): share codeDaniel Eklöf-130/+114
grid_row_uri_range_put() and grid_row_curly_range_put() now share the same base logic. Range specific data is passed through a union, and range specific checks are done through switched functions.
2024-06-26grid: reflow: handle styled underlinesDaniel Eklöf-38/+128
2024-06-26csi: wip: styled underlinesDaniel Eklöf-54/+223
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.
2024-06-26grid: refactor: first step towards a more generic range handlingDaniel Eklöf-68/+95
2024-03-17xmalloc: add xmemdup() and use to replace some uses of xmalloc+memcpyCraig Barnes-4/+2
2024-02-06Don't use fancy Unicode quotes, stick to ASCIIDaniel Eklöf-16/+16
2024-02-06grid: resize with reflow: reflow FTCS_COMMAND_{EXECUTED,FINISHED}Daniel Eklöf-27/+29
2024-02-06grid: resize without reflow: truncate shell_integration.cmd_{start,end}Daniel Eklöf-1/+3
This ensures the cmd start/end columns are valid in the new grid.
2024-02-06osc: store column of FTCS_COMMAND_{EXECUTED,FINISHED} in row structDaniel Eklöf-0/+4
2024-02-06term: move row->prompt_marker into new struct, row->shell_integrationDaniel Eklöf-5/+5
2023-10-03Codespell fixesDaniel Eklöf-2/+2
2023-06-30sixel: re-scale images when the cell dimensions changeDaniel Eklöf-14/+55
Before this patch, when the cell dimensions changed (i.e. when the font size changes), sixel images were either removed (the new cell dimensions are smaller than the old), or simply kept at their original size (new cell dimensions are larger). With this patch, sixels are instead resized. This means a sixel *always* occupies the same number of rows and columns, regardless of how much the font size is changed. This is done by maintaining two sets of image data and pixman images, as well as their dimensions. These two sets are the new ‘original’ and ‘scaled’ members of the sixel struct. The "top-level" pixman image pointer, and the ‘width’ and ‘height’ members either point to the "original", or the "scaled" version. They are invalidated as soon as the cell dimensions change. They, and the ‘scaled’ image is updated on-demand (when we need to render a sixel). Note that the ‘scaled’ image is always NULL when the current cell dimensions matches the ones used when emitting the sixel (to save run-time memory). Closes #1383
2023-03-28fix typosHarri Nieminen-1/+1
2022-10-18grid_free(): allow being called with grid == NULLDaniel Eklöf-0/+3
2022-10-10grid: resize: assert grid->cur_row is not NULL after a grid resizeDaniel Eklöf-0/+4
2022-10-10render: delay reflow for ‘resize-delay-ms’ millisecondsDaniel Eklöf-0/+2
Reflowing a large scrollback is *slow*. During an interactive resize, it can easily take long enough that the compositor fills the Wayland socket with configure events. Eventually, the socket becomes full and the compositor terminates the connection, causing foot to exit. This patch is work-in-progress, and the first step towards alleviating this. It delays the reflow by: * Snapshotting (copying) the original grid when an interactive resize is started. * While resizing, we apply a simple truncation resize of the grid (like we handle the alt screen). * When the resize is done, or paused for ‘resize-delay-ms’, the grid is reflowed. TODO: we *must* not allow any changes to the temporary (truncated) grid during the resize. Any changes to the grid would be lost when the final reflow is applied. That is, we must completely pause the ptmx pipe while a resize is in progress. Future improvements: The initial copy can be slow. We should be able to avoid it by rewriting the reflow algorithm to not free anything. This is complicated by the fact that some resources (e.g. sixel images) are currently *moved* to the new grid. They’d instead have to be copied.
2022-08-31grid: reflow: assert there aren’t any open URIs on the last rowDaniel Eklöf-0/+15
2022-08-31grid: reflow: don’t line-wrap the last rowDaniel Eklöf-21/+3
Before this patch, we would line-wrap the last row, just like any other row, and then afterwards try to reverse this, by adjusting the offset and free:ing and NULL:ing the "last row". The problem with this is if the scrollback is full. In this case, the row we’re freeing is the first row in the scrollback history. This means we’ll crash as soon as the viewport is moved to the top of the scrollback. The fix is fairly, simple. Skip the post-processing logic, and instead detect when we’re line-wrapping the last row, and skip the call to line_wrap(). This way, the last row in the new grid corresponds to the last row in the old grid.
2022-08-31grid: when setting the new viewport, ensure it’s correctly boundedDaniel Eklöf-17/+11
Do this by using scrollback relative coordinates, and ensure the new viewport is not larger than (grid_rows - screen_rows), as that would mean the viewport crosses the scrollback wrap-around.
2022-08-29grid: reflow: assert there aren’t any open URIs on the last rowDaniel Eklöf-0/+15
2022-08-29grid: reflow: don’t line-wrap the last rowDaniel Eklöf-21/+3
Before this patch, we would line-wrap the last row, just like any other row, and then afterwards try to reverse this, by adjusting the offset and free:ing and NULL:ing the "last row". The problem with this is if the scrollback is full. In this case, the row we’re freeing is the first row in the scrollback history. This means we’ll crash as soon as the viewport is moved to the top of the scrollback. The fix is fairly, simple. Skip the post-processing logic, and instead detect when we’re line-wrapping the last row, and skip the call to line_wrap(). This way, the last row in the new grid corresponds to the last row in the old grid.
2022-08-29grid: when setting the new viewport, ensure it’s correctly boundedDaniel Eklöf-17/+11
Do this by using scrollback relative coordinates, and ensure the new viewport is not larger than (grid_rows - screen_rows), as that would mean the viewport crosses the scrollback wrap-around.
2022-08-05grid: get rid of empty row at the bottom after reflowingDaniel Eklöf-0/+20
When the window is resized and we reflow the text, we ended up inserting an empty row at the bottom. This happens whenever the actual last row has a hard linebreak (which almost always is the case); we then end the reflow with a line break, causing an extra, empty, row to be allocated and inserted. This patch fixes this by detecting when: 1) the last row is empty 2) the next to last row has a hard line break In this case, we roll back the last line break, by adjusting the new offset we just calculated, and free:ing the empty row. TODO: it would be nice if we could detect this in the reflow loop instead, and avoid doing the last line break all together. I haven’t yet been able to find a way to do this correctly. Closes #1108
2022-06-30grid: reflow: require col count > 0 when skipping line truncationDaniel Eklöf-1/+1
When reflowing the grid, we truncate lines with a hard linebreak after the last non-empty cell. This way we don’t reflow trailing empty cells to a new line when resizing the window to a smaller size. However, “logical” lines (i.e. those without a hard linebreak) are *not* truncated. This is to ensure we don’t trim empty cells in the middle of a logical line spanning multiple physical lines. Since newly allocated rows are initialized with linebreak=false, we need to ensure _those_ are still truncated - otherwise all that empty space under the current prompt will be reflowed. Note that this is a temporary workaround. The correct solution, I think, is to track whether a line has been printed to or not, and simply ignore (not reflow) lines that haven’t yet been touched.
2022-06-30Revert "grid: invert the default value of ‘linebreak’, from false to true"Daniel Eklöf-11/+3
This reverts commit cdd46cdf85b1087ac7465c646bb05078f1bbe85b.
2022-06-16osc: add support for OSC 133;A (prompt markers)Daniel Eklöf-0/+40
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
2022-06-11grid: reflow: don’t trim trailing empty cells from logical linesDaniel Eklöf-0/+5
When a line in the old grid (the one being reflowed) doesn’t have a hard linebreak, don’t trim trailing empty cells. Doing so means we’ll “compress” (remove) empty cells between text if/when we revert to a larger window size. The output from neofetch suffers from this; it prints a logo to the left, and system information to the right. The logo and the system info column is separated by empty cells (i.e. *not* spaces). If the window is reduced in size such that the system info is pushed to a new line, each logo line ends with a number of empty cells. The next time the window is resized, these empty cells were ignored (i.e. removed). That meant that once the window was enlarged again, the system info column was a) no longer aligned, and b) had been pulled closer to the logo. This patch doesn’t special case trailing empty cells when the line being reflowed doesn’t have a hard linebreak. This means e.g. ‘ls’ output is unaffected. Closes #1055
2022-06-11grid: invert the default value of ‘linebreak’, from false to trueDaniel Eklöf-3/+11
2022-04-25grid: add abs-to-sb and sb-to-abs utility functionDaniel Eklöf-0/+28
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.
2022-02-07grid: reflow: add TODO to detect selection on re-used rows, and cancel itDaniel Eklöf-0/+7
2022-01-15replace gettimeofday with clock_gettimePranjal Kole-9/+9
POSIX.1-2008 has marked gettimeofday(2) as obsolete, recommending the use of clock_gettime(2) instead. CLOCK_MONOTONIC has been used instead of CLOCK_REALTIME because it is unaffected by manual changes in the system clock. This makes it better for our purposes, namely, measuring the difference between two points in time. tv_sec has been casted to long in most places since POSIX does not define the actual type of time_t.
2021-12-08grid: reload pointers into the uri range vector after insertingDaniel Eklöf-2/+40
Inserting elements into the URI range vector typically triggers a vector resize. This is done using realloc(). Sometimes this causes the vector to move, thus invalidating all existing pointers into the vector.
2021-12-08grid: reload pointers into the uri range vector after insertingDaniel Eklöf-2/+40
Inserting elements into the URI range vector typically triggers a vector resize. This is done using realloc(). Sometimes this causes the vector to move, thus invalidating all existing pointers into the vector.
2021-11-28grid: uri_range_erase(): unittest: try erasing a row without any URIsDaniel Eklöf-0/+4
2021-11-28grid: uri_range_erase: walk the ranges backwardsDaniel Eklöf-5/+4
This way, ranges are deleted last-to-first, thus avoiding memmoving multiple ranges over and over again when erasing e.g. a full line.
2021-11-27grid: remove useless assertionDaniel Eklöf-1/+0
grid.c:1041:24: warning: comparison of unsigned expression in ‘>= 0’ is always true [-Wtype-limits]
2021-11-27grid: resize without reflowing: use URI range utility functionsDaniel Eklöf-10/+13
2021-11-27grid: uri_range_{append,insert}: pass range attributes as separate parametersDaniel Eklöf-64/+54
2021-11-27grid: snapshot: use uri range utility functionsDaniel Eklöf-19/+14
2021-11-27grid: uri_range_ensure_size(): add the requested amount of entriesDaniel Eklöf-1/+1
2021-11-26grid: reflow: no need to keep a uri-range-idx variableDaniel Eklöf-14/+10
The URI ranges are now an array, which means we can get the next URI range by incrementing the pointer. Instead of checking if range is not NULL, check that it isn’t the range terminator (which is NULL when we don’t have any ranges, and the first address *after* the last range otherwise).
2021-11-26grid: resize without reflow: only verify URI ranges in debug buildsDaniel Eklöf-0/+2
2021-11-26grid: bug: OSC-8 URIs were incorrectly skipped while resizing the alt screenDaniel Eklöf-1/+1
2021-11-26osc8: replace grid_row_uri_range_add() with internal uri_range_append()Daniel Eklöf-151/+138
grid_row_uri_range_add() was only used while reflowing. In this case, we know the new URIs being added are always going at the end of the URI list (since we’re going top-to-bottom, left-to-right). Thus, we don’t need the insertion logic, and can simply append instead.
2021-11-26osc8: uri ranges: use a dynamically re-sizable array instead of a tllistDaniel Eklöf-107/+295
2021-11-25osc8: update URI ranges as we print data, *not* when the URI is closedDaniel Eklöf-35/+117
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
2021-11-21grid: refactor grid_row_uri_range_erase()Daniel Eklöf-43/+32
The old algorithm always created a new URI, followed by (maybe) removing the existing URI, when an URI needed to be modified. That is, if e.g. the tail of an URI was being erased, the old algorithm would create a new URI for the part of the URI that should remain, and then removed the old URI. This isn’t very effective. The new algorithm instead identifies all possible overlap cases, and handles each one differently: * URI ends *before* erase range starts - continue with the next URI without further checks * URI starts *after* the erase range ends - return, we’re done * Erase range erases the entire URI - remove the URI * Erase range erases a part in the middle - split the URI * Erase range erases the head of the URI - adjust the URI’s start * Erase range erases the tail of the URI - adjust the URI’s end
2021-11-21grid: row_uri_range_erase(): assume caller has checked row->extra != NULLDaniel Eklöf-2/+1
2021-11-21grid: add grid_row_uri_range_erase()Daniel Eklöf-5/+151
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).
2021-06-24composed: store compose chains in a binary search treeDaniel Eklöf-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.
2021-06-02grid: reflow: ‘amount’ has already been added to ‘from’Daniel Eklöf-1/+1
2021-06-02grid: reflow: URI range start: take over ownership of URI stringDaniel Eklöf-1/+2
Instead of strdup:ing the URI, take over ownership. This is ok since the old URI range will be free:d anyway.
2021-06-02grid: reflow: debug loggingDaniel Eklöf-12/+18
2021-06-02grid: reflow: when determining row end coord, check *last* URI rangeDaniel Eklöf-1/+5
2021-06-02grid: reflow: when determining row end coord, check *last* tracking pointDaniel Eklöf-2/+10
2021-06-02grid: reflow: check the *entire* row for non-empty cellsDaniel Eklöf-1/+1
2021-06-02grid: reflow: avoid unnecessary if-statements before chunking a rowDaniel Eklöf-8/+13
2021-06-02grid: disable reflow timing by defaultDaniel Eklöf-1/+1
2021-06-02grid: reflow: commentsDaniel Eklöf-1/+22
2021-06-02grid: no need to keep the tp_col/uri_col variables aroundDaniel Eklöf-6/+3
2021-06-02grid: fix col max calculation when row contains URI rangesDaniel Eklöf-1/+1
2021-06-02grid: set tp/uri break flags explicitly when we know them to be trueDaniel Eklöf-6/+12
2021-06-02grid: reflow: slightly simplified logic for end-coordinate calculationDaniel Eklöf-10/+8
2021-06-02grid: reflow: rename _range -> rangeDaniel Eklöf-16/+16
2021-06-02grid: reflow: remove dead codeDaniel Eklöf-135/+0
2021-06-02grid: reflow: memcpy() chunks of cells, instead of single cell-by-cellDaniel Eklöf-1/+159
Instead of walking the old grid cell-by-cell, and checking for tracking points, OSC-8 URIs etc on each cell, memcpy() sequences of cells. For each row, find the end column, by scanning backward, looking for the first non-empty cell. Chunk the row based on tracking point coordinates. If there aren’t any tracking coordinates, or OSC-8 URIs on the current row, the entire row is copied in one go. The chunk of cells is copied to the new grid. We may have to split it up into multiple copies, since not all cells may fit on the current “new” row. Care must also be taken to not line break in the middle of a multi-column character.
2021-06-02grid: don’t cut multi-column chars in half when resizing the alt screenDaniel Eklöf-1/+5
When we resize the alt screen, we don’t reflow the text, we simply truncate all the lines. When doing this, make sure we don’t truncate in the middle of a multi-column character.
2021-05-23grid: reflow: uri-ranges: avoid looping URI ranges when reflowingDaniel Eklöf-54/+57
Since we know the following: * URI ranges are sorted * URI coordinates are unique * URI ranges don’t cross rows We can optimize URI range reflowing by: * Checking if the *first* URI range’s start coordinate is on the current column. If so, keep a pointer to it. * Use this pointer as source when instantiating the reflowed URI range * If we already have a non-NULL range pointer, check its end coordinate instead. * If it matches, close the *last* URI range we inserted on the new row, and free/remove the range from the old row. * When line breaking, we only need to check if the *last* URI range is unclosed.
2021-05-22grid: row_add_uri_range: ensure the URIs are sortedDaniel Eklöf-1/+7
2021-05-17grid: disable timing of resize operationsDaniel Eklöf-1/+1
2021-05-17grid: reflow: free old rows as soon as we’re done with themDaniel Eklöf-3/+8
This reduces the memory cost of reflowing text, as we no longer needs to hold both the old and the new grid, in their entirety, in memory at the same time.
2021-05-17grid: reflow: don’t initialize newly allocated rowsDaniel Eklöf-3/+9
We’re going to write to it immediately anyway. In most cases, *all* newly allocated, and zero-initialized, cells are overwritten. So let’s skip the zero-initialization of the new cells. There are two cases where we need to explicitly clear cells now: * When inserting a hard line break - erase the remaining cells * When done, the *last* row may not have been completely written - erase the remaining cells
2021-05-15grid: reflow: qsort_r() is not portableDaniel Eklöf-11/+15
Replace with qsort() + global variable. Not thread safe!
2021-05-15grid: include <stdlib.h>, for qsort_r()Daniel Eklöf-0/+1
2021-05-15grid: reflow: always run qsort_r(), handle rows == 0 in tp_cmp() insteadDaniel Eklöf-7/+5
2021-05-15grid: take scrollback start into account when sorting the tracking points arrayDaniel Eklöf-9/+29
The row numbers in the tracking points are in absolute numbers. However, when we walk the old grid, we do so starting in the beginning of the scrollback history. We must ensure the tracking points are sorted such that the *first* one we see is the “oldest” one. I.e. the one furthest back in the scrollback history.
2021-05-15grid: fix 32-bit compilationDaniel Eklöf-2/+4
2021-05-15grid: reflow: tag tracking point if-statements with likely/unlikelyDaniel Eklöf-5/+5
2021-05-15grid: reflow: use a sorted array for tracking pointsDaniel Eklöf-27/+66
Instead of iterating a linked list of tracking points, for *each and every* cell in the old grid, use a sorted array. This allows us to step through the array of tracking points as we walk the old grid; each time we match a tracking point, we move to the next one. This means we only have to check a single tracking point for each cell.
2021-05-14grid: reflow: no need to check for combining charactersDaniel Eklöf-21/+10
Since we no longer call wcwidth(), we don’t need the base character.