Commit Graph

18895 Commits

Author SHA1 Message Date
Johannes Altmanninger
c8f3659737 Add special_key=1 to prompt marking
Kitty uses this for more graceful mouse handling
when the completion pager is active, see
https://github.com/kovidgoyal/kitty/pull/7316#issuecomment-2041279797
2024-04-07 09:59:09 +02:00
Johannes Altmanninger
3b9e3e251b Emit OSC 133 sequences to mark prompt/command output regions
This allows terminals like foot and kitty to
* scroll to the previous/next prompt with ctrl-shift-{z,x}
* pipe the last command's output to a pager with ctrl-shift-g

Kitty has existing fish shell integration
shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish which we
can simplify now. They keep a state variable to decide which of prompt start,
command start or command end to output.  I think with our implementation
this is no longer necessary, at least I couldn't reproduce any difference.
We also don't need to hook into fish_cancel or fish_posterror like they do;
only in the one place where we actually draw the prompt.

As mentioned in the above shell integration script, kitty disables reflow
when it sees an OSC 133 marker, so we need to do it ourselves,
otherwise the prompt will go blank after a terminal resize.

Closes #10352
2024-04-06 22:22:56 +02:00
Johannes Altmanninger
33701faa8c completions/set: offer private variables if token starts with _ 2024-04-06 21:20:53 +02:00
Johannes Altmanninger
18f6492564 completions/set: strip cursed descriptions from history/fish_killring
If I type

    $ echo $SOME_VARIABLE_WIHT_A_TYPO
    $ set -S SOME_VARIABLE_WIHT

and press tab, I'm always extremely surprised that this completes to

    $ set -S fish_history

which is because $history[1] contains the typo'd variable name.  I don't
think anyone intends to filter by that last 3-4 history items, so let's
remove this pitfall.

Note that I usually hit this scenario with undefined variables, not necessarily
typos.. "set -S" is usually redundant but it's still quite nice in this case,
to rule out any weird empty strings/empty lists.
2024-04-06 19:12:25 +02:00
Johannes Altmanninger
444cda20bc Document focus events 2024-04-06 18:14:17 +02:00
Johannes Altmanninger
8a7c3ceec3 Don't abandon line after writing control sequences
Commit 8164855b7 (Disable terminal protocols throughout evaluation, 2024-04-02)
changed where we output control sequences (to enable bracketed paste and CSI).
Likewise, f285e85b0 (Enable focus reporting only just before reading from
stdin, 2024-04-06) added control sequence output just before we read().

This output causes problems because it invalidates our stdout/stderr
timestamps, which causes us to think that a rogue background process wrote
to the terminal; we react by abandoning the current line and redrawing the
prompt below. Our fix was to refresh the TTY timestamps after we run a bind
command that might add stdout (#3481).

Since commit c3cd68dda (Process shell commands from bindings like regular
char events, 2024-03-02), this timestamp refresh logic is in the wrong place;
shell commands are run later now; we could move it but wait -

... we also need to make sure to refresh timestamps after outputting control
sequences.  Since bracketed paste is enabled after CSI u, we can skip the
latter.  Additionally, since we currently output control sequences before
every single top-level interactive command, we no longer need to separately
refresh timestamps in between commands.

Fixes #10409
2024-04-06 17:45:55 +02:00
Johannes Altmanninger
de730b7885 Extract function for running commands from bindings 2024-04-06 17:45:55 +02:00
Johannes Altmanninger
f285e85b0c Enable focus reporting only just before reading from stdin
Some terminals send the focus-in sequences ("^[I") whenever focus reporting is
enabled.  We enable focus reporting whenever we are finished running a command.
If we run two commands without reading in between, the focus sequences
will show up on the terminal.

Fix this by enabling focus-reporting as late as possible.

This fixes the problem with `^[I` showing up when running "cat" in
gnome-terminal https://github.com/fish-shell/fish-shell/issues/10411.

This begs the question if we should do the same for CSI u and bracketed paste.
It's difficult to answer that; let's hope we find motivating test cases.
If we enable CSI u too late, we might misinterpret key presses, so for now
we still enable those as early as possible.

Also, since we now read immediately after enabling focus events, we can get
rid of the hack where we defer enabling them until after the first prompt.
When I start a fresh terminal, the ^[I no longer shows up.
2024-04-06 11:22:19 +02:00
Johannes Altmanninger
7ffe023735 builtin read: enable terminal protocols again
It's not clear whether builtin read should be able to do everything
that the normal prompt does but I guess we haven't found a problem yet.
Given that read could be used to read a single character at a type,
it's a bit odd to toggle terminal protocols all the time.
But that's not the typical case (at least not for when stdin is a TTY),
and it seems fine.

Teste with

    bind ctrl-4 'echo yay'

Regressed in 8164855b7 (Disable terminal protocols throughout evaluation,
2024-04-02).
2024-04-06 11:22:19 +02:00
Johannes Altmanninger
629cad66a3 Clean up log statement 2024-04-06 11:22:19 +02:00
Fabian Boehm
1a4bb851ff docs: More on dereferencing variables 2024-04-05 18:41:09 +02:00
phanium
0a6e8468cc Avoid invoking extra subshell in __fish_md5 2024-04-05 15:26:48 +02:00
phanium
aa1a390504 Replace __funced_md5 with __fish_md5 2024-04-05 15:26:48 +02:00
phanium
b121b9649b Fix completions for pactree, pkgfile 2024-04-05 15:26:06 +02:00
Klaus Hipp
3c9b5713c9 Update code completions 2024-04-05 15:25:32 +02:00
Armin Brauns
3c0d7d0feb Add typst completions 2024-04-05 15:24:36 +02:00
Felix Luciano Salomon
8bbf760860
Added bruno completions (#10388)
* Added bruno completions

* Modified format completion to include formats as closed list arguments
2024-04-05 15:23:29 +02:00
Fabian Boehm
ce92472af1 input: Comment out flogs
These are *extremely* chatty.

If they are needed we should add them to a subcategory like `input` or
`reader-input` so you can easily disable them.
2024-04-03 20:15:17 +02:00
Fabian Boehm
1f2e0617d1 tests: Pass correct length for buffer
This allocated 64 bytes and then told snprinf it was 128. That's a
no-no even if we never need that much.
2024-04-03 20:15:17 +02:00
Johannes Altmanninger
66c6e89f98 Don't add collateral sentinel key to input queue
This is for bracketed paste and focus reporting where we already add a proper
event to the queue.
2024-04-03 20:02:08 +02:00
Johannes Altmanninger
1baa893e60 Don't end history search on focus in/out events
Apparently VTE terminals send the "focus in" event whenever we re-enable
focus reporting. That's probably a sensible thing to do.

Anyway, our problem is simply that we accidentally end history search on these
focus events which are implemented as anonymous (unmappable) readline cmds.
Perhaps there should be a separate cmd category.

Focus events show up as key::Invalid which is a weird private use code point;
probably we can get rid of this key..

Fixes #10411
2024-04-03 20:02:08 +02:00
Johannes Altmanninger
350598cb99 Decode arrow keys as sent by urxvt
Not sure if we want to support this indefinitely but appears to be free as
of today.
2024-04-03 19:37:03 +02:00
Fabian Boehm
e8eb4822ce input: Fix crash for weird bracketed paste
I can reproduce by pasting after

```fish
echo \cc foo | fish_clipboard_copy
```

in Wezterm
2024-04-03 16:30:38 +02:00
Johannes Altmanninger
cb58a30bf2 Report $PWD changes unconditionally
Similar to 20bbdb68f (Set terminal title unconditionally, 2024-03-30).

While at it, get rid of a few unnecessary guards (we are never called from
a command substitution, so the check only adds confusion).
2024-04-03 13:14:02 +02:00
Johannes Altmanninger
9870faa8be Remove workarounds for Emacs ansi-term
I'm not sure if it's worth supporting a terminal that mishandles unknown OSC
and CSI sequences. Better to fix the terminal.  Note that there are Emacs
terminals available that don't have this problems; for example "vterm".
2024-04-03 13:09:27 +02:00
Johannes Altmanninger
af1b599818 On redo, restore pre-undo cursor position 2024-04-03 13:09:27 +02:00
Fabian Boehm
3af849d739 tests/pexpect: Fix \d escape 2024-04-02 22:41:54 +02:00
Fabian Boehm
171869858a tests/histfile.py: Check for no jobs 2024-04-02 22:24:09 +02:00
Fabian Boehm
3d46987cff tests/histfile.py: Try exiting a second time 2024-04-02 22:19:47 +02:00
Fabian Boehm
fe95e4f4cd curses: Remove f13-f20
No longer supported by keys, and these are not a thing in the real world
2024-04-02 21:33:54 +02:00
Johannes Altmanninger
8164855b70 Disable terminal protocols throughout evaluation
Test changes are very hacky, will cleanup later.

Closes #10408
2024-04-02 21:25:47 +02:00
Fabian Boehm
6501f7ab6f tests: Disable terminal.py under asan
We want asan to tell us about memory errors, not randomly fail tests
because it's too slow.
2024-04-02 19:57:57 +02:00
Johannes Altmanninger
695b408396 kitty keyboard protocol: decode numlock keys
Also disable the legacy matching hack for CSI u sequences, to prevent bindings
from treating this as prefix.
2024-04-02 18:20:35 +02:00
Johannes Altmanninger
b04dee358e Don't translate \n to enter
Apparently it's never entere because we turn off ICRNL.

I'm not sure why it says "no binding found".
2024-04-02 17:59:40 +02:00
Fabian Boehm
53961c7759 Fix doc formatting
This is RST, not markdown
2024-04-02 17:39:39 +02:00
Fabian Boehm
ec603790d1 nim prompt: Don't use test
A single-argument use, even!

Fixes #10404
2024-04-02 17:33:30 +02:00
Johannes Altmanninger
e8e91c97a6 fish_key_reader: ignore sentinel key
Also, move the undo grouping for paste to the right place.
2024-04-02 16:48:25 +02:00
Johannes Altmanninger
8bf8b10f68 Extended & human-friendly keys
See the changelog additions for user-visible changes.

Since we enable/disable terminal protocols whenever we pass terminal ownership,
tests can no longer run in parallel on the same terminal.

For the same reason, readline shortcuts in the gdb REPL will not work anymore.
As a remedy, use gdbserver, or lobby for CSI u support in libreadline.

Add sleep to some tests, otherwise they fall (both in CI and locally).

There are two weird failures on FreeBSD remaining, disable them for now
https://github.com/fish-shell/fish-shell/pull/10359/checks?check_run_id=23330096362

Design and implementation borrows heavily from Kakoune.

In future, we should try to implement more of the kitty progressive
enhancements.

Closes #10359
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
8ada027f05 Run asan and macOS CI in release mode too
I don't know why we're inconsistent about this, and at least asan fails
frequently due to timeouts.
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
16c5ca2609 Fix mouse handling tests to send valid escape sequences 2024-04-02 14:35:16 +02:00
Johannes Altmanninger
22717339b4 fish_clipboard_paste: don't bypass pager search field.
To do so add an ad-hoc "commandline --search-field" to operate on pager
search field.

This is primarily motivated because a following commit reuses the
fish_clipboard_paste logic for bracketed paste. This avoids a regression.
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
d0cdb142de Make CharEvent a native enum 2024-04-02 14:35:16 +02:00
Johannes Altmanninger
aa40c3fb7e Remove set-mode char event
Use generic shell commands instead.  This keeps us honest.

No functional change expected.
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
20bbdb68fa Set terminal title unconditionally
Terminal titles are set with an OSC 0 sequence.  I don't think we want to
support terminals that react badly to unknown OSC (or CSI) sequences.

So let's remove our feature detection.

This will fix future false negatives along the lines of
https://github.com/fish-shell/fish-shell/pull/10037
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
bb7704efe8 Fix potentially flaky tmux-history-search test
We need to give fish time to render I think.
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
4149a37f1c Pull rust-terminfo-fix for rio terminal
https://github.com/meh/rust-terminfo/pull/42
2024-04-02 08:01:48 +02:00
Johannes Altmanninger
a216b3cf6a Print panic message to stderr, like the stack trace 2024-04-02 07:34:19 +02:00
Johannes Altmanninger
1232cfd3bb Fix typo 2024-04-02 07:33:07 +02:00
Johannes Altmanninger
af6dc9221f Use panic::set_hook instead of catch_unwind to help debug panics 2024-04-02 07:27:22 +02:00
David Adam
698d8bd315 add comment regarding lru hashing algorithm 2024-04-01 22:33:22 +08:00