Commit graph

34 commits

Author SHA1 Message Date
Daniel Eklöf
bb74fe3f7d
grid: add grid_free() 2021-02-26 09:15:45 +01:00
Daniel Eklöf
5eea06cff9
grid: add new function grid_row_add_uri_range() 2021-02-21 20:15:32 +01:00
Daniel Eklöf
00977fcc15
grid: add new function, grid_row_reset_extra()
This function resets (free:s) all ‘extra’ data associated with a row.
2021-02-21 20:15:31 +01:00
Craig Barnes
e56136ce11 debug: rename assert() to xassert(), to avoid clashing with <assert.h> 2021-01-16 20:16:00 +00:00
Daniel Eklöf
9a498038d6
resize: don’t reflow text on alt screen
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
2020-11-25 07:47:40 +01:00
Daniel Eklöf
61f950f77a
grid: reflow: calculate width of composed characters correctly
Before this patch, reflow called `wcwidth()` on our magic values for
composed characters.
2020-09-06 19:14:46 +02:00
Daniel Eklöf
57e04a1320
grid: swap_row: remove unused parameter 'initialize' 2020-05-16 23:43:05 +02:00
Daniel Eklöf
5e2e59679b
grid: reflow: make tracking_points array 'const'
The elements aren't, and cannot be, const. But the array itself can,
and should be.
2020-04-17 22:19:59 +02:00
Daniel Eklöf
ef52ed8a10
grid: reflow: caller may now pass a list of coordinates that should be translated 2020-04-17 21:04:32 +02:00
Daniel Eklöf
5546b40369
grid: grid_reflow() now translates cursor coordinates 2020-04-16 19:38:30 +02:00
Daniel Eklöf
38a682f0d0
render/grid: move grid reflow code to grid.c 2020-02-15 22:19:08 +01:00
Daniel Eklöf
aee5045395
search: wip: initial search matching
* 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.
2019-08-27 19:33:19 +02:00
Daniel Eklöf
7c7720a3ab
scrolling: optimize row access by assuming number of rows is a power of 2
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.
2019-08-22 17:33:23 +02:00
Daniel Eklöf
decb4503bf
grid: prefetch cells in grid_row() 2019-07-10 19:52:30 +02:00
Daniel Eklöf
132749b1ed
grid: repair grid_row_in_view(): use 'view', not 'offset' 2019-07-10 16:35:52 +02:00
Daniel Eklöf
1ff1b3a71e
grid: don't pre-allocate the entire grid (with all scrollback lines)
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.
2019-07-10 16:27:55 +02:00
Daniel Eklöf
8f0d574dcb
grid: don't implement grid_swap_row() in the header file 2019-07-10 16:08:53 +02:00
Daniel Eklöf
bcd111d203
wip: initial scroll back support
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...
2019-07-09 16:26:36 +02:00
Daniel Eklöf
4e25019ba6
wip: grid is now represented as a grid, not a linear array
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.
2019-07-08 13:57:31 +02:00
Daniel Eklöf
48528419c4
grid: grid_memset() -> grid_memclear() 2019-07-07 17:10:15 +02:00
Daniel Eklöf
a7a28ff581
scrolling: initial reverse scrolling support - no scroll regions 2019-07-03 10:45:49 +02:00
Daniel Eklöf
482f56b4a2
grid: implement a memmove-sort-of function
grid_memmove() moves cell data from one index to another, taking the
grid offset into account.
2019-07-01 19:18:52 +02:00
Daniel Eklöf
d70956da08
wip: use a sliding window instead of memmove() to scroll
Instead of memmoving a large amount of data on every scroll, use a
sliding window. That is, each time we scroll, we offset origin.
2019-07-01 12:23:38 +02:00
Daniel Eklöf
1ecd4a6ae1
Rename grid_* functions to term_* 2019-06-29 21:03:28 +02:00
Daniel Eklöf
a35738d96f
scroll-region: don't clear damage queue when changing scroll region
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.
2019-06-25 20:11:08 +02:00
Daniel Eklöf
2fe7145aff
scrolling region: wip 2019-06-23 21:12:32 +02:00
Daniel Eklöf
b0a2c54fe8
vt: wip: implement scrolling region
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.
2019-06-23 18:02:49 +02:00
Daniel Eklöf
fbf0db621c
vt: implement reverse scrolling (terminfo 'ri')
This currently duplicates the code paths for DAMAGE_SCROLL; there are
many similarities between the two, but also major differences...
2019-06-23 17:16:52 +02:00
Daniel Eklöf
a50be28b9d
grid: implement DAMAGE_SCROLL 2019-06-21 14:29:15 +02:00
Daniel Eklöf
304f15d696
Use a 'damage' list to communicate what needs to be updated
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).
2019-06-19 14:17:43 +02:00
Daniel Eklöf
efc8cc4914
wip: initial scrolling support (no scrollback though) 2019-06-19 10:27:31 +02:00
Daniel Eklöf
71dde121e6
wip: initial input handling 2019-06-19 10:04:47 +02:00
Daniel Eklöf
50c43be0d9
grid: track both linear and row,col cursor 2019-06-17 21:15:20 +02:00
Daniel Eklöf
4585df532c
wip: vt parsing: break out grid operating functions 2019-06-17 19:33:10 +02:00