Commit graph

3969 commits

Author SHA1 Message Date
Daniel Eklöf
207d9045ca
Merge branch 'add-bash-completions'
Closes #10
2021-03-17 19:45:11 +01:00
Simon Schricker
b169623b64
Add: Bash completion for foot and footclient
* use toe for terminfo, thanks Craig.
* adds optional dependency on bash-completion for positional arguments

Co-authored-by: Craig Barnes <craigbarnes@protonmail.com>
2021-03-17 13:10:28 +01:00
Daniel Eklöf
749ae49c48
Merge branch 'optimized-print-function' 2021-03-16 21:59:06 +01:00
Daniel Eklöf
d271119032
csi: update ASCII printer function pointer when switching to/from alt screen
This is necessary since switching screen may change how many sixels we
have in the scrollback.
2021-03-16 13:07:09 +01:00
Daniel Eklöf
b601307fae
term: update_ascii_printer(): log when we (actually) switch printer 2021-03-16 12:57:25 +01:00
Daniel Eklöf
11f2c85acf
config: open_config(): remove unused argument ‘conf’ 2021-03-16 09:54:32 +01:00
Daniel Eklöf
60b3ccc641
term: runtime switch between a ‘fast’ and a ‘generic’ ASCII print function
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
2021-03-16 08:45:18 +01:00
Daniel Eklöf
d8f0e701b5
Merge branch 'term-print-assume-col-can-be-incremented' 2021-03-16 08:44:25 +01:00
Daniel Eklöf
2451699c35
term: term_print(): assume we’re *not* at the right margin
That is, assume we can, and should, increment the cursor column.

This changes the emitted assembly from:

   518fb:       8b 8b f8 05 00 00       mov    0x5f8(%rbx),%ecx
   51901:       ff c9                   dec    %ecx
   51903:       39 d1                   cmp    %edx,%ecx
   51905:       7e 11                   jle    51918 <term_print.constprop.0+0x78>
   51907:       ff c2                   inc    %edx
   51909:       89 50 10                mov    %edx,0x10(%rax)
   5190c:       5b                      pop    %rbx
   5190d:       5d                      pop    %rbp
   5190e:       41 5c                   pop    %r12
   51910:       c3                      ret
   51911:       0f 1f 80 00 00 00 00    nopl   0x0(%rax)
   51918:       c6 40 18 01             movb   $0x1,0x18(%rax)
   5191c:       5b                      pop    %rbx
   5191d:       5d                      pop    %rbp
   5191e:       41 5c                   pop    %r12
   51920:       c3                      ret

To:

   5191c:       41 8d 50 01             lea    0x1(%r8),%edx
   51920:       89 50 10                mov    %edx,0x10(%rax)
   51923:       3b 93 f8 05 00 00       cmp    0x5f8(%rbx),%edx
   51929:       0f 8d 21 01 00 00       jge    51a50 <term_print.constprop.0+0x190>
   5192f:       5b                      pop    %rbx
   51930:       5d                      pop    %rbp
   51931:       41 5c                   pop    %r12
   51933:       c3                      ret
   ...
   51a50:       c6 40 18 01             movb   $0x1,0x18(%rax)
   51a54:       44 89 40 10             mov    %r8d,0x10(%rax)
   51a58:       5b                      pop    %rbx
   51a59:       5d                      pop    %rbp
   51a5a:       41 5c                   pop    %r12
   51a5c:       c3                      ret

I.e. it cuts the normal path from 10 instructions down to 8. It
increases the "bad" path with one extra instruction.
2021-03-14 20:47:44 +01:00
Daniel Eklöf
c5c3447ca8
sixel: sixel_overwrite_at_cursor(): early exit when the image list is empty
This avoids a call to sixel_overwrite_by_row() (where we also exit
early if the image list is empty).

This saves a couple of instructions to set up the arguments for
sixel_overwrite_by_row().
2021-03-14 14:19:12 +01:00
Daniel Eklöf
2a723e1c4c
Merge branch 'sixel-fix-max-geometry' 2021-03-14 13:07:13 +01:00
Daniel Eklöf
e7a4378f18
Merge branch 'option-no-wait'
Closes #395
2021-03-14 13:05:41 +01:00
Daniel Eklöf
6eb68ffbd9
sixel: max geometry should be max geometry, not current window size
“current geometry” will report whatever value is the smallest; the max
geometry or the current window size.

But “max geometry” always returns the configured max geometry.

This aligns foot’s behavior with XTerm.
2021-03-14 10:58:13 +01:00
Daniel Eklöf
29709c6966
scripts: generate-alt-random: reduce number of emitted sixels
After emitting multiple color bands for each sixel row, the increased
amount of sixel data shifted the balance in the profiling data,
causing a performance regression in regular ASCII handling.
2021-03-14 10:40:29 +01:00
Daniel Eklöf
4fca142f71
Merge branch 'drain-pty-when-client-terminates' 2021-03-13 21:36:30 +01:00
Felipe Trzaskowski
452830bd08 add changelog entry, completions and man entry for -N, --no-wait 2021-03-13 08:07:08 -03:00
Felipe Trzaskowski
2dc13cc13b fix code style issues and memory leak 2021-03-13 08:01:38 -03:00
Felipe Trzaskowski
3ed9314266 add option to detach the client process from the terminal instance 2021-03-13 05:48:55 -03:00
Daniel Eklöf
329f2a488c
term: don’t close PTY when client application dies
Closing it as soon as we detect that the client has died, means we may
not have drained it completely.

The PTY is either closed _by_ the client application, or by us when we
shutdown the terminal. Thus, leaving it open (until we call
term_shutdown()) is fine.
2021-03-12 22:06:50 +01:00
Daniel Eklöf
464851fac1
client: repair usage output 2021-03-12 21:53:11 +01:00
Daniel Eklöf
84f840a197
client: remove excess ‘-’ from ‘--log-level’ in usage 2021-03-12 21:51:07 +01:00
Daniel Eklöf
ebc57d1a80
changelog: sixel decoding performance improvements 2021-03-12 21:43:35 +01:00
Daniel Eklöf
f19e1e4c36
Merge branch 'sixel-background-and-transparency'
Closes #391
2021-03-12 21:42:17 +01:00
Daniel Eklöf
5a9ae07167
changelog: implemented DCS parameter P2 2021-03-11 17:37:56 +01:00
Daniel Eklöf
655e756f58
render: sixels: render cursor, if it’s partially covered by an opaque sixel 2021-03-11 17:34:19 +01:00
Daniel Eklöf
7d315d7bf9
sixel: implement P2=1 - transparent pixels
When P2=1, empty pixels are transparent.

This patch also changes the behavior of P2=0|2, from setting empty
pixels to the default background color, to instead use the *current*
background color.

To implement this, a couple of changes are needed:

* Sixel pixels always use alpha=1.0, except for *empty* cells when
  P2=1 (i.e. transparent pixels).
* The renderer draws sixels with the OVER operator, instead of the SRC
  operator.
* The renderer *must* now render the cells beneath the sixel. As an
  optimization, this is only done for sixels where P2=1. I.e. for
  fully opaque sixels, there’s no need to render the cells beneath.

The sixel renderer isn’t yet hooked into the multi-threaded
renderer. This means *rows* (not just the cells) beneath
maybe-transparent sixels are rendered single-threaded.

Closes #391.
2021-03-11 17:34:19 +01:00
Daniel Eklöf
5650120e08
Merge branch 'sixel-optimize' 2021-03-11 17:33:41 +01:00
Daniel Eklöf
5e852f148e
changelog: empty pixel rows at the bottom of a sixel is now trimmed 2021-03-11 17:33:01 +01:00
Daniel Eklöf
6f6bcbc1bc
sixel: decgra: set max-non-empty-row-no when resizing the image
This ensures we don’t trim off bottom rows in unhook().

This could happen either because the application used “Set Raster
Attributes” to configure an image size larger than the sixels later
emitted.

Or, the last sixel row contains empty pixel rows.

In either case, the size set with “Set Raster Attributes” defines
the *minimum* image size; the image may still end up being larger.
2021-03-11 17:33:01 +01:00
Daniel Eklöf
a8186351d1
generate-alt-random: sixel: emit at least 4 color bands
This fixes an issue where there was a relatively high chance of not
emitting any color bands at all, causing the final image size to be
too small.
2021-03-11 17:33:01 +01:00
Daniel Eklöf
f3bc5a95b5
generate-alt-random: DECGRI: don’t emit zero-length repeat sequences 2021-03-11 17:33:00 +01:00
Daniel Eklöf
8ba455f70e
generate-alt-random: DECGRI: random repeat lengths 2021-03-11 17:33:00 +01:00
Daniel Eklöf
660a7f9345
generate-alt-random: don’t skip that last partial row 2021-03-11 17:33:00 +01:00
Daniel Eklöf
0bc98877f3
generate-alt-random: emit “Set Raster Attributes” before color definitions 2021-03-11 17:33:00 +01:00
Daniel Eklöf
a3f2e2220a
generate-alt-random: 50% chance of overwriting the last sixel 2021-03-11 17:33:00 +01:00
Daniel Eklöf
4a86cd7475
generate-alt-random: emit sixels on the alt screen 2021-03-11 17:32:59 +01:00
Daniel Eklöf
f8e51fcb17
generate-alt-random: emit multiple sixel bands
This ensures we’re getting the ‘$’ command PGO:d
2021-03-11 17:32:59 +01:00
Daniel Eklöf
ae86043780
sixel: decgri: handle a repeat count of 0, by ignoring it 2021-03-11 17:32:59 +01:00
Daniel Eklöf
eee216f5fe
generate-alt-random: sixel: pan/pad must not be 0 2021-03-11 17:32:59 +01:00
Daniel Eklöf
6d208fa5e0
sixel: add: add sixel_add_many(), improving performance of DECGRI
DECGRI, i.e. repeat sixel character, only need to do image resizing,
and updating the current ‘column’ value *once*.

By adding sixel_add_many(), and doing the size/resize checking there,
the performance of sixel_add() is made much simpler.

This boosts performance quite noticeably when the application is
emitting many and/or long repeat sequences.
2021-03-11 17:32:59 +01:00
Daniel Eklöf
6e963dbf68
sixel: add: calculate absolute row no inside the loop
This results in the same number of instructions inside the loop, with
a ‘lea’ instead of a ‘mov’, but simplifies the post-loop logic to
update the global state.
2021-03-11 17:32:59 +01:00
Daniel Eklöf
751ccf5316
sixel: add: increase data pointer instead of offset
Same ‘add’ instruction to increase the offset, but simpler ‘mov’
instruction when writing the pixel data.
2021-03-11 17:32:58 +01:00
Daniel Eklöf
777576b66b
sixel: decgri: avoid load inside for-loop 2021-03-11 17:32:58 +01:00
Daniel Eklöf
9f224a13df
sixel: add optimized resize_horizontally() and resize_vertically()
The resize operations performed in the “hot” path either change the
width, or the height, but not both at the same time.
2021-03-11 17:32:58 +01:00
Daniel Eklöf
c181eb2bf6
sixel: empty pixels in the last sixel row doesn’t contribute to the image height
All-empty pixels rows in the last sixel row should not be included in
the final sixel image.

This allows applications to emit sixels whose height is not a multiple
of 6, and is how XTerm works.

This is done by tracking the largest row number that contains
non-empty pixels.

In unhook, when emitting the image, the image height is adjusted based
on this value.
2021-03-11 17:32:58 +01:00
Daniel Eklöf
d35963f584
sixel: resize: width is no longer a multiple of 6 2021-03-11 17:32:58 +01:00
Daniel Eklöf
6ab7052be4
sixel: set ‘col’ outside image boundaries when we’ve reached max height
This is to optimize sixel_add(). It already checks ‘pos’, to see if it
needs to resize the image, and if the resize fails (either due to
allocation failures, or because we’ve reached the maximum width), we
bail out.

We need to do the same thing for height. But, we don’t want to add
another check to sixel_add() since its’s performance critical.

By setting ‘col’ outside the image boundaries when ‘row’ reaches the
maximum image height, we can “re-use” the existing code in
sixel_add().
2021-03-11 17:32:58 +01:00
Daniel Eklöf
4b0e9a6bee
sixel: remove ‘max_col’
The image width *is* the maximum number of columns we’ve seen.
2021-03-11 17:32:57 +01:00
Daniel Eklöf
1c9c1aafc8
sixel: adjust image height when processing ‘-’ 2021-03-11 17:32:57 +01:00
Daniel Eklöf
891e0819f0
sixel: resize: check new width/height against max geometry early 2021-03-11 17:32:57 +01:00