Commit Graph

5522 Commits

Author SHA1 Message Date
Johannes Altmanninger
4336f9df7f fish_key_reader: stop emitting \b for ctrl-h
This is just too confusing; \b sounds like it would map backspace but it's
actually just ctrl-h.  Backspace is a different key ("bind backspace"),
so let's move away from \b.

Reproduce by typing ctrl-h in fish_key_reader, or, for even more confusion,
use a terminal like tmux and type ctrl-backspace which also sends ctrl-h.

I've thought about changing \b (and its aliases like \ch and \x08) to mean
backspace but that seems like unnecessary breakage, since they all already
mean ctrl-h, and can usually be mapped independent of backspace.

See the discussion in #10738
2024-09-23 20:00:35 +02:00
Peter Ammon
e3993a3d96
Update code and Cargo.toml for recent pcre2-utf32 changes 2024-09-22 17:05:14 -07:00
Peter Ammon
617b61cd3a
Clean up fd_monitor getter
No need for UnsafeCell
2024-09-22 14:02:55 -07:00
Peter Ammon
fb700ca50d
Clean up a few more comments 2024-09-22 13:11:40 -07:00
Peter Ammon
f733553ac8
Clean up some stale comments 2024-09-22 13:09:11 -07:00
Peter Ammon
974ad882fa
Clean up fish-printf in preparation for publishing
Make fish-printf no longer depend on the widestring crate, as other clients
won't use it; instead this is an optional feature.

Make format strings a generic type, so that both narrow and wide strings can
serve. This removes a lot of the complexity around converting from narrow to
wide.

Add a README.md to this crate.
2024-09-21 17:52:11 -07: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
Johannes Altmanninger
add0a9dfcd fish_indent: clean up file writing logic
Fix 7308dbc7a (fish_indent: Prevent overwriting file with identical content,
2024-07-21) in a different way by passing O_TRUNC again.
If we don't want regressions we could use code review.
2024-09-16 21:27:11 +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
1e2368f609 Fix off-by-one-error parsing \e\e prefixed sequences
Closes #10721
2024-09-14 22:56:37 +02:00
Peter Ammon
8f3a034264
History to store old item offsets in Vec and not VecDeque
We used deque in C++ because this vector may be large, and so it avoids
repeated re-allocations. But VecDeque is different in Rust - it's contiguous -
so there's no benefit. Just use Vec.
2024-09-14 13:26:34 -07:00
Peter Ammon
7ac62bbca4
Remove a redundant "unsafe" specifier 2024-09-14 13:15:21 -07:00
Johannes Altmanninger
5432ee1aa9 Relax history autosuggestion and highlighting if cd is wrapped
For implementation reasons, we special-case cd in several ways
1. it gets different completions (handle_as_special_cd)
2. when highlighting, we honor CDPATH
3. we discard autosuggestions from history that don't have valid path arguments

There are some third-party tools like zoxide that redefine cd ("function cd
--wraps ...; ...; end"). We can't support this in general but let's try to
make an effort.

zoxide tries to be a superset of cd, so special case 1 is still
valid but 2 and 3 are not, because zoxide accepts some paths
that cd doesn't accept.

Let's add a hack to detect when "cd" actually means something else by checking
if there is any --wraps argument.

A cleaner solution is definitely possible but more effort.

Closes #10719
2024-09-14 08:51:42 +02:00
Kaley Main
a979b6341d Create a test that reproduces fish-shell/fish-shell#10703 2024-09-06 16:41:10 +02:00
Johannes Altmanninger
f8a720da8c Fix wildcard expansion doubling up "*/"
In some cases we add the wildcard twice.

    $ fish -c '../jj; complete -C"ls cli/*/conf/tem"'
    cli/*/*/config/templates.toml

Fix that. Test in the next commit.

There seems to be another bug in 3.7.1 where we fail to apply this completion
to the command line. This appears fixed. (FWIW we might want to revert
the quoting change in completion_apply_to_command_line(), maybe that one
accidentally fix this).

Fixes #10703
2024-09-06 16:41:10 +02:00
Johannes Altmanninger
77b2dcb462 Fix ctrl-c being ignored during builtin wait
Same as d21ed0fb2 (Disable terminal protocols before expanding wildcards,
2024-07-31).

Also mention a related issue in the changelog.
2024-09-01 14:08:01 +02:00
Johannes Altmanninger
15b08cbcab Make import style less noisy 2024-09-01 14:05:48 +02:00
Mahmoud Al-Qudsi
50a6dfd10d Replace a HashMap w/ a BTreeMap
The HashMap is used to generate the __fish_describe_command integration
completions. Given the nature of the allocations and the numbers that we use, a
BTreeMap would theoretically perform better. Benchmarks show a 2-9%
improvement in completion times consistently in favor of BTreeMap.
2024-08-31 14:13:41 -05:00
Mahmoud Al-Qudsi
73908f1218 fish_test_helper: Fix warnings about intentionally unused results
Warnings were appearing under GCC 13.2

(void) alone is insufficient under modern compilers, workaround with logical
negation taken from GCC bug tracker.
2024-08-31 13:16:51 -05:00
Mahmoud Al-Qudsi
ef6577db25 Update threads::thread_id() documentation 2024-08-31 12:57:13 -05:00
Mahmoud Al-Qudsi
c6bbacc703 Catch tls issues caused by linker bug
Worth including because mold is rather popular in the rust world and because the
bug affects mold versions coincident with the development of the fish rust port.

The bug affects all currently released versions of mold from 2.30.0 (Mar 2024)
onwards under at least FreeBSD (though quite likely other platforms as well).

See https://github.com/rui314/mold/issues/1338 for reference.
2024-08-31 12:48:15 -05:00
Mahmoud Al-Qudsi
5278259312 Don't break out of panic handler
The previous control flow logic wasn't sound and would leave the shell in a hung
state when `break` would be encountered.

The behavior is now straightforward, the shell reads until <Enter> or <q> is
pressed, at which point it aborts.
2024-08-28 17:38:05 -05:00
Mahmoud Al-Qudsi
4d0aa2b5dd Fix panic handler
It wasn't actually exiting and would basically block indefinitely after reading
from stdin.
2024-08-28 17:29:56 -05:00
Fabian Boehm
7b7d16da48 Revert libc time_t changes
This was based on a misunderstanding.

On musl, 64-bit time_t on 32-bit architectures was introduced in version 1.2.0,
by introducing new symbols. The old symbols still exist, to allow programs compiled against older versions
to keep running on 1.2.0+, preserving ABI-compatibility. (see musl commit 38143339646a4ccce8afe298c34467767c899f51)

Programs compiled against 1.2.0+ will get the new symbols, and will therefore think time_t is 64-bit.

Unfortunately, rust's libc crate uses its own definition of these types, and does not check for musl version.
Currently, it includes the pre-1.2.0 32-bit type.

That means:

- If you run on a 32-bit system like i686
- ... and compile against a C-library other than libc
- ... and pass it a time_t-containing struct like timespec or stat

... you need to arrange for that library to be built against musl <1.2.0.

Or, as https://github.com/ericonr/rust-time64 says:

> Therefore, for "old" 32-bit targets (riscv32 is supposed to default to time64),
> any Rust code that interacts with C code built on musl after 1.2.0,
> using types based on time_t (arguably, the main ones are struct timespec and struct stat) in their interface,
> will be completely miscompiled.

However, while fish runs on i686 and compiles against pcre2, we do not pass pcre2 a time_t.
Our only uses of time_t are confined to interactions with libc, in which case with musl we would simply use the legacy ABI.

I have compiled an i686 fish against musl to confirm and can find no issue.

This reverts commit 55196ee2a0.
This reverts commit 4992f88966.
This reverts commit 46c8ba2c9f.
This reverts commit 3a9b4149da.
This reverts commit 5f9e9cbe74.
This reverts commit 338579b78c.
This reverts commit d19e5508d7.
This reverts commit b64045dc18.

Closes #10634
2024-08-27 14:28:00 +02:00
Mahmoud Al-Qudsi
46c1f0e338
Add kqueue-based uvar notifier for BSD (#10674)
Add kqueue-based uvar notifier for BSD

Tested under FreeBSD 13.3.

This also works under all versions of macOS, and has some
benefits over the current notifyd choice.

Mutex is used because of the non-mut `notification_fd_became_readable()` `&self`
reference, but contention is not expected.
2024-08-26 17:10:26 -05:00
Peter Ammon
91ffa8ab48
Revert "Resume repainting command line when colors change"
This reverts commit 313bd558da.

Per discussion in 313bd558da
2024-08-25 18:41:31 -07:00
Peter Ammon
313bd558da
Resume repainting command line when colors change
This restores a hack to trigger a command line repaint when "$fish_color_*" or
"$fish_pager_color_*" changes. These allow the command line to react immediately
to changes in other sessions or web_config.

This was removed in ff62d172e5 but there does not
appear to be a handler which actually redraws these.

Revert of ff62d172e5
2024-08-24 15:02:14 -07: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
Mahmoud Al-Qudsi
f3d59abc46 Remove unnecessary reference 2024-08-20 14:48:59 -05:00
Mahmoud Al-Qudsi
6c37103b7c unescape_yaml_fish_2_0: Remove MaybeUninit::assume_init()
The generated assembly is more or less the same and the previously generated
version had been manually verified, but this PR removes the usage of
`MaybeUninit::assume_init()` and replaces it with direct pointer writes.

This should result in no observable change: it continues to pass the functional
tests and benchmarks identically. The safety of the new code has been verified
with Miri.

[0]: https://github.com/mqudsi/fish-yaml-unescape-benchmark
2024-08-20 14:27:59 -05:00
Johannes Altmanninger
31896534a0 Correct iTerm2 version in CSI u workaround
The 3.5.4 release does not include the fix, presumably the next one then.

See #10653
2024-08-17 07:43:18 +02:00
Fabian Boehm
8612d34996 Remove useless osttr->cstr->osstr roundtrip 2024-08-16 15:30:57 +02:00
Johannes Altmanninger
e4bcee2727 Revert "Decode arrow keys as sent by urxvt"
This does not work as-is ("CSI a" is shift-up, not up).
I'm not sure if we want to implement these.
It's not a regression so there is no pressure.

This reverts commit 350598cb99.
2024-08-14 15:43:54 +02:00
Johannes Altmanninger
fcf7cd81cf Parse no more than one \e prefix as alt modifier 2024-08-14 15:16:14 +02:00
Johannes Altmanninger
53ea6db72d Show un-decodable inputs as bytes instead of the internal encoding
When the input is invalid UTF8, we re-encode the raw bytes using the private
use area. Let's make sure we convert back before printing.
2024-08-14 15:16:14 +02:00
Johannes Altmanninger
182f8948b8 Remove unused function 2024-08-14 15:16:14 +02:00
Johannes Altmanninger
b8e280add6 Clean up fish_key_reader rendering code 2024-08-14 15:16:14 +02:00
Fabian Boehm
357eb3cd32 fish_key_reader: use char_to_symbol for verbose output
byte_to_symbol was broken because it didn't iterate by byte, it
iterated by rust-char, which is a codepoint.

So it failed for everything outside of ascii and, because of a
mistaken bound, ascii chars from 0x21 to 0x2F ("!" to "/" - all the punctuation).

char_to_symbol will print printable codepoints as-is and
others escaped. This is okay - something like `decoded from: +` or
`decoded from: ö` is entirely understandable, there is no need to tell
you that "ö" is \xc3\xb6.

This reverts commit 423e5f6c03.
2024-08-13 16:03:47 +02:00
Johannes Altmanninger
423e5f6c03 Fix fish_key_reader --verbose output 2024-08-11 15:16:03 +02:00
Fabian Boehm
e3196446fa Fix crash in ctrl_to_symbol
Array starts at 0, goes up to 27, that's 28 entries... *BUT* we also
need the catch-all entry after, so it's 29.

To be honest there's got to be a better way to write this.
2024-08-11 14:57:04 +02:00
Fabian Boehm
9903eb4c76 Convert ASCII DEL to \x7f
Annoying when you press backspace in fish_key_reader
2024-08-11 14:57:04 +02:00
hdhoang
7682abb703 Import portable_atomic::AtomicU64 when std does not provide it
Restores support for 32-bit powerpc and mips. Fixes #10415.

Signed-off-by: Hoang Duc Hieu <code@hdhoang.space>
2024-08-11 14:50:39 +02:00
Johannes Altmanninger
ebd23c9f86 Add back fish_key_reader --verbose
See #10663
2024-08-11 14:41:17 +02:00
Johannes Altmanninger
ba3683cfa5 Disable keyboard protocols on WezTerm
WezTerm supports CSI u but unfortunately, typing single quote on a German
keyboard makes WezTerm send what gets decoded as `shift-'`.

This is bad, so disable it until this is fixed.  In future we should maybe
add a runtime option to allow the user to override this decision.

See #10663
2024-08-11 14:12:28 +02:00
Johannes Altmanninger
ff476eff2d Read \e prefix for escape sequences as alt modifier
The \e\e\[A style is bad but iTerm and putty (alt-left) use it.

The main motivation for this change is to improve fish_key_reader output.

Part of #10663
2024-08-11 11:31:13 +02:00
Johannes Altmanninger
d32825ba57 Decode formatOtherKeys=0 format (XTerm default) too
Part of #10663
2024-08-11 11:31:13 +02:00
Peter Ammon
2b40c6364e
Mark some functions as potentially unused
Fixes warnings on macOS
2024-08-10 17:36:56 -07:00
Johannes Altmanninger
4664a0b52f Limit iTerm2 CSI u workaround to iTerm<=3.5.3
Looks like 3.5.4 will include
9cd0241afd
so the need for the workaround is gone.

See #10653
2024-08-10 08:17:35 +02:00
Dezhi Wu
09b8b94025 Remove unnecessary unsafe block
The `unsafe` is not needed here, as the `select64` is already a safe wrapper
around the `C_select64` function.

Closes #10659
2024-08-10 07:16:04 +02:00
Johannes Altmanninger
5f9e9cbe74 Replace clock_gettime/futimens with 64-bit wrappers
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
c1fba4663b Replace nanosleep with stdlib wrapper (which is still broken)
As of rust 1.78, the Unix stdlib implementation is affected by the same issue:

    pub fn sleep(dur: Duration) {
        let mut secs = dur.as_secs();
        let mut nsecs = dur.subsec_nanos() as _;

        // If we're awoken with a signal then the return value will be -1 and
        // nanosleep will fill in `ts` with the remaining time.
        unsafe {
            while secs > 0 || nsecs > 0 {
                let mut ts = libc::timespec {
                    tv_sec: cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t,
                    tv_nsec: nsecs,
                };
                secs -= ts.tv_sec as u64;
                let ts_ptr = core::ptr::addr_of_mut!(ts);
                if libc::nanosleep(ts_ptr, ts_ptr) == -1 {
                    assert_eq!(os::errno(), libc::EINTR);
                    secs += ts.tv_sec as u64;
                    nsecs = ts.tv_nsec;
                } else {
                    nsecs = 0;
                }
            }
        }
    }

Note that there is a small behavior change here -- sleep() will continue
after signals; I'm not sure if we want that but it seems harmless?

Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
55196ee2a0 Replace pselect with a 64-bit-time_t wrapper
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
4992f88966 Replace getrusage with a 64-bit-time_t wrapper
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
46c8ba2c9f Replace select with a 64-bit-time_t wrapper
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
3a9b4149da Replace localtime_r with a 64-bit-time_t wrapper
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
70357c4f6e Add back .clang-format 2024-08-07 13:11:22 +02:00
Johannes Altmanninger
338579b78c Rename fstatat/readdir wrapper to match Linux equivalents 2024-08-07 13:11:22 +02:00
Johannes Altmanninger
d19e5508d7 Remove non-portable use of fstatat
Part of #10634
2024-08-06 14:16:01 +02:00
Johannes Altmanninger
0705446e6e Remove non-portable use of stat
Part of #10634
2024-08-06 14:16:01 +02:00
Johannes Altmanninger
ff47c2c628 Remove non-portable use of fstat
Part of #10634
2024-08-06 14:15:57 +02:00
Johannes Altmanninger
b64045dc18 Remove non-portable use of ino_t
Part of #10634
2024-08-06 14:15:03 +02:00
Johannes Altmanninger
fa4daeee0f Address clippy lint 2024-08-06 14:15:03 +02:00
Johannes Altmanninger
8fbe29ed7b Remove dead code 2024-08-06 14:15:03 +02:00
Johannes Altmanninger
7cfc6297bc Hack to make alt-{left,right} work again in iTerm2
iTerm2 deviates from protocol, so back out c3c832761 (Stop using stack for
kitty progressive enhancement, 2024-08-03) in that case.

Note that we use several ways of detecting iTerm2 (ITERM_PROFILE,
TERM_PROGRAM=iTerm.app, ITERM_SESSION_ID).
LC_TERMINAL seems superior because it works over ssh.

This new one should hopefully go away eventually.
2024-08-06 10:36:36 +02:00
Peter Ammon
1c38677db0
Minor cleanup of path_normalize_for_cd 2024-08-03 12:27:05 -07:00
Johannes Altmanninger
c3c8327610 Stop using stack for kitty progressive enhancement
Today fish pushes/pops kitty progressive enhancements everytime control is
transfered to/from fish. This constitutes a regression relative to 3.7.1:

    $ fish
    $ ssh somehost fish
    (network disconnect, now we missed our chance to pop from the stack)
    $ bash # or some ncurses application etc
    (keyboard shortcuts like ctrl-p are broken)

When invoking bash, we pop one entry off the stack but there is another one.
There seems to be a simple solution: don't use the stack but always reset
the current set of flags.  Do that since I did not find a strong use case
for using the stack[1] (Note that it was recommended by terminal developers
to use the stack, so I might be wrong).

Note that there is still a regression if the outer shell is bash.

[1]: https://github.com/kovidgoyal/kitty/issues/7603#issuecomment-2256949384

Closes #10603
2024-08-03 17:51:48 +02:00
Amos Bird
041a26f647 Update TTY modes for external commands only after successful command
According to the discussion in #2315, we adopt TTY modes for external commands
mainly for "stty".  If our child process crashes (or SSH disconnect), we
might get weird modes. Let's ignore the modes in the failure case.

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>

Part of #10603
2024-08-03 17:51:48 +02:00
Johannes Altmanninger
e25a1358e6 Work around broken rendering of pasted multibyte chars in non-UTF-8-ish locale
Run

    printf \Xf6 | wl-copy # ö in ISO-8859-1
    LANG=de_DE LC_ALL=$LANG gnome-terminal -- build/fish

and press ctrl-v. The pasted data looks like this:

    $ set data (wl-paste -n 2>/dev/null | string collect -N)
    $ set -S data
    $data: set in local scope, unexported, with 1 elements
    $data[1]: |\Xf6|

we pass $data directly to "commandline -i", which is supposed to insert it
into the commandline verbatim. What's actually inserted is "�".

This is because of all of:
1. We never decode "\Xf6 -> ö" in this scenario. Decoding it -- like we do
   for non-pasted keyboard input -- would fix the issue.
2. We've switched to using Rust's char, which, for better or worse, disallows
   code points that are not valid in Unicode (see b77d1d0e2 (Stop crashing
   on invalid Unicode input, 2024-02-27)). This means that we don't simply
   store \Xf6 as '\u{00f6}'. Instead we use our PUA encoding trick, making it
   \u{f6f6} internally.
3. Finally, b77d1d0e2 renders reserved codepoints (which includes PUA chars)
   using the replacement character � (sic).  This was deemed more
   user-friendly than printing an invalid character (which is probably not
   mapped to a glyph).  Yet it causes problems here: since we think that
   \u{f6f6} is garbage, we try to render the replacement character. Apparently
   that one is not defined(?) in ISO-8859-1; we get "�".

Fix this regression by removing the replacement character feature.

In future we should maybe decode pasted input instead. We could do that
lazily in "commandline -i", or eagerly in "set data (wl-paste ...)".
2024-08-03 11:32:59 +02:00
Johannes Altmanninger
d21ed0fb22 Disable terminal protocols before expanding wildcards
Commit 29f2da8d1 (Toggle terminal protocols lazily, 2024-05-16) made it so
the wildcard expansion in "echo **" (in a large directory tree) can't be
canceled with ctrl-c.  Fix this by disabling terminal protocols already at
expansion time (not waiting until execution).
2024-07-31 23:37:11 +02:00
Johannes Altmanninger
3be588569d Disable CSI u inside Midnight Commander for now
Using

    SHELL=$(command -v fish) mc

Midnight Commander will spawn a fish child with

    "function fish_prompt;"
    "echo \"$PWD\">&%d; fish_prompt_mc; kill -STOP %%self; end\n",

So fish_prompt will SIGSTOP itself using an uncatchable signal.

On ctrl-o, mc will send SIGCONT to give back control to the shell.
Another ctrl-o will be intercepted by mc to put the shell back to sleep.

Since mc wants to intercept at least ctrl-o -- also while fish is in control
-- we can't use the CSI u encoding until mc either understands that, or uses
a different way of passing control between mc and fish.

Let's disable it for now.

Note that mc still uses %self but we've added a feature flag
to disable that.  So if you use "set fish_features all"
you'll want to add a " no-remove-percent-self". A patch
to make mc use $fish_pid has been submitted upstream at
https://lists.midnight-commander.org/pipermail/mc-devel/2024-July/011226.html.

Closes #10640
2024-07-29 22:38:18 +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
Peter Ammon
3d816174fd
Wildcard tree walking to only rely on dev, inode to detect changes
When applying a wildcard, it's important to keep track of the files that have
been visited, to avoid symlink loops. Previously fish used a FileId for the
purpose. However FileId also includes richer information like modification time;
thus if a file is modified during wildcard expansion then fish may believe that
the file is different and visit it twice.

The richer information like modification time is important for atomic file
writes but should be ignored for wildcard expansion; just use the (dev, inode)
pair instead.

This also somewhat reduces our reliance on struct stat, but we still need it for
fstatat which Rust does not expose.
2024-07-28 09:48:24 -07:00
Peter Ammon
89794ccfdb
Adopt fstat in screen.rs 2024-07-27 18:58:35 -07:00
Peter Ammon
3dc3aed991
Adopt fstat in file_id_for_fd 2024-07-27 18:58:34 -07:00
Peter Ammon
1332d33025
Introduce fstat() and adopt it in reader
Begin to migrate to Rust "native" Metadata, as part of addressing #10634

This will be structured as a series of small commits to aid bisecting.
2024-07-27 18:49:46 -07:00
Peter Ammon
0651ca0d9b
Unify FileId structs
We had two of these! Just use one.
2024-07-27 18:48:51 -07:00
Johannes Altmanninger
c3cf3792f3 Expand tilde after brace expansion
Fixes #10610
2024-07-23 11:47:58 +02:00
Dezhi Wu
7308dbc7ad fish_indent: Prevent overwriting file with identical content
Fixes #10616
2024-07-21 18:57:48 +08: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
faf3b356f2 Add commandline --showing-suggestion
Returns 0 (true) in case an autosuggestion is currently being displayed.

This was first requested in #5000 then again in #10580 after the existing
workaround for this missing functionality was broken as part of a change to the
overall behavior of `commandline` (for the better).
2024-07-07 22:34:36 -05:00
Mahmoud Al-Qudsi
4730a04f25 Use NonZero types for 1-based line numbers
Since we have a mix of both 0-based and 1-based line numbers in the code base,
we can now distinguish between them by type alone. Also stop using 0 as a
placeholder value for "no line number available" except in explicit helper
functions such as `get_lineno_for_display()`.
2024-07-07 20:58:09 -05:00
Mahmoud Al-Qudsi
92cae9b576 Reduce size of Block to 32 bytes
Using a 32-bit integer to store the line number, as previously discussed.
2024-07-07 20:37:04 -05:00
Fabian Boehm
70242ce38c reader: Fix external modes again
Missed in the port
2024-07-03 20:39:25 +02:00
Mahmoud Al-Qudsi
93f8385448 Add option to speed up string match/replace with --max-matches
I've often needed a way to get the last bit of performance out of unwieldy
completions that involve a lot of string processing (apt completions come to
mind, and I ran into it just now with parsing man pages for kldload
completions).

Since many times we are looking for just one exact string in the haystack, an
easy optimization here is to introduce a way for `string match` or `string
replace` to early exit after a specific number of matches (typically one) have
been found.

Depending on the size of the input, this can be a huge boon. For example,
parsing the description from FreeBSD kernel module man pages with

    zcat /usr/share/man/man4/zfs.4.gz | string match -m1 '.Nd *'

runs 35% faster with -m1 than without, while processing all files under
/usr/share/man/man4/*.4.gz in a loop (so a mix of files ranging from very short
to moderately long) runs about 10% faster overall with -m1.
2024-06-30 17:51:50 -05:00
Peter Ammon
204663f1b8
Minor cleanup of apply_var_assignments
Simplify the function signature and calls sites.
2024-06-30 15:27:49 -07:00
Peter Ammon
b5fd8d697b
Minor refactor of completer perform_for_commandline 2024-06-30 13:59:22 -07:00
Nikita Bobko
67e190876a
Implement jump-till-matching-bracket input function
Part of #1842

It's like jump-to-matching-bracket, but jumps right before the bracket

I will use it to mimic vi 'ab' and 'ib' text objects in the next commit

Given complicated semantics of jump-till-matching-bracket, an alternative name
could be 'jump-inside-matching-brackets'. But that would make names non-symmetrical.
I'm not sure what is worse.
2024-06-30 11:58:10 -07:00
Nikita Bobko
f8ebe346a9
Implement jump-to-matching-bracket motion and bind % (percent) in vi mode
Part of #1842
2024-06-30 11:58:10 -07:00
Nikita Bobko
c966c19c56
Refactoring. Decompose ReaderData.jump function to two functions
Part of #1842

Split to:
- jump_and_remember_last_jump. What previously was called jump, now called
  jump_and_remember_last_jump
- jump. Only jump, don't remember last jump. Now it's also possible to pass
  vector of targets

The commit is pure refactoring, no functional changes are introduced.
The refactoring is needed for the next commits
2024-06-30 11:58:10 -07:00
Peter Ammon
1cbd18cc30
Tweak the allowed clippy set and fix some 2024-06-30 11:38:15 -07:00
Peter Ammon
90535d5b51
Allow clippy::ptr_arg and fix cases 2024-06-29 18:48:49 -07:00
Peter Ammon
cce2aab371
Rename binary_semaphore_t to BinarySemaphore 2024-06-29 18:07:11 -07:00
Peter Ammon
266852327f
Rename fd_readable_set_t to FdReadableSet 2024-06-29 18:06:21 -07:00
Peter Ammon
2d35d3f3c7
Remove yet more dead code 2024-06-29 18:03:52 -07:00
Peter Ammon
6b4dbf3b05
Remove additional dead code 2024-06-29 18:03:52 -07:00
Peter Ammon
1ed256d328
Remove RefCells from ExecutionContext and just make it mut
No more storing these in Parser; big simplification.
2024-06-29 18:03:52 -07:00
Peter Ammon
aa50e4f8c4
Remove some more dead code 2024-06-29 18:03:52 -07:00
Peter Ammon
606b668fff
Remove the pointer module
This is now unused.
2024-06-29 18:03:52 -07:00
Peter Ammon
c212ac95e9
Thread a reference to a line counter into parse execution
Simplify Parser by removing the reference to the execution context
2024-06-29 18:03:52 -07:00
Peter Ammon
b00ab4673b
Adopt the new line counting machinery in parse_execution 2024-06-29 18:03:52 -07:00
Peter Ammon
300fcfdba7
Factor out line counting
This moves the line counting logic from parse_execution into a new type, in
preparation for further refactoring.
2024-06-29 18:03:52 -07:00
Peter Ammon
ad1ea94405
Remove an Option from the parsed source ref in parse_execution
This was never None.
2024-06-29 18:03:52 -07:00
Peter Ammon
3aa12c1be9
Rename ParseExecutionContext to ExecutionContext 2024-06-29 18:03:52 -07:00
Mahmoud Al-Qudsi
0adebdfbc4 Fix completely broken __fish_describe_command integration
Command completion descriptions were not being generated from `apropos`. Well,
they were being generated but that was not being correctly used by fish core.

Not sure when this was broken, but there's a possibility it was during the rust
port.

In addition to simply not working, it seems the old code tried to avoid
allocations but String::split_at_mut() allocates a new string (since one
allocation from the global allocator can't be split into two allocations to be
freed separately). Use `String::as_mut_utfstr()` before splitting the &wstr
instead of splitting the &str to actually do this alloc-free.
2024-06-27 20:43:14 -05:00
Mahmoud Al-Qudsi
f711c874ce Fix broken __fish_bin_dir when running out of build directory
`exec_path` is the path to the `fish` binary itself. This would cause the shell
to try to execute /foo/bar/fish/fish, which would, of course, fail.
2024-06-26 19:01:57 -05:00
Johannes Altmanninger
90150e1729 fish_key_reader: enable terminal protocols again
Fixes 29f2da8d1 (Toggle terminal protocols lazily, 2024-05-16).
2024-06-25 19:55:24 +02:00
Peter Ammon
73c46db609
Remove some (hopefully) unnecessary clippy and compiler directives 2024-06-23 17:13:14 -07:00
Peter Ammon
d059bdb877
Bring topic monitor naming in line with Rust conventions 2024-06-23 17:06:20 -07:00
Peter Ammon
6163999ec7
Remove the ParserRef type
No need to pass around Rc any more.
2024-06-23 16:49:11 -07:00
Peter Ammon
4557d9fc09
Remove the notion of principal parser
The "principal" parser is the one and only today; in the future we hope to
have multiple parsers to execute fish script in parallel.

Having a globally accessible "principle" parser is suspicious; now we can
get rid of it.
2024-06-23 16:49:11 -07:00
Peter Ammon
631516398e
Remove the notion of the "principal" environment stack
The "principal" environment stack was the one that was associated with the
"principal" parser and would dispatch changes like to TZ, etc.

This was always very suspicious, as a global; now we can remove it.
2024-06-23 16:49:11 -07:00
Peter Ammon
dbf54f49ff
Remove principal_parser() from the last of the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
fd84dc4cdd
Remove principal_parser() from yet more of the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
2bd3bcf7fc
Remove principal_parser() from yet more of the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
0d7e8c22a6
Remove principal_parser() from yet more of the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
077f439283
Remove uses of EnvStack::principal() in the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
0e96a420d6
Remove a use of EnvStack::principal()
Try to get off of globals.
2024-06-23 16:49:11 -07:00
Peter Ammon
01d45ad755
Clarify a comment about safety in the environment impl
We use an unusual pattern of protecting data via a global lock, but it's safe.
2024-06-23 16:49:11 -07:00
Peter Ammon
0378cb750b
Be more explicit about when to dispatch variable changes
This controls e.g. when we react to TZ changes. Rather than having a special
blessed environment stack, simply store it as a property.
2024-06-23 16:49:11 -07:00
Peter Ammon
9ad875cdb7
Enforce that nobody can push/pop from the global environment stack
This is just a precaution.
2024-06-23 16:39:39 -07:00
Peter Ammon
7fcbe5b8ab
Thread variables into autoload_names
Stop fetching a global set of variables.
2024-06-23 16:39:39 -07:00
Peter Ammon
d2d2d8cb45
Remove the shared_from_this for Parser
We no longer need this.
2024-06-23 16:39:39 -07:00
ridiculousfish
924d6aac71
Remove another call to current_data()
Continue to get off of globals.
2024-06-23 16:39:39 -07:00
ridiculousfish
dee692759a
Split Reader off from ReaderData
Prior to this commit, there was a stack of ReaderDatas, each one has a
reference to a Parser (same Parser in each, for now). However, the current
ReaderData is globally accessible. Because it holds a Parser, effectively
anything can run fish script; this also prevents us from making the Parser
&mut.

Split these up. Create ReaderData, which holds the data portion of the
reader machinery, and then create Reader which holds a ReaderData and a
Parser. Now `reader_current_data()` can only return the data itself; it
cannot execute fish script.

This results in some other nice simplifications.
2024-06-23 16:39:39 -07:00
ridiculousfish
dfd948fcb5
Eliminate a call to reader_current_data
Try to get off of these globals.
2024-06-23 16:39:39 -07:00
ridiculousfish
c297df38c7
Migrate the Inputter type to a trait
This is a start on untangling input. Prior to this, a ReaderData and an
Inputter would communicate with each other; this is natural in C++ but
difficult in Rust because the Reader would own an Inputter and therefore
the Inputter could not easily reference the Reader. This was previously
"resolved" via unsafe code.

Fix this by collapsing Inputter into Reader. Now they're the same object!
Migrate Inputter's logic into a trait, so we get some modularity, and then
directly implement the remaining input methods on ReaderData.
2024-06-23 16:39:39 -07:00
ridiculousfish
c9a76bd634
Make OperationContext not hold a Parser via Rc
Exploit Rust's lifetimes. This will lead to simplifications.
2024-06-23 16:39:39 -07:00
ridiculousfish
d36f94d96c
Remove additional call to Parser::shared() 2024-06-23 16:39:39 -07:00
ridiculousfish
832ed31687
Start removing calls to Parser::shared()
Parser::shared() gets an Rc to a Parser, but we can do without it.
Let's aim to get rid of the cyclic ref.
2024-06-23 16:39:39 -07:00
Mahmoud Al-Qudsi
2f46186f2b Fix formatting 2024-06-23 18:01:31 -05:00
Mahmoud Al-Qudsi
1a18d06a57 math: Fix copy-and-paste error in error message 2024-06-23 17:53:49 -05:00
Mahmoud Al-Qudsi
1a7a7a5dcb math: Support abbreviated scale modes 2024-06-23 17:52:14 -05:00
Mahmoud Al-Qudsi
80c02400eb Fix hard-coded decimal separator in builtin math 2024-06-23 17:50:02 -05:00
Mahmoud Al-Qudsi
c0028a0ec9 math: Rename ZeroScaleMode
It's no longer only for the zero scale.
2024-06-23 17:47:21 -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
32a5be52e1 Add note about non-ASCII decimal_sep length 2024-06-19 18:50:24 -05:00
Mahmoud Al-Qudsi
28a3ae7a8b Remove Clone bound on parse_dec_float()
It's not necessary to clone the character iterator at all.
Also move rarely used inf/nan parsing to own cold function.
2024-06-19 18:43:53 -05:00
Peter Ammon
373cef08cc
Fix a clippy in ulimit 2024-06-19 10:47:46 -07:00
Peter Ammon
5cc9e0187e
Suppress an annoying warning about non-camel-case types 2024-06-16 11:49:09 -07:00
Peter Ammon
376bdb16c7
Fix a misspeeled comment 2024-06-15 16:20:15 -07:00
Peter Ammon
5a45b189da
Make EnvStackSetResult use Rust naming conventions 2024-06-15 15:57:28 -07:00
Peter Ammon
0c20ccc72d
Fix an annoying warning about camel case types 2024-06-15 13:46:45 -07:00
Fabian Boehm
84b5701b92 Port fish_test_helper to C
This is the last piece of C++, so now we can remove the need for a C++
compiler.

We need one for C anyway (libc.c).

Fixes #10549
2024-06-12 08:11:16 +02:00
Fabian Boehm
32d23a37cb format 2024-06-10 17:16:19 +02:00
Fabian Boehm
652996124d reader: Remove a panic
The special input functions self-insert, self-insert-not-first, and
and or used to be handled by inputter_t::readch, but they aren't
anymore with `commandline -f`.

I am unsure if these *would* have worked, I can't come up with a use.

So, for now, do nothing instead of panicking.
2024-06-10 17:14:13 +02:00
Fabian Boehm
c7d878a8d2 input: Let function_pop_arg return an Option
This would crash if you ran `commandline -f backward-jump`.

The C++ version would read a char (but badly), this doesn't anymore.

So, at least instead of crashing, just do nothing.
2024-06-10 17:02:11 +02:00
ridiculousfish
20e9c9493c Rewrite float parsing to use Rust native parsing
Eliminates the fast-float dependency.
2024-06-09 15:52:13 -07:00
ridiculousfish
838ff86ae7 Rename printf crate to fish-printf
Preparing to publish to crates.io
2024-06-09 12:29:09 -07:00
Fabian Boehm
251ddd1bcc Revert "builtins/path: Use fancy bitflags feature"
This builds on my machine, but doesn't on CI.

Rust 1.67 possibly needs to derive Eq as well as PartialEq?

This reverts commit 2fa0f13db2.
2024-06-08 09:12:56 +02:00
Fabian Boehm
2fa0f13db2 builtins/path: Use fancy bitflags feature
Just a cleanup TODO, no functional changes intended
2024-06-07 21:49:49 +02:00