Commit Graph

824 Commits

Author SHA1 Message Date
Johannes Altmanninger
04c9134275 Limit command line rendering to $LINES lines
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
Render the command line buffer only until the last line we can fit
on the screen.

If the cursor pushes the viewport such that neither the prompt nor
the first line of the command line buffer are visible, then we are
"scrolled". In this case we need to make sure to erase any leftover
prompt, so add a hack to disable the "shared_prefix" optimization
that tries to minimize redraws.

Down-arrow scrolls down only when on the last line, and up-arrow always
scrolls up as much as possible.  This is somewhat unconventional;
probably we should change the up-arrow behavior but I guess it's a
good idea to show the prompt whenever possible.  In future we could
solve that in a different way: we could keep the prompt visible even
if we're scrolled. This would work well because at least the left
prompt lives in a different column from the command line buffer.
However this assumption breaks when the first line in the command
line buffer is soft-wrapped, so keep this approach for now.

Note that we're still broken when complete-and-search or history-pager
try to draw a pager on top of an overfull screen.  Will try to fix
this later.

Closes #7296
2024-10-25 17:35:42 +02:00
Johannes Altmanninger
2dbaf10c36 Also refresh TTY timestamps after external commands from bindings
Commit ba67d20b7 (Refresh TTY timestamps after nextd/prevd, 2024-10-13)
wasn't quite right because it also needs to fix it for arbitrary commands.

While at it, do this only when needed:
1. It seems to be only relevant for multiline prompts.
   Note that we can wait until after evaluation to check if the prompt is
   multiline, because repaint events go through the queue, see 5ba21cd29
   (Send repaint requests through the input queue again, 2024-04-19).
2. When the binding doesn't execute any external command, we probably don't
   need to fix up whatever the user printed. If they actually wanted to show
   output and print another prompt, they should currently use  "__fish_echo",
   to properly support multiline prompts. Bindings should produce no other
   output. What distinguishes external programs is that they can trigger this
   issue even if they don't  produce any output that remains visible in fish,
   namely by using the terminal's alternate screen.
   Would be nice if we could get rid of __fish_echo; I'm not yet sure how.

Fixes #10800
2024-10-21 12:13:00 +02:00
Johannes Altmanninger
cd541575b4 Fix completion failing on unclosed brace with wildcard
Completion on ": {*," used to work but nowadays our attempt to wildcard-expand
it fails with a syntax error and we do nothing.  This behavior probably only
makes sense for the overflow case, so do that.
2024-10-19 22:04:54 +02:00
Johannes Altmanninger
00875d0f83 Allow builtin source to read from non-regular files
Commit a91bf6d88 (builtin.c: builtin_source now checks that its argument is
a file., 2005-12-16) fixed an infinite loop for commands like "source /"
where the argument is a directory.

It did so by erroring out early unless the filename argument is a regular file.
This is too restrictive; it disallows reading from special files like /dev/null
and fifos.
Today we get a sensible error without this check, so remove it.
2024-10-13 10:44:38 +02:00
Johannes Altmanninger
ba67d20b7c Refresh TTY timestamps after nextd/prevd
This fixes a macOS-specific bug.  See 390b40e02 (Fix regression not refreshing
TTY timestamps after external command from binding, 2024-05-29) and 8a7c3ceec
(Don't abandon line after writing control sequences, 2024-04-06).

Fixes #10779
2024-10-13 08:17:22 +02:00
Johannes Altmanninger
3a02a3bd6c Fix tmux-multiline-prompt test on some systems
The fast input would race with tmux redrawing the screen,
so sometimes the ": 5" is rendered twice.
2024-10-13 08:17:22 +02:00
Johannes Altmanninger
24e7a2ca60 Disable tmux OSC 133 prompt marking test also on cirrus' old alpine
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
tmux -V prints "tmux next-3.4" there.
2024-10-12 21:05:27 +02:00
Johannes Altmanninger
f77153e6c8 Disable tmux OSC 133 prompt marking test for some tmux versions < 3.4
OSC 133 was added to tmux 3.4.

Also fix the test on macOS where we do have 3.5a in CI; for some reason we
get copy_cursor_y=6 there.  I didn't investigate yet but at least that's
not the same bug this test was made to fix.
2024-10-12 19:48:26 +02:00
Johannes Altmanninger
5496247344 Avoid erasing OSC 133 prompt start marker with clr_eol
For multi-line prompts, we start each leading line with a clr_eol.  Immediately
before printing these prompt lines we emit the OSC 133 prompt start marker.
Some terminals such as tmux interpret make clr_eol delete such markers,
hence prompt navigation is broken.

Fix this by printing the marker only after clr_eol.

The scenario where this triggers is quite odd.  I haven't looked into why
the problem doesn't exist if I remove the recursive repaint request.

See https://github.com/tmux/tmux/issues/4183
Closes #10776
2024-10-12 19:00:16 +02:00
Fabian Boehm
5e8adb18f4 complete: Sort --keep-order completions smaller
This should make the sort have a strict weak ordering, which rust
requires since 1.81 (or it will panic).

Note: This changes the order, but that's *fine* since the current
order is random weirdness anyway.

Fixes #10763
2024-10-05 13:53:02 +02:00
Fabian Boehm
cdcf460edf math: Nicer error for non-ascii-lowercase identifiers
This gave a weird error when you did e.g. `math Foo / 6`:

"Missing Operator" and only the "F" marked.

Adding an operator here anywhere won't help, so calling this an
"Unknown function" is closer to the truth. We also get nicer markings
because we know the extent of the identifier.
2024-09-18 22:27:00 +02:00
Fabian Boehm
e27f4a3744 fish_indent: Truncate file to the size of the text
This can happen in case the formatted script is shorter, e.g. because
we ditched superfluous quotes.

Fixes #10724
2024-09-16 21:08:53 +02:00
Johannes Altmanninger
5918bca1eb Make "complete -e" prevent completion autoloading
We do the same for functions.

Closes #6716
2024-08-24 08:30:52 +02:00
Fabian Boehm
a4cc9c6975 Skip cd-without-read tests on NetBSD 2024-08-15 17:38:04 +02:00
Fabian Boehm
bd5f9babd7 __fish_seen_subcommand_from: Fix error when there's no second token
Regression from 2bfa7db7bc

Can be triggered e.g. with `complete -C"history "`.
2024-08-08 21:20:07 +02:00
Johannes Altmanninger
3984725b80 Fix tmux-complete test for old tmux versions
The CentOS Stream image I used provided tmux 2.7 which doesn't know about the
"Delete" alias.
2024-08-05 10:41:17 +02:00
Johannes Altmanninger
615b413335 Mention in changelog that universal notifiers are not yet supported on BSD 2024-08-05 10:41:17 +02:00
Xiretza
fd006e02da Fix cd .. to the root directory
The leading slash always needs to be present, even if there aren't any other
components. This was introduced by the Rust port.
2024-07-29 10:23:29 -07:00
Johannes Altmanninger
c3cf3792f3 Expand tilde after brace expansion
Fixes #10610
2024-07-23 11:47:58 +02:00
Mahmoud Al-Qudsi
fe63775ec5 string: Also escape new lines with --style=regex
This isn't *required* in the PCRE2 spec but it greatly increases the utility of
escaped regex strings at the commandline.
2024-07-16 17:05:11 -05:00
Mahmoud Al-Qudsi
8b7597913e Add tests for string match/replace --max-matches 2024-06-30 17:51:50 -05:00
Mahmoud Al-Qudsi
b5f5fa98bf Fix __fish_describe_command integration test under macOS
__fish_apropos is a huge hack under macOS and it seems that it's either broken
or man pages are missing/not indexed under CI. In all cases, hard-code the
results of __fish_describe_command to test the integration machinery
specifically and get the test to pass under macOS CI.
2024-06-27 21:35:06 -05:00
Mahmoud Al-Qudsi
dd7d537d90 Add regression test for command completion descriptions 2024-06-27 20:45:38 -05:00
Looouiiis
480d48351c feat(math): add round options (#9117)
Add round options, but I think can also add floor, ceiling, etc. And
the default mode is trunc.

Closes #9117

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2024-06-23 17:45:52 -05:00
Mahmoud Al-Qudsi
7d1942a023 Add reduced-accuracy variants of some math tests under x86
Due to the inherent floating point accuracy issues under i586 described
in #10474 and at https://github.com/rust-lang/rust/issues/114479, we need to add
a workaround to our littlecheck math tests to perform less stringent comparisons
when fish was built for x86 without SSE2 support.

This commit addresses the littlecheck issues that caused #10474 to be re-opened,
but I still have to reproduce the cargo test failures for
`negative_precision_width`, `test_float`, `test_float_g`, and `test_locale`.
2024-06-23 16:14:02 -05:00
Fabian Boehm
04da7043a6 tests: Remove skipped tests hack for Cmake < 3.9.0
We require 3.19

This also makes skipped tests visible, which showed that the
print-help test was never run because the REQUIRES line was off.

In sh-mode, bash's `command -v` returns true if *all* commands exist.
2024-06-11 16:55:11 +02:00
Fabian Boehm
f59cdfaa8d fish_add_path: Be more informative in verbose mode
One issue with fish_add_path at the moment is that it is sometimes a bit too intransparent.

You'll try to add a path, but it won't appear - was that because it wasn't a directory,
or because it doesn't exist, or because it was already included?

If it isn't usable after, did fish_add_path not add it because of something or did something *else* remove it?

So we give more explanations - "skipping this because it's a file", "not setting anything because no paths are left to add", ...
2024-06-06 16:47:39 +02:00
Mahmoud Al-Qudsi
a3e0d64e88 Remove usage of env -u
`env -u` is not supported on all platforms we support (e.g. macOS/OS X 10.10).
We don't need these variables erased, blanked works just fine.
2024-05-30 12:14:43 -05:00
Mahmoud Al-Qudsi
4b840075f4 Patch cd.fish test to support older macOS versions
The sysctl kern.osproductversion is not available on the oldest versions
we support.
2024-05-30 12:14:43 -05:00
Mahmoud Al-Qudsi
f84b1993ec Add path basename -E tests 2024-05-26 22:06:11 -05:00
Fabian Boehm
2c3894993f Remove errant profiling enabling
This enabled the profile in fish_setlocale, which caused startup
profile to always be on, so

```fish
fish --profile file -c 'foo'
```

would show the entire startup as well
2024-05-26 10:32:28 +02:00
Fabian Boehm
d5101e1923 set: Put back zero-index error instead of crashing
This was missed in the initial port in 77aeb6a2a8.
2024-05-25 21:32:40 +02:00
Fabian Boehm
bf9e5583ba Push and pop for-block every run through the loop
We do the same in while loops. This clears the local variables every time.

Fixes #10525
2024-05-25 13:20:05 +02:00
Johannes Altmanninger
2fa98ec20c Fix deadlock when importing universal LC_* variable
The C++ version of this code simply copied the entire uvar table.
Today we take a reference. It's not clear which one is better.

Removal of locale variables like LC_ALL triggers variable change handlers
which call EnvStackImpl::get. This deadlocks because we still hold the lock
to protect the reference to all uvars.  Work around this.

Closes #10513
2024-05-21 23:11:06 +02:00
Fabian Boehm
f1e19884fb Add set --no-event
This allows running `set` without triggering any event handlers.

That is useful, for example, if you want to set a variable in an event
handler for that variable - we could do it, for example, in the
fish_user_path or fish_key_bindings handlers.

This is something the `block` builtin was supposed to be for, but it
never really worked because it only allows suppressing the event for
the duration, they would fire later. See #9030.

Because it is possible to abuse this, we only have a long-option so
that people see what is up.
2024-05-14 17:31:47 +02:00
Johannes Altmanninger
a19ff4989a Prevent out-of-order execution following repaint
Commit a583fe723 ("commandline -f foo" to skip queue and execute immediately,
2024-04-08) fixed the execution order of some bindings but was partially
backed out in 5ba21cd29 (Send repaint requests through the input queue again,
2024-04-19) because repainting outside toplevel yields surprising results
(wrong $status etc).

Transient prompts wants to first repaint and then execute some more readline
commands, all within a single binding.  This was broken by the second commit
because that one defers the repaint until after the binding has finished.

Work around this problem by deferring input events again while a readline
event was queued. This is closest to the historical behavior.

The implementation feels hacky; we might find odd situations.
For example,

    commandline -f repaint end-of-line
    set token (commandline -t)

sets the wrong token.
Probably not a very important case. We could throw an error or make it work
by letting "commandline -t" drain the input queue.

That seems too complicated, better change repaints to not use the input queue
(and fake $status etc). Let's try to do that in future.

Closes #10492
2024-05-13 10:44:12 +02:00
ridiculousfish
32ba8d93af Disable cd-without-permission test on macOS < 12
This allows the tests to pass on older macOS, before O_SEARCH was introduced.
2024-05-11 13:20:34 -07:00
Jonathan Krebs
4eb0dd623d add testcase for cd without read permission 2024-05-11 11:12:29 -07:00
Fabian Boehm
37f0d7c522 Work around more spurious test failures 2024-05-07 17:55:29 +02:00
Fabian Boehm
2a121ef1aa function: Check if --argument-names gets a valid variable name
These were accepted but then ineffective because the only way these
are used is to set a variable.
2024-05-06 17:00:45 +02:00
Fabian Boehm
39b996332e functions: Fix --argument-names display
Mentioned in #10465
2024-05-06 17:00:45 +02:00
Johannes Altmanninger
4e816212a1 Check for unsupported "time &" in the proper place
This means we can detect this error also for simple blocks.

While at it do some cleanup in the area.
2024-05-03 09:37:56 +02:00
Johannes Altmanninger
d4ecea56df Fix regression spuriously expanding abbr with cursor outside token
Given "abbr foo something", the input sequence

    foo<space><ctrl-z><space>

would re-expand the abbreviation on the second space which is surprising
because the cursor is not at or inside the command token.  This looks to be
a regression from 00432df42 (Trigger abbreviations after inserting process
separators, 2024-04-13)

Happily, 69583f303 (Allow restricting abbreviations to specific commands
(#10452), 2024-04-24) made some changes that mean the bad commit seems no
longer necessary. Not sure why it works but I'll take it.
2024-05-03 08:39:05 +02:00
Johannes Altmanninger
b00899179f Don't indent multi-line quoted strings; do indent inside ()
On a command with multiline quoted string like

    begin
        echo "line1
    line2"
    end

we actually indent line2 which seeems misleading because the indentation
changes the behavior when typed into a script.

This has become more prominent since commits
- a37629f86 (fish_clipboard_copy: indent multiline commands, 2024-04-13)
- 611a0572b (builtins type/functions: indent interactively-defined functions, 2024-04-12)
- 222673f33 (edit_command_buffer: send indented commandline to editor, 2024-04-12)

which add indentation to an exported commandline.

Never indent quoted strings, to make sure the rendering matches the semantics.
Note that we do need to indent the opening quote which is fine because
it's on the same line.

While at it, indent command substitutions recursively.  That feature should
also be added to fish_indent's formatting mode (which is the default).
Fortunately the formatting mode already works fine with quoted strings;
it does not indent them. Not sure how that's done and whether indentation
can use the same logic.
2024-04-30 14:12:48 +02:00
Johannes Altmanninger
dfd08a1a2c Run fish_indent on checks/expansion.fish 2024-04-30 14:00:06 +02:00
Johannes Altmanninger
5152f6534d Fix test_functions.fish for Ubuntu Noble Numbat Docker build
vared.fish is installed at
/home/fishuser/fish-build/test/buildroot/usr/local/share/fish/functions/vared.fish
as oppposed to being sourced from share/functions/.

I'm not 100% sure why this happens but it doesn't seem wrong.
2024-04-28 10:38:26 +02:00
Johannes Altmanninger
52ef919aee Require mandoc/nroff for print-help test
Ubuntu Noble Numbat doesn't install this by default.
2024-04-28 10:38:26 +02:00
Johannes Altmanninger
fb99edae92 Stop using comma from command substitution in brace expansion
Fixes #5048
2024-04-26 18:15:47 +02:00
Fabian Boehm
7ec715ba8b tests: Fix noshebang test
This was silently skipped because of a broken REQUIRES line

(it would be great if our test runner could surface skipped tests)
2024-04-25 21:52:56 +02:00
Fabian Boehm
691acfc28d tests: Disable some slow tests under ASAN
These take over two minutes under ASAN (like ~40 seconds without, so
they aren't quick to begin with), and don't really give any additional
insight.

So we skip them to save time
2024-04-25 21:52:13 +02:00