Commit Graph

5050 Commits

Author SHA1 Message Date
Johannes Altmanninger
c3cd68dda5 Process shell commands from bindings like regular char events
A long standing issue is that bindings cannot mix special input functions
and shell commands. For example,

    bind x end-of-line "commandline -i x"

silently does nothing. Instead we have to do lift everything to shell commands

    bind x "commandline -f end-of-line; commandline -i x"

for no good reason.

Additionally, there is a weird ordering difference between special input
functions and shell commands. Special input functions are pushed into the
the queue whereas shell commands are executed immediately.

This weird ordering means that the above "bind x" still doesn't work as
expected, because "commandline -i" is processed before "end-of-line".

Finally, this is all implemented via weird hack to allow recursive use of
a mutable reference to the reader state.

Fix all of this by processing shell commands the same as both special input
functions and regular chars. Hopefully this doesn't break anything.

Fixes #8186
Fixes #10360
Closes #9398
2024-03-23 10:06:11 +01:00
Johannes Altmanninger
232483d89a History pager to only operate on the line at cursor
Multiline search strings are weirdly broken (inserting control characters
in the command line) and probably not very useful anyway.
On the other hand I often want to compose a multi-line command
from single-line commands I ran previously.

Let's support this case by limiting the initial search string to the current
line; and replace only that line.

Alternatively this could operate on jobs (that is, replace a surrounding
"foo | bar") instead of using line boundaries.
2024-03-23 09:54:18 +01:00
Mahmoud Al-Qudsi
0ca199ef98 Change wopen_cloexec() to return File 2024-03-23 01:34:23 -05:00
Mahmoud Al-Qudsi
8d9d4ce1f9 Add and use separate open_dir() method
This is resistant to misuse by including O_DIRECTORY in the open flags and it is
a separate function from {w,}open_cloexec() in preparation for making that one
return a `File` instead of an `OwnedFd`.
2024-03-23 01:15:43 -05:00
Mahmoud Al-Qudsi
99c9d6eef6 IoFile: Wrap File instead of OwnedFd 2024-03-23 00:44:27 -05:00
Mahmoud Al-Qudsi
6f9f9ee400 Use bitflags contains() instead of intersects()
`intersects()` is "any of" while `contains()` is "all of" and while it makes no
difference when testing a single bit, I believe `contains()` is less brittle
for future maintenance and updates as its meaning is clearer.

</pedantic>
2024-03-23 00:24:31 -05:00
Mahmoud Al-Qudsi
6ed4d09c93 Switch more to File/BorrowedFd from OwnedFd/RawFd
More work in prep for having wopen_cloexec() return `File` directly.

This eliminates checking for an invalid fd and makes both ownership and
mutability clear (some more operations that involve changes to the underlying
state of the fd now require `&mut File` instead of just a `RawFd`).

Code that clearly does not use non-blocking IO is ported to use
`Write::write_all()` directly instead of our rusty port of the `write_loop()`
function (which handles EAGAIN/EWOULDBLOCK in addition to EINTR, while
`write_all()` only handles the latter).
2024-03-23 00:01:57 -05:00
Mahmoud Al-Qudsi
c0d68084f7 Add AsFd impl for AutoCloseFd
Will be used to remove RawFd usages.
2024-03-22 23:58:12 -05:00
Mahmoud Al-Qudsi
4e50ae34da Add native read_retry() and write_retry() methods
These are equivalent to read_loop() and write_loop() but operate on native Rust
types without libc ffi.
2024-03-22 23:05:56 -05:00
Fabian Boehm
ce62b284b1 test_helper: Give self-signalling a chance to trigger
This abort()ed right after the signal, so it's possible to crash
before the signal is delivered. This could trigger under ASAN on
Github Actions.
2024-03-19 16:41:25 +01:00
Mahmoud Al-Qudsi
decf99f71b
Use File instead of OwnedFd in a few places (#10355)
This is a step towards converting `wopen_cloexec()` to return `File` instead of
`OwnedFd`/`AutocloseFd`.¹

In addition to letting us use native standard library functions instead of
unsafe libc calls, we gain additional semantic safety because `File` operations
that manipulate the state of the fd (e.g. `File::seek()`) require a `&mut`
reference to the `File`, whereas using `RawFd` or `OwnedFd` everywhere leaves us
in a position where it's not clear whether or not other references to the same
fd will manipulate its underlying state.

¹ We actually wouldn't even need `wopen_cloexec()` at all (just a widechar
wrapper) as Rust's native `File::open()`/`File::create()` functionality uses
`FD_CLOEXEC` internally.
2024-03-17 11:20:44 -05:00
Johannes Altmanninger
2972407b9e builtin read: minor code cleanup 2024-03-16 10:31:01 +01:00
The0x539
b8d1dc93d6 ast: Replace can_parse with static dispatch 2024-03-16 08:39:27 +01:00
Andrew Neth
08220c2189
builtin/test: refactor the Token enum to be more granular (#10357)
* builtin/test: Split Token enum into 2-level hierarchy

* builtin/test: Rearrange the Token enum hierarchy

* builtin/test: Separate Token into Unary and Binary

* builtin/test: import IsOkAnd polyfill

* builtin/test: Rename enum variants one more time
2024-03-15 23:24:44 -05:00
Fabian Boehm
a64a50db47 reader: Use our isatty overload
Removes an annoying use of unsafe
2024-03-10 20:47:26 +01:00
Fabian Boehm
ffc4372cad History: Change an assert into return None
I was able to trigger this by flipping around the history pager.

Since the only applicable caller here already stops if it gets None,
just don't assert.
2024-03-10 16:55:43 +01:00
Fabian Boehm
074b96640d pager: Make search text translatable 2024-03-10 16:38:05 +01:00
Fabian Boehm
00c68145b8 fmt
I still hate this
2024-03-10 16:17:40 +01:00
Fabian Boehm
25e170141c Fix some translated strings 2024-03-10 16:15:15 +01:00
Mahmoud Al-Qudsi
3f6b009870 Only update env_universal self.last_read_file on success
I don't think the existing logic is correct, as the comment says, our internal
state is only matched if we *actually* wrote out the file. But if we ran into an
error, it doesn't match, does it?
2024-03-10 09:49:54 +01:00
Johannes Altmanninger
94477f3029 Fix commandline -C regression handling negative offsets 2024-03-10 09:46:16 +01:00
Fabian Boehm
947883c842 commandline: Fix setting cursor
Fixes #10358
2024-03-10 09:27:56 +01:00
Mahmoud Al-Qudsi
7c173c4b45 Fix formatting of new test 2024-03-09 22:06:33 -06:00
Mahmoud Al-Qudsi
4e95a3713e Add test asserting stdlib uses O_CLOEXEC 2024-03-09 22:05:23 -06:00
Bartłomiej Maryńczak
d5cde80447
Use Result for write_to_fd return value (#10308) 2024-03-09 21:29:50 -06:00
Mahmoud Al-Qudsi
e6687dc61f Make open_temporary_file() fallible again
I was under the apparently mistaken impression that `FLOG!(error, ...)`
triggered an abort when I committed 58a6eb6e45.
2024-03-09 21:21:29 -06:00
Mahmoud Al-Qudsi
6d30363090 Simplify control flow in env_universal_common::save() 2024-03-09 15:21:47 -06:00
Mahmoud Al-Qudsi
58a6eb6e45 Convert fish_mkstemp_cloexec() to return an OwnedFd 2024-03-09 15:21:47 -06:00
The0x539
cfe9881eaa Suppress unknown_lints lint
This is to prevent stable from complaining about nightly-only lints.

Closes #10354
2024-03-09 13:49:25 +01:00
The0x539
6c0381c335 Suppress assigning_clones and incompatible_msrv
The incompatible_msrv one is a false positive because we have polyfills for
is_some_and() and is_ok_or() which are Rust 1.74. I'm not yet sure how to
communicate that to Clippy.
2024-03-09 13:49:25 +01:00
The0x539
4296c49a06 Remove unnecessary scoped #[allow] attributes 2024-03-09 13:49:25 +01:00
The0x539
4c3e814a50 Address clippy lints 2024-03-09 13:49:25 +01:00
Fabian Boehm
b03e727531 Remove unnecessary formatting 2024-03-09 12:06:24 +01:00
Fabian Boehm
f7cc1743c6
Allow deciding if a command should be saved to history (#10302)
Call fish_should_add_to_history to see if a command should be saved

If it returns 0, it will be saved, if it returns anything else, it
will be ephemeral.

It gets the right-trimmed text as the argument.

If it doesn't exist, we do the historical behavior of checking for a
leading space.

That means you can now turn that off by defining a
`fish_should_add_to_history` that just doesn't check it.

documentation based on #9298
2024-03-09 12:04:16 +01:00
Fabian Boehm
97e7e730e1 Clean up two awkward wgettext_fmt invocations 2024-03-09 11:48:29 +01:00
The0x539
1de7ebcf68 Simplify shared-from-this pattern 2024-03-09 10:09:03 +01:00
Peter Collingbourne
e5f83cd9a7 Fix logic for relocatable directory trees
The existing logic did not work because:

- Path::new("/foo/bar").ends_with("/bar") does not return true.
- PathBuf::shrink_to() only (potentially) reallocates the backing
  storage, and won't have an effect on the stored value.
2024-03-09 09:38:48 +01:00
John
b75e5ee823
remove repetitive words (#10348)
Signed-off-by: hishope <csqiye@126.com>
2024-03-07 18:35:41 -06:00
Mahmoud Al-Qudsi
80133c4bc6
Fix safety issues with some static variables (#10329)
Add safe Send/Sync wrapper for main thread data
2024-03-05 12:33:13 -06:00
Fabian Boehm
031dbb33b1 commandline: Borrow libdata later
builtin_print_help will end up borrowing it as mutable.

Fixes #10342
2024-03-04 16:53:51 +01:00
ridiculousfish
ff6fd699fe Fix a warning about an unused import on macOS 2024-03-03 14:12:59 -08:00
Johannes Altmanninger
33a7172ee8 Revert to not inserting control characters from keyboard input
As mentioned in the comment the historical behavior is because pressing unknown
control characters like Ctrl+4 inserts confusing characters, so let's back
out that part of b77d1d0e2 (Stop crashing on invalid Unicode input, 2024-02-27).

We still have the code for rendering control characters, for pasted text,
or text recalled from history. It is unclear whether we should strip those.
Some terminals already strip control characters from pasted text -- but not
all of them: see https://codeberg.org/dnkl/foot/pulls/312 for example which
has a follow up called "Don't strip HT when pasting in non-bracketed mode".
2024-03-02 23:31:08 +01:00
Fabian Boehm
2a4e776d92 Reimplement git version generation ourselves
This allows us to remove two dependency crates
2024-03-02 10:05:37 +01:00
Mahmoud Al-Qudsi
1ac17756c2 Also address safety issues with principal_parser() 2024-03-01 19:54:28 -06:00
Mahmoud Al-Qudsi
2ecbc56de9 Change MainThread<T> abstraction
Don't force the internal use of `RefCell<T>`, let the caller place that into
`MainThread<>` manually. This lets us remove the reference to `MainThread<>`
from the definition of `Screen` again and reduces the number of
`assert_is_main_thread()` calls.
2024-03-01 19:42:43 -06:00
Mahmoud Al-Qudsi
5c94ebd095 Fix output::stdoutput() safety issues
Fairly straightforward, with the only unfortunate part of this being that
`Screen` isn't as pure and now encodes the facte that we use it with
main-thread-only stdout `Outputter`.
2024-02-29 11:29:37 -06:00
Mahmoud Al-Qudsi
f67ce2ac4b Add Sync/Send wrapper for main-thread-only data 2024-02-28 13:06:04 -06:00
Fabian Boehm
29af775390 abbr: Box the regex
The regex struct is pretty large at 560 bytes, with the entire
Abbreviation being 664 bytes.

If it's an "Option<Regex>", any abbr gets to pay the price. Boxing it
means abbrs without a regex are over 500 bytes smaller.
2024-02-28 18:48:24 +01:00
Fabian Boehm
3d1e8a6106 pager: Simplify some code 2024-02-28 18:34:57 +01:00
Fabian Boehm
31c2eb3f3c pager: Use selected color for parentheses if applicable
This always used pager_completion even for the selected one, now it
uses pager_selected_completion for that.

Fixes #10328
2024-02-28 18:14:05 +01:00