Commit Graph

3352 Commits

Author SHA1 Message Date
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
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
ridiculousfish
703e6f571e Highlight the = in variable assignments as an operator 2020-08-10 16:41:56 -07:00
Fabian Homborg
7254dfecb2 fish_indent: Print the failed files with --check
Also return the number of failed files.

I decided to *just* print the filenames (newline-separated because
NULLs are annoying here) to make it easier to deal with.

See #7251.
2020-08-10 22:03:51 +02:00
ridiculousfish
8301aa9929 Add a test that nohup works
If fish is invoked with nohup, then its children should be nohup too.
2020-08-10 12:26:30 -07:00
David Adam
d8eb7fc46d fish: support -o short option correctly
Closes #7254.
2020-08-10 13:37:29 +08:00
ridiculousfish
aaa59d377e Remove a bunch of #ifdef'd out code 2020-08-09 15:06:50 -07:00
ridiculousfish
c1abb474c2 Remove some dead code and enable a test 2020-08-09 15:05:16 -07:00
Johannes Altmanninger
563a2d824c fish_indent: indent comments before line continuation
See #7252
2020-08-09 23:59:30 +02:00
Johannes Altmanninger
f8f32628a6 fish_indent: no extra newline at comment after pipe
Fixes the unstable case in #7252
2020-08-09 23:59:30 +02:00
ridiculousfish
f6c1ef58df Indent continuations after | and &&
This indents continuations after pipes and conjunctions if they contain
a newline.

Example:

    cmd1 &&
        cmd2

But it avoids the "double indent" if it indented unconditionally:

    cmd1 | begin
        cmd2
    end

More work towards improving #7252
2020-08-09 12:22:15 -07:00
ridiculousfish
9a53bf7d56 fish_indent: indent line continuations
For example:

    cmd \
        arg

Fixes one case from #7252
2020-08-09 12:22:14 -07:00
ridiculousfish
e2a26b2fdf fish_indent: Correct certain comment indenting
Prior to this change, when emitting gap text (comments, newlines, etc),
fish_indent would use the indentation of the text at the end of the gap.
But this has the wrong result for this case:

    begin
    command
    # comment
    end

as the comment would get the indent of the 'end'. Instead use the indent
computed for the gap text itself.

Addresses one case of #7252.
2020-08-09 12:22:05 -07:00
ridiculousfish
2676926902 Use unordered_map instead of map in lru
They have the same iterator invalidation guarantees, and unordered_map
benchmarks as faster for wcstring.
2020-08-08 15:32:06 -07:00
ridiculousfish
91955c1371 Don't eagerly fetch the current time in autoloading
The call to now() is not always necessary and shows up in traces.
2020-08-08 15:30:04 -07:00
ridiculousfish
68275e7f58 Simplify parser_keywords_is_reserved 2020-08-08 15:04:52 -07:00
Fabian Homborg
2cdd6df257 fish_indent: Add a "--check" option to only test indentation
Fixes #7251.
2020-08-08 20:23:14 +02:00
Fabian Homborg
103a4ece81 Add parens to silence warning
This triggered -Wparentheses in gcc 10.1.0
2020-08-08 09:14:47 +02:00
ridiculousfish
3dcb39f8ec Improve codegen of generation_list_t::operator==
Bizarrely comparing three integers showed up heavy in traces. This
reduces the time in seq_echo by about 500 msec.
2020-08-07 23:15:09 -07:00
ridiculousfish
5bee1e3e1f Avoid an errant copy in autoload_t::resolve_command
The ternary expression was causing the list of paths (e.g.
$fish_function_path) to be copied. Avoid that copy with an if statement.

This reduces the time spent in try_autoload from 2.4 sec to 961ms on
the seq_echo benchmark run 1024 times, about 5% improvement.

Oh, C++...
2020-08-07 22:34:42 -07:00
ridiculousfish
2cd336376e Refactor process_mark_finished_children
Reduce the level of nesting and the loop complexity.
2020-08-07 12:34:53 -07:00
ridiculousfish
26fda2bf0d Improve some formatting in proc.h 2020-08-07 11:38:47 -07:00
ridiculousfish
557fe57deb Close the file descriptor returned by mkstemp 2020-08-06 19:12:15 -07:00
ridiculousfish
206b2d0a26 Simplify topic monitoring
The topic monitor allows a client to wait for multiple events, e.g. sigchld
or an internal process exit. Prior to this change a client had to specify
the list of generations and the list of topics they are interested in.
Simplify this to just the list of generations, with a max-value generation
meaning the topic is not interesting.

Also remove the use of enum_set and enum_array, it was too complex for what
it offered.
2020-08-06 19:01:30 -07:00
Johannes Altmanninger
f7ef91ae2a Use mkstemp over mktemp to silence warning 2020-08-06 21:24:26 +02:00
Johannes Altmanninger
b947e360db Allow newlines after && and ||
We do the same for pipes (#1285). This matches POSIX sh behavior.
2020-08-06 21:24:26 +02:00
ridiculousfish
e6616d7017 Correct a misspeeling 2020-08-06 11:51:08 -07:00
Soumya
539e6fe8b1 Return no status from successful variable assignments 2020-08-05 12:23:49 -07:00
Soumya
8dd2d4f15d Change builtins to return maybe_t<int> instead of int 2020-08-05 12:23:49 -07:00
Soumya
a2b2bcef6e Add a $status_generation variable that's incremented for each interactive command that produces a status.
This can be used to determine whether the previous command produced a real status, or just carried over the status from the command before it. Backgrounded commands and variable assignments will not increment status_generation, all other commands will.
2020-08-05 12:23:49 -07:00
Johannes Altmanninger
8d3b66fb52 Reflow comment 2020-08-04 21:44:59 +02:00
Johannes Altmanninger
64601fd4d3 Reformat CPP files 2020-08-04 21:44:59 +02:00
ridiculousfish
81f9f51bcb Incorporate widecharwidth changes for narrow emoji
This pulls in widechar_width.h from commit 7e9dfdaf05059b3f. The big change
here is that some characters which were previously marked as widened in 9
are now marked as unconditionally narrow; this includes some randoms like
hot pepper (U+1F336) but more importantly all of the regional indicators,
which affects how flags are rendered.

If you put two regional indicators together, you get a flag emoji. It's
unclear what the width of this flag emoji should be; Terminal and iTerm2
renders it as width 1, while kitty renders it as width 2. This is
unaffected by fish_emoji_width because the flag does not have an assigned
codepoint, it is a pair of codepoints.

The regional indicators are marked as "neutral" in EastAsianWidth.txt which
means they conceptually have width 1. So two of them have width 2. So now
we assume that flags are rendered as width 2.

This fixes #7237, for terminals that render flags as width 2 (but not 1,
unfortunately, which includes iTerm2 and Terminal.app).
2020-08-04 12:40:46 -07:00
ridiculousfish
c9bcb52fe9 Pull in later widecharwidth
This pulls in widechar_width.h from commit d4e75d5bb1930291223d1.
This is a "rebuild with latest data" before we attempt a risky bugfix.
The idea here is that bisecting can separate whether any regression is
due to using the latest Unicode data, or the bug fix.
2020-08-04 12:21:33 -07:00
ridiculousfish
fc5067ca33 Fix an uninitialized variable warning on gcc 6 2020-08-04 11:01:31 -07:00
ridiculousfish
976ed6d2e8 Fix std::hash overload on g++ 6
Fixes a build error introduced in 6eab9275d0.
2020-08-04 10:56:14 -07:00
ridiculousfish
6eab9275d0 Cache resolved colors when outputting to the screen
Prior to this change, fish would "resolve" highlight specs to rgb colors
right before use. This requires a series of variable lookups; profiling
showed 30% of draw time was spent here.

Switch to caching these (within a single redraw only).
2020-08-03 17:34:27 -07:00
ridiculousfish
87d049edd8 Remove redirect_tty_output call from tcgetattr return
tcgetattr cannot return EIO.
2020-08-03 16:42:27 -07:00
ridiculousfish
f1402ac7a3 Eliminate some uses of current_data in the reader 2020-08-03 15:41:12 -07:00
ridiculousfish
272ca37582 Remove most dynamic reader configuration
Have the reader accept a constant configuration object, which controls
whether autosuggestions, etc. are enabled. These things don't change
dynamically.
2020-08-03 15:02:44 -07:00
ridiculousfish
fadd429348 Make the shell test function a toggle
We either perform fish syntax checking or we don't; there's no reason
to specify a function pointer here.
2020-08-03 14:31:09 -07:00
ridiculousfish
7304815736 Make shell highlighting a toggle instead of a function parameter
Remove the ability to specify the "highlight function." The reader
always highlights via shell highlighting, or doesn't.
2020-08-03 14:10:37 -07:00
ridiculousfish
18c7c46657 Remove highlight_universal
This was an attempt to offer syntax highlighting for `read` when shell
highlighting is not enabled, but it hardly did anything.
2020-08-03 13:41:41 -07:00
ridiculousfish
f94a6a74f0 Remove fish_color_match support
fish_color_match is a variable which controls syntax highlighting for
matching quotes and parens, but only with interactive `read` with shell
highlighting disabled. It seems unlikely that anybody cares about this.
2020-08-03 13:36:47 -07:00
Olivier FAURE
e7f0b5801d Add forward-single-char input command
This allows users to add custom keybindings to autocomplete only one
character at a time.

Resolves https://github.com/fish-shell/fish-shell/issues/4984
2020-08-01 12:09:31 +02:00
Olivier FAURE
6778d04aa5 Add or keybind input function 2020-08-01 12:09:31 +02:00
ridiculousfish
81a39be0bb Support explicitly separated output on stderr
In principle this would allow 'string split' or whatever to output to
stderr and not lose the item separation. In practice this is not used
but it fixes a TODO.
2020-07-30 23:00:34 -07:00
ridiculousfish
bcfc54fdaa Do not buffer builtin output if avoidable
builtins output to stdout and stderr via io_streams_t. Prior to this fix, it
contained an output_stream_t which just wraps a buffer. So all builtin output
went to this buffer (except for eval).

Switch output_stream_t to become a new abstract class which can output to a
buffer, file descriptor, or nowhere. This allows for example `string` to stream
its output as it is produced, instead of buffering it.
2020-07-30 22:45:44 -07:00
ridiculousfish
68092c5d21 Bravely have read_blocked return after first read
In commit fd6d814ea4, read_blocked was changed to read until EOF
or the full amount requested is returned. Switch this to returning
as soon as any data is available, which was the behavior prior to
fd6d814ea4.

This will allow builtin_string to output data in a "streaming"
fashion instead of needing to read a large block up-front.
2020-07-30 22:08:54 -07:00
ridiculousfish
81d5a3ea64 Do not add silent mode history items to history
Prior to this fix, if you invoked fish with --private and then used
`read --silent` to read something sensitive, the variable would be
stored in history, with the plain text available through up-arrow.
Fix it to not store items in silent mode.

Note the item was never written to disk; it was only stored in memory.

Fixes #7230
2020-07-30 20:26:01 -07:00
ridiculousfish
f7f35d2373 Fix a warning in fish_tests 2020-07-29 20:12:19 -07:00
ridiculousfish
2809d637db Introduce wwrite_to_fd
wwrite_to_fd() is a function which writes a wide string to a file
descriptor without performing any heap allocations.
2020-07-29 19:38:45 -07:00
ridiculousfish
a0cb23bea5 Introduce wcs2string_callback
This is like wcs2string, but instead of returning a std::string, it invokes
a user-supplied function with each converted character.

The idea is to allow interleaved conversion and output.
2020-07-29 19:36:20 -07:00
ridiculousfish
c9b42c6f1f Stop #include-ing wcstringutil.h in flog.h
This is a header dependency that we can break.
2020-07-29 17:04:18 -07:00
ridiculousfish
db086fc5d4 Eliminate wcs2str
Use std::string variants everywhere instead
2020-07-29 16:37:39 -07:00
ridiculousfish
e4b1fc9f6a Remove stdout_read_limit param from exec_process_in_job
This can always be trivially fetched from the parser - no need to pass it
in separately.
2020-07-29 16:04:29 -07:00
ridiculousfish
3506274ccf Make in_foreground an explicit param to continue_job
This moves us slightly closer towards fish code in the background. The idea is
that a background job may still have "foreground" sub-jobs, example:

    begin ; sleep 5 ; end &

The begin/end job runs in the background but should wait for `sleep`.

Prior to this fix, fish would see the overall job group is in the background
and not wait for any of its processes. With this change we detach waiting from
is_foreground.
2020-07-27 15:56:24 -07:00
ridiculousfish
3382bc70d2 Fix a stale comment
[ci skip]
2020-07-27 15:36:43 -07:00
ridiculousfish
c35fe879c7 Bravely remove reclaim... param from continue_job, and rework tcsetpgrp calls
This changes how fish attempts to protect itself from calling tcsetpgrp() too
aggressively. Recall that tcsetpgrp() will "force" itself, if SIGTTOU is
ignored (which it is in fish when job control is enabled).

Prior to this fix, we avoided SIGTTINs by only transferring the tty ownership
if fish was already the owner. This dated from a time before we had really
nailed down how pgroups should be assigned. Now we more deliberately assign a
job's pgroup so we don't need this conservative check.

However we still need logic to avoid transferring the tty if fish is not the
owner. The bad case is when job control is enabled while fish is running in the
background - here fish would transfer the tty and "steal" from the foreground
process.

So retain the checks of the current tty owner but migrate them to the point of
calling tcsetpgrp() itself.
2020-07-27 14:51:37 -07:00
ridiculousfish
1823f5d95f Remove the send_sigcont from continue_job
We can just send sigcont if the job is stopped; no need to make this an
explicit param.
2020-07-27 10:48:32 -07:00
ridiculousfish
6d77a93cc2 Improve commenting in exec_job
[ci skip]
2020-07-26 10:45:02 -07:00
Mahmoud Al-Qudsi
d46b9ff9be Remove repeated acquire of disowned pid lock in a loop 2020-07-25 20:45:08 -05:00
David Adam
2720f3d2ef proc: disown PIDs, not just PGIDs
add_disowned_pgid skipped jobs that have a PGID equal to the running
process. However, this includes processes started in config.fish or when
job control is turned off, so they never get waited on.

Instead, refactor this function to add_disowned_job, and add either the PGID or
all the PIDs of the job to the list of disowned PIDs/PGIDs.

Fixes #7183.
2020-07-25 20:38:59 -05:00
David Adam
025a0d3cf5 proc: add log message for reaped disowned IDs 2020-07-25 20:35:54 -05:00
ridiculousfish
bae64f8a8a Modest cleanup of profiling
This is a set of miscellaneous cleanup for profiling.

An errant newline has been removed from 'if' statement output, which got
introduced with the new ast.
Switch from storing unique_ptr to a deque, which allocates less.
Collapse "parse" and "exec" times into just a single value "duration". The
"parse" time no longer makes sense, as we now parse ahead of time.
2020-07-24 11:53:07 -07:00
ridiculousfish
7d2d2c97b2 Fix a compiler warning in builtin_printf 2020-07-19 16:51:11 -07:00
ridiculousfish
54b642bc6f Factor job groups into their own file
Migrate out of proc.h, which has become too long.
2020-07-19 16:42:29 -07:00
ridiculousfish
56e250d467 Remove a commented-out field 2020-07-19 15:48:16 -07:00
Johannes Altmanninger
b3485d2457 Have the pager use the correct prefix for case-corrected completions
Follow-up to 28d67c8f which only fixed inserting such completions.
2020-07-20 00:38:01 +02:00
Johannes Altmanninger
a61e97a8b9 Fix case-correcting completion stomping token on common prefix
The prefix has already been case-corrected at this point and the remaining
completions are for the suffix only.

Fixes #7211

Introduced in
28d67c8f Show completion list on Tab also if a common prefix was inserted
2020-07-19 23:40:07 +02:00
ridiculousfish
dff4f140b0 Make the list of blocked events const
These are events that have been queued but not yet fired. There's no
reason to modify the events after creating them. Mark them as const
to ensure that doesn't happen.
2020-07-19 12:03:10 -07:00
ridiculousfish
7f8c00c20a Remove job_t::wants_terminal
This now lives in the job group, not individual jobs.
2020-07-18 12:42:44 -07:00
ridiculousfish
ba8b89873e Teach a job its command at constructor time
No point in allowing this to be set later.
2020-07-18 12:42:44 -07:00
ridiculousfish
f30ce21aaa terminal_maybe_give_to_job to operate on groups, not jobs
Assigning the tty is really a function of a job group, not an individual
job. Reflect that in terminal_maybe_give_to_job_group and also
terminal_return_from_job_group.
2020-07-18 12:42:44 -07:00
ridiculousfish
40c9bda7fd Store the command that produced a job group in the group
This will enable us to replace more uses of jobs with job groups.
2020-07-18 12:42:44 -07:00
ridiculousfish
3571754e06 Only perform universal barriers for the principal env stack
In practice this means that, if fish ever gets multiple variable stacks,
we will only incorporate environment variable changes from other fish
instances on the "main thread."
2020-07-16 16:16:03 -07:00
ridiculousfish
352062219d More clean up of parse_util_detect_errors_in_argument 2020-07-14 15:51:12 -07:00
ridiculousfish
3532a955a6 Use parse_util_locate_cmdsubst_range when validating arguments
Removes another usage of parse_util_locate_cmdsubst().
2020-07-14 15:34:26 -07:00
ridiculousfish
68d256a91c Use parse_util_locate_cmdsubst_range in highlighting 2020-07-14 15:27:14 -07:00
ridiculousfish
9cade52c77 Clean up expand_cmdsubst somewhat
Eliminate some of the pointer arithmetic and switch to
parse_util_locate_cmdsubst_range. It's still a pretty ugly function.
2020-07-14 15:19:10 -07:00
ridiculousfish
37dc554fe1 Revert "Remove unnecessary owning_lock usages"
This reverts commit 3a5585df95.

This reverts a change that removed a lock. It's indeed true that in master,
fish script is bound to the main thread. But I'm working to remove that
limitation and these locks are important in that future.
2020-07-12 18:56:39 -07:00
ridiculousfish
4904e4bc41 Fix autosuggestion validation
When switching to the new ast, commands that were not decorated
statements (like function declarations) would be rejected from
autosuggestion validation because we could not find a command. Stop
rejecting them.
2020-07-12 18:47:33 -07:00
Mahmoud Al-Qudsi
3a5585df95 Remove unnecessary owning_lock usages
The owning locks were added after the original code and decorated with
comments indicating they are thread-safe, even though they're only ever
used from the main thread. Presuming the intent was to make future
manipulation of the code safer rather than to actually make use of any
thread safety guarantees, these have been wrapped in a new
`thread_exclusive` type which always calls ASSERT_IS_MAIN_THREAD.

The benefit is that this does not perform a syscall to lock a mutex
each time the variables are accessed.
2020-07-12 20:21:28 -05:00
Mahmoud Al-Qudsi
6d45dd837f Remove trailing ", " in functions output
When executed interactively and not piped, `functions` adds a comma as a
separator between each result. This removes the separator after the last
item.
2020-07-12 19:14:35 -05:00
Mahmoud Al-Qudsi
f1951fed3a Fix suggestionOK variable name 2020-07-12 19:14:35 -05:00
Mahmoud Al-Qudsi
73bf9dd784 Stop calling path_get_path for builtins and functions
highlight.cpp was blindly calling path_get_path for each head command
typed at the prompt which triggers a lot of syscalls via waccess.

It's still going to do that while commands are being composed, but now
it won't if we can make a cheap lookup to the builtins/functions hash
table and can determine that it's a valid command before inspecting the
filesystem.
2020-07-12 19:14:35 -05:00
ridiculousfish
3319e308d0 Make ast::node_t non-virtual
Eliminate its vtable to save 8 bytes per node, which is a lot!
2020-07-12 16:57:30 -07:00
ridiculousfish
a8eb2a6813 Make union_ptr_t's constructor statically type safe
Ensure it cannot be constructed from the wrong node type.
2020-07-12 16:57:30 -07:00
ridiculousfish
8d37be2916 ast lists to use new[] instead of vector
Because the list is not changed after construction, we do not need
the vector's capacity field. This reduces the size of lists from 48
to 32 bytes.
2020-07-12 16:57:30 -07:00
ridiculousfish
c12ab7a674 Rearrange ast::node_t fields to improve packing 2020-07-12 16:57:30 -07:00
ridiculousfish
487de1e6c3 Reduce copying in parse_util_detect_errors
Allow parse_util_detect_errors to accept an already-parsed ast. This
eliminates a copy of the source, which is helpful when executing large
scripts.
2020-07-12 16:57:30 -07:00
ridiculousfish
dfeec433d8 Reduce allocation churn in parse_util_detect_errors
Reuse a single string for storage.
2020-07-12 16:57:30 -07:00
ridiculousfish
9ee5075fc3 Reformat CPP files 2020-07-12 12:21:25 -07:00
ridiculousfish
2a4c545b21 Rework how signals trigger cancellation
When fish receives a "cancellation inducing" signal (SIGINT in particular)
it has to unwind execution - for example while loops or whatever else that
is executing. There are two ways this may come about:

1. The fish process received the signal
2. A child process received the signal

An example of the second case is:

    some_command | some_function

Here `some_command` is the tty owner and so will receive control-C, but
then fish has to cancel function execution.

Prior to this change, these were handled uniformly: both would just set a
cancellation signal inside the parser. However in the future we will have
multiple parsers and it may not be obvious which one to set the flag in.
So instead distinguish these cases: if a process receives SIGINT we mark
the signal in its job group, and if fish receives it we set a global
variable.
2020-07-12 12:16:01 -07:00
ridiculousfish
12d0afa929 Fix some build warnings in fish_tests 2020-07-12 11:41:06 -07:00