Commit Graph

3245 Commits

Author SHA1 Message Date
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
Johannes Altmanninger
b25b291d38 Refactor: inline clear_pager() 2020-08-26 22:45:05 +02:00
Johannes Altmanninger
9000a3b2fa Redraw pager after it is cleared
Have the new is_repaint_needed() take care of updating the page rendering,
this way we trigger the expected repaints.

Fixes #7289
2020-08-26 22:44:53 +02:00
Fabian Homborg
5eb4de4285 math: Implement tau 2020-08-26 17:48:58 +02:00
Fabian Homborg
5b1c000a2e math: Add bitwise and/or functions
Just as `math "bitand(5,3)"` and `math "bitor(6,2)"`.

These cast to long long before doing their thing,
so they truncate to an integer, producing weird results with floats.

That's to be expected because float representation is *very*
different, and performing bitwise operations on floats feels quite useless.

Fixes #7281.
2020-08-26 17:48:58 +02:00
ridiculousfish
58077c27f8 Remove a wrapper around run_on_main_thread
This was apparently a performance optimization but it is not valuable
given that function is about to load and execute a fish script.
2020-08-24 16:26:15 -07:00
ridiculousfish
47480b2dbd Remove redraw coalescing logic
Prior to this change, if we saw more than one repaint readline command in
a row, we would try to ignore the second one. However this was never the
right thing to do since sometimes we really do need to repaint twice in a
row (e.g. the user hits Ctrl+L twice). Previously we were saved by the
buginess of this mechanism but with the repainting refactoring we see
missing redraws.

Remove the coalescing logic and add a test. Fixes #7280.
2020-08-24 13:22:35 -07:00
ridiculousfish
ac053c02f3 Correct a stale comment 2020-08-24 12:12:10 -07:00
ridiculousfish
9d98bc5158 Ensure we repaint right before execution
If the user enters a command and hits return, we need to repaint so as
to clear the autosuggestion and apply any coalesced characters.
2020-08-23 15:31:57 -07:00
ridiculousfish
d563084dfb Correct highlighting of executed invalid commands
If you expand an abbreviation by executing the command, fish uses a
synchronous mode of syntax highlighting that performs no I/O, because we
want to highlight the abbreviation but don't know if it's valid or not
without doing I/O. However we were doing this too aggressively, after
every command regardless of whether it contained an abbreviation. Only
do this for commands with abbreviations.
2020-08-23 15:31:57 -07:00
ridiculousfish
6d339df612 Revert "Revert "Factor repainting decions from readline commands better in the reader""
This reverts commit eb86bf23e8.

This reintroduces the refactoring; the next two commits fix the
regressions identified in it.
2020-08-23 15:31:57 -07:00
ridiculousfish
eb86bf23e8 Revert "Factor repainting decions from readline commands better in the reader"
This reverts commit 7e7599b22a.

Identified a regression in highlighting
2020-08-23 04:08:03 -07:00
ridiculousfish
7e7599b22a Factor repainting decions from readline commands better in the reader
When typing into the command line, some actions should trigger repainting,
others should kick off syntax highlighting or autosuggestions, etc. Prior
to this change, these were all triggered in an ad-hoc manner. Each
possible

This change centralizes the logic around repainting. After each readline
command or text change, we compute the difference between what we would
draw and what was last drawn, and use that to decide whether to repaint
the screen.

This is a fairly involved change. Bugs here would show up as failing to
redraw, not reacting to a keypress, etc. However it better factors the
readline command handling from the drawing.
2020-08-23 03:41:17 -07:00
ridiculousfish
eac0f35413 camelCase to snake_case a function name 2020-08-23 03:38:25 -07:00
ridiculousfish
9f4b00d95b Remove sanity_check from reader
It hardly checks anything and isn't adding any value.
2020-08-22 12:34:53 -07:00
ridiculousfish
a3a8992f81 Switch reader gen count from 'unsigned' to 'uint32_t'
No functional change but 'unsigned' isn't used often.
2020-08-22 12:30:47 -07:00
ridiculousfish
f24f952991 Use in-line initialization for page_renderint_t's constructor 2020-08-22 12:04:47 -07:00
ridiculousfish
65e1c42a2b topic_monitor to use binary semaphore instead of self-pipe
With the prior commit, the topic_monitor only writes to the pipe if a
thread is known to be waiting. This is effectively a binary semaphore, and
on systems that support anon semaphores (yes Linux, but not Mac) we can use
them. These are more efficient than self-pipes.

We add a binary_semaphore_t class which uses sem_t if sem_init succeeds,
and a self-pipe if it fails.

On Linux the seq_echo benchmark (run 1024 times) goes from 12.40 seconds to
11.59 seconds, about an 11% improvement.
2020-08-20 14:58:18 -07:00
ridiculousfish
c2da175f34 Use some fancy atomics in topic_monitor
The topic monitor is what allows a thread to wait for any of a set of
events. Events are identified by a bit in a "pending update" mask. Prior to
this fix, post() would atomically set the bit, and if it was newly set,
announce the change by unconditionally writing to a self-pipe. Threads
could wait for new posts by reading from the pipe.

This is less efficient than it could be; in particular if no thread is
waiting on the pipe, then the write() is unnecessary. This slows down our
signal handler.

Change the design in the following way: if a thread is committed to
waiting, then it atomically sets the "pending update" mask (now just called
status) to a sentinel value STATUS_NEEDS_WAKEUP. Then post() will only
write to the self-pipe if it sees that there is a thread waiting. This
reduces the number of syscalls.

The total effect is hardly noticeable (usually there is a thread waiting)
but it will be important for the next commit.
2020-08-20 14:55:37 -07:00
Johannes Altmanninger
19943576e4 fish_indent: preserve semis in if and while conditions
It could be nice to use a heuristic for this in future, but for now let's
stick to the old behavior so we can keep formatting scripts without occasional
bad formatting changes.

A heuristic could also be used to break lines after |, && or || but I don't
think there is much need for that at the moment.

Closes #7252
2020-08-17 17:40:28 +02:00
ridiculousfish
d50c0c2b85 Prevent certain 100% CPU loops
We weren't correctly updating the internal exit generation value. This
meant that if one internal process exits, every other internal process
that has not exited will continually check, leading to 100% CPU usage.

I think this mainly affects concurrent mode, but it may be reproducible
if you have a command which refuses to consume its input.
2020-08-16 12:56:42 -07:00
ridiculousfish
b0182183d4 Rework exit command
Prior to this fix, the `exit` command would set a global variable in the
reader, which parse_execution would check. However in concurrent mode you
may have multiple scripts being sourced at once, and 'exit' should only
apply to the current script.

Switch to using a variable in the parser's libdata instead.
2020-08-15 16:06:54 -07:00
ridiculousfish
a83dbec075 Remove reader_bg_job_warning
It was unused.
2020-08-14 16:29:42 -07:00
ridiculousfish
82fed6fc2f Correctly propagate signals from cancelled jobs into parse_execution_context
This concerns code like the following:

    while true ; sleep 100; end

Here 'while' is a "simple block execution" and does not create a new job,
or get a pgid. Each 'sleep' however is an external command execution, and
is treated as a distinct job. (bash is the same way). So `while` and
`sleep` are always in different job groups.

The problem comes about if 'sleep' is cancelled through SIGINT or SIGQUIT.
Prior to 2a4c545b21, if *any* process got a SIGINT or SIGQUIT, then fish
would mark a global "stop executing" variable. This obviously prevents
background execution of fish functions.

In 2a4c545b21, this was changed so only the job's group gets marked as
cancelled. However in the case of one job group spawning another, we
weren't propagating the signal.

This adds a signal to parse_execution_context which the parser checks after
execution. It's not ideal since now we have three different places where
signals can be recorded. However it fixes this regression which is too
important to leave unfixed for long.

Fixes #7259
2020-08-13 15:30:15 -07:00
ridiculousfish
1cf835e6e9 switch statements to respect fish_trace
Previously switch statements were not reported by fish_trace.
2020-08-13 14:36:48 -07:00
David Adam
70f51937d9 complete.cpp: correct a comment
[ci skip]
2020-08-13 16:03:15 +08:00
ridiculousfish
57102caba6 Remove the cursor position from highlighting
This used to be used to determine which token contained the cursor, so
as to highlight potential paths. But now we highlight all potential paths,
so we can remove the field.
2020-08-11 17:42:30 -07:00
ridiculousfish
84b9cc5c01 Factor reader's selection range into a new struct
The selection is used in vi visual mode. Previously it was four fields
embedded in the reader. Switch to a new struct wrapped in a maybe.
2020-08-11 14:29:52 -07:00
ridiculousfish
5c38c4f531 Stop caching indentation in the reader
In practice we didn't use the cache for anything. Always compute it on
demand.

This eliminates the 'indents' variable which had to be manually kept in
sync with the command line.
2020-08-11 13:41:19 -07:00
ridiculousfish
a6b8394114 Remove some debugging code which was accidentally left in 2020-08-11 13:11:48 -07:00
ridiculousfish
65f7f90433 Correctly highlight =s in var assignments after the first
We were not correctly offsetting the = in the token, it was always from the
start of the string.
2020-08-11 12:27:32 -07:00