Commit Graph

21332 Commits

Author SHA1 Message Date
Johannes Altmanninger
7e3fac561d Query terminal only just before reading from it
Commit 5e317497ef (Query terminal before reading config, 2025-05-17)
disabled the kitty keyboard protocol in "fish -c read".  This seems
surprising, and it's not actually necessary that we query before
reading config; we only need query results before we read from
the TTY for the first time (which is about the time we call
__fish_config_interactive). Let's do that, reverting parts of
5e317497ef.
2025-09-26 12:59:02 +02:00
Johannes Altmanninger
7713e90aeb Make query response handling more consistent 2025-09-26 12:58:10 +02:00
Johannes Altmanninger
08ad5c26ea Give scroll-forward a less confusing name
ECMA-48 calls CSI S "scroll up", so use something like that but try
to avoid ambiguity.
2025-09-26 12:52:28 +02:00
Johannes Altmanninger
310b7eca68 Only initialize kitty keyboard capability on startup
If the initial query is interrupted by ctrl-c, we leave it unset. A
later rogue "\e[?0u" reply would make us enable it, which seems
surprising. Fix that by always setting the capability if we're gonna
read from stdin.
2025-09-26 12:10:56 +02:00
Johannes Altmanninger
e9ae143bab Fix cursor position reports being ignored
When we receive a cursor position report, we only store the result;
we'll act on it only when we receive the primary DA reply.  Make sure
we don't discard the query state until then.

Fixes 06ede39ec9 (Degrade gracefully when failing to receive cursor
position report, 2025-09-23)
2025-09-26 12:10:04 +02:00
Johannes Altmanninger
74d3832610 Early return in reader_execute_readline_cmd() 2025-09-26 12:10:04 +02:00
yegorc
3c04a05ea4 Added documentation for &>>.
The `&>>` redirection was undocumented.

Closes #11824
2025-09-26 12:10:04 +02:00
Johannes Altmanninger
e6541c5c93 Enable sphinx parallelism also when building markdown release notes
We get a warning about sphinx_markdown_builder not being
parallelizable. Fix that.

Ref: https://github.com/liran-funaro/sphinx-markdown-builder/pull/38
2025-09-26 12:10:04 +02:00
Johannes Altmanninger
7b495497d7 Only load sphinx_markdown_builder extension if it's used
As is, building man pages or HTML docs while sphinx_markdown_builder
is installed, will result in unrelated warnings.  Remove those by
removing it from the extensions config.  Markdown building (only used
for changelog) seems to work without this just fine.
2025-09-26 12:08:51 +02:00
Johannes Altmanninger
6e90d9bd6f Fix markdown changelog generation test
System tests typically run outside the workspace directory, but they
still have read-only access to the workspace; fix it accordingly.
This test only works on git checkouts, not in tarballs, so skip it
if .git doesn't exist.
2025-09-26 12:08:51 +02:00
Stevie Alvarez
b8f704e3c4 fish_git_prompt: add diverged upstream char option
Currently, `__fish_git_prompt_char_upstream_diverged` can only be set to
a combination of `__fish_git_prompt_char_upstream_behind` and
`__fish_git_prompt_char_upstream_ahead`s plain-text options. Adding a
combination of the less-plain character options gives users more choice.

Closes #11817
2025-09-25 11:38:52 +02:00
Johannes Altmanninger
b37b57781b Disable sphinx-markdown-builder in tests again for now
Somehow I didn't realize this breaks the tests/checks/sphinx-* tests.
2025-09-24 16:30:21 +02:00
Fabian Boehm
e3a5725a46 Fix crash if there is no xtversion reply 2025-09-24 16:21:18 +02:00
Karel Balej
3d5a5b8740 completions: add basic completions for udevil
Add a set of basic completions for udevil, which is a program that
allows unpriviledged users to mount devices.

Each command has a corresponding long-option-like syntax variant
(sometimes even multiple ones), such as "udevil monitor" -> "udevil
--monitor", which are omitted here for simplicity.

The project unfortunately seems long abandoned and as such no attempt to
submit these completions upstream has been made.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
22ffc31b71 release workflow: credit contributors in release notes
While at it, do a 's/^--$/^---/' to fix Markdown syntax for horizontal
line for CommonMark-based parsers.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
127c02992d Test markdown changelog creation in CI
Extract a github action to install the same version used in the release
workflow.  In future we should probably migrate to requirements.txt
or similar.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
765ca54d59 release workflow: resolve relative references in changelog properly
Instead of having sphinx-build only build CHANGELOG.rst, build the
entire thing, so relative references (":doc:", ":ref:") can be resolved
properly.  Replace our sed-based hacks with 'markdown_http_base'.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
1519ea74be release workflow: extract script for generating markdown release notes 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
2895986465 tests/sphinx-man: man page building no longer requires fish_indent 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
e9e7ad24b5 Changelog: also extract changes to embed-data to its own section 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
4f8aa0a78c Show warnings from sphinx-build when building with cargo 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
f821d6dd7f Feature flag for turning off TTY querying
Experience with OSC 133 and kitty keyboard protocol enabling sequences
has shown that a lot of users are still on incompatible terminals.
It's not always easy to fix those terminals straight away. There
are probably some more environments where primary device attribute
queries are not answered.

Add a feature flag (similar to keyboard-protocols and mark-prompt)
to allow users to turn this off.

When the terminal fails to respond to primary device attribute, we
already print an error pointing to "help terminal-compatibility".
Inside that document, inside the "primary device attribute" section,
point out this new feature flag.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
4c1da3b2d3 Parse Terminal.app version only if needed 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
a6f975a7e3 Add mark-prompt feature flag
(not sure if we should also include this in 4.1 but I guess better
safe than sorry)

So far, terminals that fail to parse OSC sequences are the only reason
for wanting to turn off OSC 133.  Let's allow to work around it by
adding a feature flag (which is implied to be temporary).

To use it, run this once, and restart fish:

    set -Ua fish_features no-mark-prompt

Tested with

    fish -i | string escape | grep 133 &&
    ! fish_features=no-mark-prompt fish -i | string escape | grep 133

Closes #11749
Also #11609

(cherry picked from commit 6900b89c82)
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
bbd7205de1 Document GNU screen incompatibily & workarounds
The problem described in 829709c9c4 (Replace synchronized update
workaround, 2025-04-25) doesn't seem too bad; let's document the
workaround.

We could probably also remove our $STY-based workaround.  I'm not
yet sure how many problems that one will cause.

Closes #11437
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
64c8d361b0 status.rst: link to feature flag documentation 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
c31e769f7d Use XTVERSION for terminal-specific workarounds
As mentioned in earlier commit
("Query terminal before reading config").

Closes #11812
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
99854c107a Set kitty keyboard capability only at startup 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
5e317497ef Query terminal before reading config
We still have terminal-specific workarounds based on TERM_PROGRAM and
others, see test/test_driver.py.  In future we should get rid of them.

They are also unreliable, potentially missing inside SSH/containers,
incorrect if a terminal was started from another terminal (#11812);
also TERM can be incorrect for many reasons.

The better criterion for terminal-specific workarounds is XTVERSION,
which has none of the above disadvantages.

Since some of the workarounds (tmux, iTerm2) need to be applied before
we draw the first prompt. This also means: before we read any config
because config may call builtin "read".

Do startup queries before reading config.

Some changes implied by this:
1. Remove a call to init_input() which is already done by env_init()
2. call initialize_tty_metadata() only after queries have returned
3. Since we call initialize_tty_metadata() before the first
   call to tty.enable_tty_protocols() in Reader::readline(),
   we can remove the redundant call from reader_interactive_init().
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
96f63159b5 Be consistent about how we handle bad stdin FD
When poll() or read() on stdin fails, fish's interactive reader
pretends it has received SIGHUP, and subsequently exits.

I don't know if this is the right thing to do, or how to reproduce
this in a realistic scenario.

Unlike fish, fish_key_reader seems to ignore these failures, meaning
it will retry poll()/read() immediately.  This seems less correct,
so use fish's behavior for now.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
fadb2fac44 Fix some import conventions 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
1b01ac87fa Improve a tcsetpgrp error message 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
4abd390c84 test_driver.py: extend the list of terminal-specific workarounds 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
712bbf00ec fish_key_reader: remove things that don't belong in the builtin
While at it, remove a redundant call to initialize_tty_metadata();
that's done by initial_query().
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
76d1e8d4da fish_key_reader: reuse isatty helper 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
2d457adfec builtin read: use a better type 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
6fdce59572 Extract function for setting shell modes
We do the same thing in several places, with lots of small differences.
Extract the most reasonable behavior and use it everywhere.  Note that
we had an explictly-motivated ENOTTY check; the motivating issues
doesn't seem to reproduce anymore here though I did not bisect yet.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
21150726d3 Remove confused redundant mutex lock 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
37a0919fee Also check isatty(0) before querying
A process like "fish -i <somefile ..."  probably shouldn't query
because it's not gonna work.

In future we could enable this by sending/receiving queries to/from
/dev/tty rather than stdout/stdin.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
7a14dd0b7f Be more consistent about when to query the TTY
We are more conservative with querying on startup than we are with
querying for cursor position.

Part of this is oversight (if startup querying is not done, we
basically never get into a position where we query for cursor position,
outside extreme edge cases).

Also, some specific scenarios where we query for cursor position
inside, say, Midnight Commander, are not actually broken, because that
only happens when Midnight Commander gives us control.  But let's
favor consistency for now; the Midnight Commander issue should be
fixed soon anyway.

Use the same logic in both cases.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
fb0e17d6ea tty_handoff: extract Midnight Commander workaround
A following commit wants to run the full initialize_tty_metadata()
only after querying XTVERSION.

But MC_TMPDIR needs to be checked before querying for XTVERSION.

Remove this cyclic dependency by extracting the MC_TMPDIR check.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
a6a38b78d6 Don't initialize interactive reader redundantly
Commands like

	fish -C 'read'

create two top-level readers one after the other.  The second one is
the fish REPL.

Both run some initialization of globals and parser variables.  This is
weird; it should not be necessary.

Let's call reader_interactive_init() only once.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
f5420b1110 Remove stale comment 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
90124c7889 Remove workaround for dvtm/abduco
dvtm and abduco are two terminal session managers with the same
original.

Among other issues, they fail to reply to primary device
attribute.  We have added a workaround for that based on
TERM=dvtm-256color (unreliable). A patch has been submitted for dvtm
https://lists.suckless.org/hackers/2502/19264.html

I don't know of a maintained fork (the original ones have had no
commit in 5 years) and there are better alternatives available
(shpool, tmux).  They have other VT100 compatibility issues as well
(accidental DECRST; something like "ls" Tab Tab Tab causes spurious
bold and underline markup).

Also, as of the parent commit, failure to respond to primary DA is
no longer catastrophic. So let's remove the workaround.  This means
that fish inside dvtm/abduco will pause for 2 seconds on startup and
print a warning (unless interrupted by ctrl-c).
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
7ef4e7dfe7 Time out terminal queries after a while
Add a timeout of 2 seconds queries; if any query takes longer, warn
about that and reduce the timeout  so we stop blocking the UI.  This 2
second delay could also happen when network latency is momentarily
really high, so we might want relax this in future.

Note that this timeout is only triggered by a single uninterrupted
poll() (and measured from the start of poll(), which should happen
shortly after sending the query). Any polls interrupted by signals
or uvars/IO port before the timeout would be hit do not matter.
We could change this in future.

Closes #11108
Closes #11117
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
06ede39ec9 Degrade gracefully when failing to receive cursor position report
Follow up the cursor position report query with a primary device
attribute one.  When that one arrives, any cursor position response
must have arrived too. This allows us to prevent a hang on terminals
that only support primary device attribute.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
1612576d1c Restructure query response handling logic
Instead of switching only on the response type, switch on the
combination of that and the expected response.  This helps the
following commits, which add more combinations (due to following up
cursor position report with a primary DA, and adding a timeout). No
behavior change here.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
2260465ed7 Rename enum variants to remove a name clash 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
3bd296ae3d Reuse variable in next_input_event() 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
064a45635c Document inter-dependencies between optional terminal features
- document that we currently require "cursor position report" if
  either of both click_events or XTGETTCAP+indn is implemented.
  One of the following patches will remove this requirement.
- document properly that scrollback-push currently only works
  when XTGETTCAP+indn is implemented. There are still a few terminals
  that don't support SCROLL UP, for example the Linux Console,
  and there is no better way to find out if it's supported.
2025-09-24 15:51:32 +02:00