Commit Graph

3375 Commits

Author SHA1 Message Date
Fabian Homborg
cc0e366037 history: Skip lines with tabs when importing from bash
Fixes #6923.
2020-10-09 18:54:47 +02:00
ridiculousfish
e9902159c2 Send fish_cancel event on control-C again
This adds support for sending fish_cancel, and a test for it.
Fixes #7384.
2020-10-06 17:49:55 -07:00
Fabian Homborg
e949b1de02 ifdef SIGIO handling
This relies on POLL_IN which apparently isn't a thing on OpenBSD
2020-10-06 17:34:50 +02:00
Fabian Homborg
289bce2f25 Add event flog
I needed this, and it should be there.

[ci skip]
2020-10-06 17:25:45 +02:00
Fabian Homborg
00ab51bedc set: Allow erasing multiple variables at once
See #7377.
2020-10-04 12:24:11 +02:00
ridiculousfish
f9e426813c Do not complain about fcntl(F_SETOWN) failing
On WSL1, fcntl(F_SETOWN) will fail and this would report an error.
Suppress this error message since it is not very interesting.
The effect is to disable real-time universal variable propagation.
2020-10-03 15:54:27 -07:00
ridiculousfish
558dd6e53d Add sigio-based universal notifier strategy
Introduce a new strategy for notifying other fish processes of universal
variable changes, as a planned replacement for the complex
strategy_named_pipe. The new strategy still uses a named pipe, but instead
of select() on it, it arranges for SIGIO to be delivered when data is
available. If a SIGIO has been seen since the last check, it means the file
needs to be re-read.
2020-10-01 13:19:41 -07:00
ridiculousfish
700fe4f131 Moderize universal variable notifiers
Use some C++11 features.
2020-10-01 13:27:13 -07:00
Fabian Homborg
bbdfe126a7 Flash if history search found nothing
This makes it clearer that we're at the end.

Fixes #7362.
2020-09-30 18:02:22 +02:00
Fabian Homborg
d6d3abf59a Introduce $FISH_DEBUG and $FISH_DEBUG_OUTPUT variables
Same as the `--debug` and `--debug-output` options, can be enabled
when the option can't be passed, e.g. in linux shebangs.

Fixes #7359.
2020-09-28 17:46:37 +02:00
ridiculousfish
c89c72f431 Invert sense of expand_flag::no_descriptions
When expanding a string, you may or may not want to generate
descriptions alongside the expanded string. Usually you don't want to
but descriptions were opt out. This commit makes them opt in.
2020-09-27 16:50:40 -07:00
Johannes Altmanninger
f758d39535 string pad: handle padding characters of width > 1
If the padding is not divisible by the char's width without remainder,
we pad the remainder with spaces, so the total width of the output is correct.

Also add completions, changelog entry, adjust documentation, add examples
with emoji and some tests.  Apply some minor style nitpicks and avoid extra
allocations of the input strings.
2020-09-27 21:59:15 +02:00
Johannes Altmanninger
5ae03414d7 Sort string subcommands, and use binary search for lookup
I have no idea if this is better, and did not attempt to measure it, but we
do the same for electric variables which are even fewer.
2020-09-27 21:59:15 +02:00
Andrew Prokhorenkov
92511b09c4 New command "string pad" to pad text to a given width (#7340)
Pads text to a given width, or the maximum width of all inputs.
2020-09-27 21:59:15 +02:00
Johannes Altmanninger
e8859b4ce2 Do not treat newlines special in bigword movements
Improves on #7328.

I believe this is the correct behavior, simply skip all whitespace before
a word. Try with

	./fish -C 'bind \ef forward-bigword; bind \eb backward-bigword; bind \ed kill-bigword; bind \cw backward-kill-bigword'

Also unrelated formatting fixes. I don't think a CI failure on unformatted
code is warranted but I wish it could do that behind the scenes.
2020-09-27 18:04:09 +02:00
Johannes Altmanninger
791d23502f Do not add a space after completing flag with optional argument
For example "grep --color"<TAB> can complete to "grep --color=".  Don't add
a space in this case; we do the same for arguments that end in =.

In GNU-style getopt, equal sign means that the flag has an argument. Without
the = it would not consume the next argument as opposed to Python's argparse.
2020-09-27 17:56:21 +02:00
sgrj
ab2cb03189
Consistency-fix for word motions (#7354)
* change word motion test to include start cursor in specification

* add test case for bug

* fix bug
2020-09-27 15:34:34 +02:00
Fabian Homborg
adb1f993a7 Reader: Turn *off* INLCR for external commands
That's how it worked previously, and it makes ctrl-j usable again.

Fixes #7352
2020-09-27 13:54:47 +02:00
Fabian Homborg
0f7e2ca99c Don't put commandline on a new line if prompt is "long"
This was a weird special behavior where we'd put the commandline on a
new line if it wrapped *and* the prompt was > 33% of the screen.

It seems to be more confusing than anything.

Fixes #5118.
2020-09-27 13:12:06 +02:00
ridiculousfish
e88eb508d0 Rework variable assignments during tab completion
Prior to this change, tab completing with a variable assignment like
`VAR=val cmd<tab>` would parse out and apply VAR=val, then recursively
invoke completions. This caused some awkwardness around the wrap chain -
if a wrapped command had a variable completion we risked infinite
recursion. A secondary problem is that we would run any command
substitutions inside variable assignment, which the user does not expect
to run until pressing enter.

With this change, we explicitly track variable assignments encountered
during tab completion, including both those explicitly given on the
command line and those found during wrap chain walk. We then apply them
while suppressing command substitutions.
2020-09-26 18:39:38 -07:00
ridiculousfish
cc07716dc1 Separate out variable assignments when completing
In preparation for applying variable assignments (VAR=VAL cmd), separate
them out from the command when performing completions. This includes both
those that the user typed, and any that come about through
completion --wraps.
2020-09-26 17:30:25 -07:00
ridiculousfish
3ef83de866 Rename cmd to cmdline in completer_t::perform_for_command
This makes it clear that the commandline contains arguments, etc.
2020-09-26 17:30:13 -07:00
ridiculousfish
757dda43ac Factor custom completion information into custom_arg_data_t
When completing and walking a wrap chain, we pass around a lot of
information. Factor this together into a new struct custom_arg_data_t
which reduces the number of parameters needed.
2020-09-26 17:30:10 -07:00
ridiculousfish
5cadea0173 Migrate the complete_custom transient command line pop to cleanup_t
This ensures that it gets cleaned up even if there is a mid-function
return.
2020-09-26 17:25:02 -07:00
ridiculousfish
45b85d28bb Completion wrap chain visited set to store only wrapped command
The "wrap chain" refers to a sequence of commands which wrap other
commands, for completion purposes. One possibility is that a wrap chain
will produce a combinatorial explosion or even an infinite loop, so there
needs to be logic to prevent that. Part of that logic is encapsulated in a
visited set (wrap_chain_visited_set_t) to prevent exploring the same item
twice.

Prior to this change, we stored pairs (command, wrapped_command). But we
only really need to store the wrapped command. Switch to that.

One consequence is that if a command wraps another command in more than
one way, we won't explore both ways. This seems unlikely in practice.
2020-09-26 17:24:59 -07:00
Johannes Altmanninger
879e80859c Refactor: apply some lints
And reformat touched files; my editor just does that.
2020-09-26 14:56:03 +02:00
Johannes Altmanninger
45e7c709f4 Consolidate complete cycle detection and always report error on cycle
Detect recursive calls to builtin complete and the internal completion in
the same place.

In 0a0149cc2 (Prevent infinite recursion when completion wraps variable assignment)
we don't print an error when completing certain aliases like:

	alias vim "A=B vim"

But we also gave no completions.
We could make this case work, but I think that trying to salvage situations
like this one is way too complex. Instead, let the user know by printing an
error. Not sure if the style of the error fits.

We could add some heuristic to alias to not add --wraps in some cyclic cases.
2020-09-26 14:56:03 +02:00
Johannes Altmanninger
3dd9531472 Refactor: decouple the command to complete from completer_t
This allows us to reuse a completer_t for completions of commands like
"a=b ... ", instead of calling complete().
2020-09-26 14:56:03 +02:00
Johannes Altmanninger
e4e2155f5e Refactor: move wrap chain visitor into a function
The lambda has grown way too big, and it was not easy to see what the inputs
and outputs are. We always use the same visitor, so the function parameter
is not necessary.
2020-09-26 14:56:03 +02:00
Fabian Homborg
fa0c9f90f8 Read arguments with fish -c
This reads any additional positional arguments given to `fish -c` into
$argv.

We don't handle the first argument specially (as `$0`) as that's confusing and
doesn't seem very useful.

Fixes #2314.
2020-09-26 14:47:20 +02:00
Fabian Homborg
396d7e105f fish_tests: Break if unescape test failed
Otherwise this prints millions of lines of errors, which just seems
like overkill
2020-09-26 10:43:05 +02:00
Fabian Homborg
06f6436943 reader: Return true if suppress-autosuggestion suppressed
This allows

bind -k backspace suppress-autosuggestion or backward-delete-char

To remove the suggestion on the first press and then delete
chars.

Note: This requires that we then don't reenable suggestions
immediately afterwards. Currently we don't after deletion.

Fixes #1419.
2020-09-26 10:09:55 +02:00
Fabian Homborg
0d0ee473fa Detect windows line endings when executing a file
Fixes #2783.
2020-09-25 16:51:05 +02:00
Fabian Homborg
a776b08e84 Use bools, we have the technology 2020-09-24 18:53:19 +02:00
Fabian Homborg
1188a12dfd type: Print *only* the path if given --path or --force-path
This is what happens when you check your tests in the wrong tab,
folks.

Fixes #7345.
2020-09-23 17:24:51 +02:00
Fabian Homborg
1da56f9937 Make history search smartcase
This makes history searches case-insensitive, unless the search string
contains an uppercase character.

This is what vim calls "smartcase".

Fixes #7273.
2020-09-22 16:13:24 +02:00
Johannes Altmanninger
0a0149cc2a Prevent infinite recursion when completion wraps variable assignment
Closes #7344

Apply a targeted fix to the place where complete() is called to handle nested
variable assignments.  Sadly, reporting an error is probably not okay here,
because people might legitimately use aliases like:

	alias vim "A=B command vim"

This is all a bit ugly, and I hope to find a cleaner solution.  Supporting
completions on commandlines like `x=$PWD cd $x/ ` is a nice feature but it
comes with some complexity.
2020-09-22 01:11:18 +02:00
Johannes Altmanninger
ca538fa8d8 Refactor: make function static and reformat
"IndentCaseLabels: false" seems nice but not now.
2020-09-22 00:17:19 +02:00
Mahmoud Al-Qudsi
383f1d1a19 fixup! Make type a builtin
[ci skip]
2020-09-21 15:42:55 -05:00
Fabian Homborg
ef9c924960 Make type a builtin
This is too important to not be one.

For one if it couldn't be loaded for any reason it would
break a lot of fish scripts.

Also this is faster by ~20x.

Fixes #7342
2020-09-21 20:58:34 +02:00
Fabian Homborg
3a05326a39 Move functions_def to function.cpp
We're gonna be using it in two places
2020-09-21 17:44:58 +02:00
Fabian Homborg
66475732af Fix str2wcs for LANG=C
4f0ade7a73 broke the tests when LANG was
C, so the MB_CUR_MAX==1 path wasn't working.

Seemingly that cast is doing some work here?

Just revert that bit for now, since this path is unimportant
anyway (please, please, please, please use a unicode capable locale).
2020-09-20 15:05:49 +02:00
Fabian Homborg
7ec57f2c50 string: Handle unmatched capturing groups as empty
Instead of erroring out.

Fixes #7343.
2020-09-20 10:36:17 +02:00
ridiculousfish
5c3571d626 Revert accidental merge of #7340
This reverts back to commit d8e2cac83e.
I accidentally did a 'git push' during code review.
2020-09-19 19:31:44 -07:00
Andrew Prokhorenkov
2afa354c14 builtin_string: implement "width" argument for "string pad" 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
70dfece3ce builtin_string: remove quiet 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
7eccec3ce0 builtin_string: order "string_pad" before "string_replace" 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
52b0d356ff builtin_string: remove redundant statements 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
2b9158ddab builtin_string: add "--max" for "string pad" 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
886290c123 builtin_string: change npad 2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
c8e1894c72 builtin_string: add pad command 2020-09-19 19:25:57 -07:00
ridiculousfish
d8e2cac83e Reimplement vectorized reads for detecting ASCII strings
This is a reimplementation of the "vectorized" ASCII detection
from str2wcs_internal. This handles the case where only part of
a string is ASCII. It also avoids pointer overflow issues and improves
commenting.
2020-09-19 17:52:17 -07:00
ridiculousfish
4f0ade7a73 Optimize str2wcs_internal more
Prior to this change, str2wcs_internal had an optimization for ASCII
inputs. However the main cost was the repeated bounds checks when
performing push_back() on the resulting wcstring.

Switch to determining the number of ASCII characters, and then appending
those all in one go. This improves the time in the 'convert_ascii' test
from ~450 usec to ~75 usec.
2020-09-19 17:47:14 -07:00
ridiculousfish
4d5d90d828 Add a simple ASCII conversion test and benchmark
Run `fish_tests perf_convert_ascii` to run the benchmark.
2020-09-19 17:47:12 -07:00
Johannes Altmanninger
291d1fbf1b Recompute completions if previous attempt failed
When pressing tab repeatedly, completions only computed on the first one. This
is because the old logic assumed that completions are present if the last
key was tab. Recompute them if there are no completions at all.

Fixes #6863
2020-09-17 18:44:54 +02:00
Fabian Homborg
181ce4a6b6 Actually create runtime path if needed
This checked if the path was readable and only then tried creating it,
which... isn't right.

Fixes #7335.
2020-09-17 12:33:56 +02:00
Fabian Homborg
58245b6fe7 set_color: Honor modifiers (bold, background..) with --print-colors
Fixes #7314
2020-09-17 12:33:56 +02:00
Fabian Homborg
709e91c1e6 builtin test: Let -t work for the standard streams
Since builtins don't actually have the streams connected, but instead
read input via the io_streams_t objects, this would just always say
what *fish's* fds were.

Instead, pass along some of the stream data to check those
specifically - nobody cares that `test`s fd 0 *technically* is stdin.
What they want to know is that, if they used another program in that
place, it would connect to the TTY.

This is pretty hacky - I abused static variables for this, but
since it's two bools and an int it's probably okay.

See #1228.

Fixes #4766.
2020-09-16 21:02:59 +02:00
Fabian Homborg
1215717d20 Set exit status with delete-or-exit
(regression from d415350aaf)

This is important especially in e.g. the new Windows Terminal, because
for some reason that lets the tab stick around if the process exited
with a non-zero status.

Will add tests as soon as I figure out how.
2020-09-16 21:02:59 +02:00
ridiculousfish
2a8e104cc8 Relax some main thread requirements around waiting for jobs
This is now correctly per-parser so the thread should no longer matter.
2020-09-13 17:54:52 -07:00
ridiculousfish
9ba12aad55 Fix the tests
Make the features_t constructor public so the tests compile. Mea culpa.
2020-09-12 19:06:28 -07:00
ridiculousfish
6e11750479 Make the global feature set an instance variable
Allow it to be inlined.
2020-09-12 17:35:21 -07:00
Fabian Homborg
5fd3ad624f screen: Show suggestion if the commandline was pushed to a new line
Pretty sure this was just overlooked, the comment mentions that it
should happen and it seems to work.

Fixes #7213.
2020-09-12 20:09:26 +02:00
Fabian Homborg
568f9031aa builtin realpath: Add --no-symlinks option
Taken from GNU realpath, this one makes realpath not resolve symlinks.

It still makes paths absolute and handles duplicate and trailing
slashes.

(useful in fish_add_path)
2020-09-12 19:26:04 +02:00
Fabian Homborg
8cf389baf2 tokenizer: Switch to !iswblank instead of iswgraph
Fixes #7328
2020-09-11 23:53:26 +02:00
Fabian Homborg
0e9b496bba Fix bigword bindings with single-character words
With a commandline like

```
a b c d
```

and the cursor at the beginning, this would eat "a b", which isn't a
sensible bigword.

Bigword should be "a word, with optional leading whitespace".

This was caused by an overly zealous state-machine that always ate one
char and only *then* started eating leading whitespace.

Instead eat *a character*, and if it was whitespace go on eating
whitespace, and if it was a printable go straight to only eating
printables.

Fixes #7325.
2020-09-11 20:13:06 +02:00
Fabian Homborg
30b2dc2b97 Don't enqueue a repaint in the middle of one
This can easily lead to an infinite loop, if a variable handler
triggers a repaint and the variable is set in the prompt, e.g. some of
the git variables.

A simple way to reproduce:

    function fish_mode_prompt
        commandline -f repaint
    end

Repainting executes the mode prompt, which triggers a repaint, which
triggers the mode prompt, ....

So we just set a flag and check it.

Fixes #7324.
2020-09-11 19:23:26 +02:00
Fabian Homborg
903b7888d3 complete: Make -c optional
Currently, completions have to be specified like

```fish
complete -c foo -l opt
```

while

```fish
complete foo -l opt
```

just complains about there being too many arguments.

That's kinda useless, so we just assume if there is one left-over
argument that it's meant to be the command.

Theoretically we could also use *all* the arguments as commands to
complete, but that seems unlikely to be what the user wants.

(I don't think multi-command completions really happen)
2020-09-09 20:23:08 +02:00
Fabian Homborg
a8e237f0f9 Let complete show completions for one command if just given -c
Currently only `complete` will list completions, and it will list all
of them.

That's a bit ridiculous, especially since `complete -c foo` just does nothing.

So just make `complete -c foo` list all the completions for `foo`.
2020-09-09 18:37:39 +02:00
Johannes Altmanninger
de9874e4de Remove some useless casts
I think the warnings from -Wuseless-cast are mostly platform-specific but
I hope these are correct.
2020-09-08 22:44:03 +02:00
Johannes Altmanninger
fbaa5d193d Declare functions in headers or use internal linkage (static)
Found with gcc's -Wmissing-declarations which gives warnings like

	../src/tinyexpr.cpp:61:5: warning: no previous declaration for ‘int get_arity(int)’ [-Wmissing-declarations]
	   61 | int get_arity(const int type) {

The same warnings show up for builtin functions like builtin_bg because they
currently don't include their own headers. I left that.
Also reformat the touched files.
2020-09-08 22:44:03 +02:00
Johannes Altmanninger
7a4fece445 Give reader control of all edits to a command line
So we can do something on every edit, for example repaint the pager (#7318).
This patch fixes pager refiltering and repainting when pressing Control+U
after typing something in the search field.

Implement this by moving the convenience functions from editable_line_t to
the reader, so we have fewer places where we need to refilter.  Essentially we
only have two cases: insertions at the cursor are handled by insert_string(),
and all others go through push_edit().  This should also make it clearer
where we update undo_history.may_coalesce.

This commit was on the history-search-edit-needle branch, so it should
work fine.  I hope it does play well with some recent changes.

In 6d339df61 (Factor repainting decions from readline commands better
in the reader), insert_string() was simplified a lot, mirror that.

The tests for editable_line_t are not that useful anymore since the caller has
to decide whether to coalesce insertions, but I guess they don't hurt either.
We should have more tests for some interactive scenarios like undo and the
pager filtering.
2020-09-08 22:00:48 +02:00
Mahmoud Al-Qudsi
90433f6ea3 Minimize AST node vector reallocations
Closes #7201
2020-09-08 11:55:10 -05:00
Fabian Homborg
f67673de71 Repaint on pager search
This was broken in 6d339df612, when we removed
the normal repainting logic.

The pager *search* however needs to trigger a refilter, and therefore
needs to trigger after every insert/removal.

Fixes #7318
2020-09-08 15:01:22 +02:00
Mahmoud Al-Qudsi
be1604fe31 fixup! Add str2wcs optimization for ascii-only inputs
Fix aligned read past end of buffer.
2020-09-07 20:39:49 -05:00
Mahmoud Al-Qudsi
84c72f2817 Add str2wcs optimization for ascii-only inputs
This avoids the heavy hit of __gconv_transform_utf8_internal.

In the worst case, after `is_ascii` returns the string is guaranteed to
be in the CPU cache (assuming realistic input sizes). In the best (and
hopefully extremely common) case, the conversion table lookups are
completely avoided.

In terms of real world gains, simply calling `history` is anywhere from
2x to 3x faster for large history files composed of mostly ascii
content under glibc 2.31 on AMD64.
2020-09-07 19:38:06 -05:00
Mahmoud Al-Qudsi
1365379518 Optimize away a str2wcs_internal check
str2wcs_internal is one of worst hot paths in the codebase, and this
particular check can be optimized away for non-macOS hosts at compile
time.
2020-09-07 18:05:18 -05:00
Fabian Homborg
340de73172 Call "fish_command_not_found" if a command wasn't found
Previously, when a command wasn't found, fish would emit the
"fish_command_not_found" *event*.

This was annoying as it was hard to override (the code ended up
checking for a function called `__fish_command_not_found_handler`
anyway!), the setup was ugly,
and it's useless - there is no use case for multiple command-not-found handlers.

Instead, let's just call a function `fish_command_not_found` if it
exists, or print the default message otherwise.

The event is completely removed, but because a missing event is not an error
(MEISNAE in C++-speak) this isn't an issue.

Note that, for backwards-compatibility, we still keep the default
handler function around even tho the new one is hard-coded in C++.

Also, if we detect a previous handler, the new handler just calls it.

This way, the backwards-compatible way to install a custom handler is:

```fish
function __fish_command_not_found_handler --on-event fish_command_not_found
    # do a little dance, make a little love, get down tonight
end
```

and the new hotness is

```fish
function fish_command_not_found
    # do the thing
end
```

Fixes #7293.
2020-09-06 11:15:54 +02:00
ridiculousfish
d1dab22691 Ensure we don't leak half of a pipe
It was possible though unlikely for make_autoclose_pipes to close only
one side of pipe, if it fails to find a new fd. This would result in an
fd leak. Ensure that doesn't happen.
2020-09-05 13:24:26 -07:00
ridiculousfish
1cef87d790 Use anon semaphores only on Linux
On BSDs, anonymous semaphores are implemented using a file descriptor
which is not marked CLOEXEC, so it gets leaked into child processes.
Use ordinary pipes instead of semaphores everywhere except Linux.

Fixes #7304
2020-09-05 13:04:22 -07:00
ridiculousfish
acb33682a9 Remove some errant 'file' from redirection comment
See #7301
2020-09-05 11:28:43 -07:00
ridiculousfish
abadab5176 Revert "Fix examples in tokenizer comment for redirection"
This reverts commit 66f81a2b4c.
2020-09-05 11:27:48 -07:00
Nathan Lanza
66f81a2b4c Fix examples in tokenizer comment for redirection
Four of these examples were incorrect and didn't perform the stated
behavior in neither bash nor fish. Fix them here.
2020-09-05 11:27:30 -07:00
ridiculousfish
457f95fe52 Mark s_cancellation_signal a relaxed atomic
Thread sanitizer is salty about this even though it's
volatile sig_atomic_t. Make it atomic too.
2020-09-04 16:10:22 -07:00
ridiculousfish
3f3531c819 Ensure we preserve errno in signal handlers 2020-09-04 15:32:29 -07:00
Fabian Homborg
55f1cc56da Remove errant fish_wcwidth call
This was added in c9bcb52fe9 for no discernable reason.
2020-09-04 17:12:22 +02:00
Fabian Homborg
bfb5b28d0f Let command, jobs and type take --query instead of --quiet
Now command, jobs, type, abbr, builtin, functions and set take `-q` to
query for existence, but the long option is inconsistent.

The first three use `--quiet`, the latter use `--query`. Add `--query`
to the first three, but keep `--quiet` around.

Fixes #7276.
2020-09-04 16:55:09 +02:00
ridiculousfish
3062994645 Implement cancel groups
This concerns how "internal job groups" know to stop executing when an
external command receives a "cancel signal" (SIGINT or SIGQUIT). For
example:

    while true
        sleep 1
    end

The intent is that if any 'sleep' exits from a cancel signal, then so would
the while loop. This is why you can hit control-C to end the loop even
if the SIGINT is delivered to sleep and not fish.

Here the 'while' loop is considered an "internal job group" (no separate
pgid, bash would not fork) while each 'sleep' is a separate external
command with its own job group, pgroup, etc. Prior to this change, after
running each 'sleep', parse_execution_context_t would check to see if its
exit status was a cancel signal, and if so, stash it into an int that the
cancel checker would check. But this became unwieldy: now there were three
sources of cancellation signals (that int, the job group, and fish itself).

Introduce the notion of a "cancellation group" which is a set of job
groups that should cancel together. Even though the while loop and sleep
are in different job groups, they are in the same cancellation group. When
any job gets a SIGINT or SIGQUIT, it marks that signal in its cancellation
group, which prevents running new jobs in that group.

This reduces the number of signals to check from 3 to 2; eventually we can
teach cancellation groups how to check fish's own signals and then it will
just be 1.
2020-09-03 11:01:27 -07:00
ridiculousfish
760b6e76cc Rename populate_group_for_job to resolve_group_for_job
Factor it to allows the function to not modify the job.
2020-09-03 10:50:17 -07:00
ridiculousfish
6c4d6dc4a9 Make the 'time' keyword a fixed property of a job.
The 'time' prefix may come about either because the job itself is marked
with time, or because of the "inside out" weirdness of 'not time...'.
Factor this logic together and precompute it for a job.
2020-09-02 15:06:17 -07:00
Fabian Homborg
b521ca4875 Always check for fish_right_prompt's existence
This would only check for fish_right_prompt at startup, so if one
wasn't defined then it would never accept one.

The "config" here is just the *name* of the function (which we never
change, so it wouldn't really be necessary, but whatever).

The one exception is the breakpoint, in those we don't run the right
prompt.

Fixes #7302.
2020-09-02 17:51:21 +02:00
Fabian Homborg
4d22ebf49c Remove duplicated line
This was duplicated on accident, and given that it runs outside of the
"if (cur_term != null)" block and accessed max_colors it could cause issues.
2020-09-02 17:37:32 +02:00
Fabian Homborg
be3a7c03ba Move truecolor detection to C++
This allows us to send proper debug messages via FLOG, and it removes
more things from share/config.fish.

Note that the logic differs in some subtle ways. For instance it will
now obey $COLORTERM, so if that isn't "truecolor" or "24bit" it will
deactivate truecolor.
2020-08-31 16:49:57 +02:00
ridiculousfish
0379f21870 Correctly cancel on receipt of SIGHUP
When we receive SIGHUP, stop executing normal fish script (but allow
exit handlers to run).
2020-08-30 15:09:34 -07:00
ridiculousfish
0b075fce88 Factor the exit state to make exit handlers more explicit
This adds a new type 'exit_state_t' which encapsulates where fish is in
the process of exiting. This makes it explicit when fish wants to cancel
"ordinary" fish script but still run exit handlers.

There should be no user-visible behavior change here; this is just
refactoring in preparation for the next commit.
2020-08-30 15:09:31 -07:00
Johannes Altmanninger
cf075b4179 Teach up-line to cross empty lines
The line offset of a trailing newline on the commandline was computed incorrectly.
As a result, up-arrow did not work for a commandline like the one inserted by:

	commandline -i echo '' ''

Note this and the previous commit in the changelog.
2020-08-29 12:02:18 +02:00
Johannes Altmanninger
ac60522373 Stop history searches with no results to allow up-or-search to move the cursor
Enter a multiline commandline, for example using

	commandline -i echo echo

And press down-arrow. This will start a new history search which fails.
Then press up-arrow. I expect the cursor to move up, however, because we
are still in history search mode, up-or-search will search instead of moving
the cursor. Correct that by stopping history searches that don't have any results.
2020-08-29 12:02:18 +02:00
Johannes Altmanninger
a20721a278 Address some warnings from clangd 2020-08-29 12:02:18 +02:00
ridiculousfish
b166baf7d6 Fix a warning about ambiguous && and || in pager 2020-08-27 14:14:05 -07:00
Johannes Altmanninger
09f189870e Trigger prompt repaint after printing parser error or background job warning
See #7289
2020-08-27 21:18:26 +02:00