Commit Graph

136 Commits

Author SHA1 Message Date
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
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
ridiculousfish
68d256a91c Use parse_util_locate_cmdsubst_range in highlighting 2020-07-14 15:27:14 -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
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
9ee5075fc3 Reformat CPP files 2020-07-12 12:21:25 -07:00
ridiculousfish
225470493b Make parse_token_type_t an enum class
Improves type safety.
2020-07-09 14:22:04 -07:00
ridiculousfish
35cb449aa1 Make parse_statement_decoration_t a class enum 2020-07-07 16:28:39 -07:00
ridiculousfish
8d9725c301 Adopt the new AST in highlighting
This switches syntax highlighting from parsing with parse_tree to the new
ast.
2020-07-04 14:58:05 -07:00
Rosen Penev
0668513138 Change C casts to C++ ones
Some were kept for compatibility.

Found with -Wold-style-cast

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-05-01 13:30:56 -07:00
Johannes Altmanninger
0fb58ab625 highlight: normalize path when validating path for cd
As builtin cd does.

Fixes #6915.
2020-04-19 07:01:25 +02:00
Fabian Homborg
1406d63b85 Restyle
I kinda hate how fussy clang-format is. It reflows text
constantly (line limit), forces things onto one line *except* when
they're too long, and wants to turn this:

```c++
    return true;;
```

into this:

```c++
    return true;
    ;
```

instead of, you know, eliminating the second semicolon?

Anyway, it is what it is and we use it, I'll just look into getting some
more slack.
2020-03-26 20:45:40 +01:00
Johannes Altmanninger
64a89f882d Fix directory highlighting with custom CDPATH
Reproduce: `set CDPATH . /usr; mkdir foo` Then type "cd foo" and notice
that foo is highlighted incorrectly, because there is no /usr/foo.
2020-03-25 20:36:58 +01:00
ridiculousfish
f6e5a5c521 Thread a cancellation function into is_potential_path
Allows sooner cancellation of redundant operations like highlighting.
2020-03-02 22:10:43 -08:00
ridiculousfish
a65e3f1876 Check for cancellation more often in highlighting 2020-03-02 22:02:03 -08:00
Rosen Penev
aae9ebfbd4 [clang-tidy] use using instead of typedef
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:16 +01:00
Fabian Homborg
3bb15defbb
Replace debug() with flog
PR #6511 

Flog has the advantage of having *categories*, not severities, so it'll be easier to get output for a certain subsystem now.
2020-01-26 14:13:17 +01:00
ridiculousfish
2af710f7c0 Eliminate expand_result_t::wildcard_match
This was an internal implementation detail that all callers had to deal
with. Just get rid of it.
2020-01-22 11:49:59 -08:00
Fabian Homborg
349b9e9dee Remove commented out debugs 2020-01-19 14:54:53 +01:00
ridiculousfish
0f7bba5f0e Introduce operation_context_t
This commit recognizes an existing pattern: many operations need some
combination of a set of variables, a way to detect cancellation, and
sometimes a parser. For example, tab completion needs a parser to execute
custom completions, the variable set, should cancel on SIGINT. Background
autosuggestions don't need a parser, but they do need the variables and
should cancel if the user types something new. Etc.

This introduces a new triple operation_context_t that wraps these concepts
up. This simplifies many method signatures and argument passing.
2020-01-16 15:21:28 -08:00
ridiculousfish
6705a2efc6 Migrate a bunch of code out of common.h
Put it into wcstringutil, path, or a new file null_terminated_array.
2020-01-15 13:16:43 -08:00
Johannes Altmanninger
3de95038b0 Make "time" a job prefix
In particular, this allows `true && time true`, or `true; and time true`,
and both `time not true` as well as `not time true` (like bash).

time is valid only as job _prefix_, so `true | time true` could call
`/bin/time` (same in bash)

See discussion in #6442
2020-01-03 01:07:49 -06:00
Rosen Penev
6f4a9d527c [clang-tidy] Use C++ using instead of C typedef
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
586ac3dfa7 [clang-tidy] Convert loops to range based
Found with modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:50:40 -08:00
Rosen Penev
1055ff321c [clang-tidy] Replace NULL with nullptr
Found with modernize-use-nullptr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
Rosen Penev
0dfa7421f3 [clang-tidy] Convert C casts to C++ ones
Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
Johannes Altmanninger
7d5b44e828 Support FOO=bar syntax for passing variables to individual commands
This adds initial support for statements with prefixed variable assignments.
Statments like this are supported:

a=1 b=$a echo $b        # outputs 1

Just like in other shells, the left-hand side of each assignment must
be a valid variable identifier (no quoting/escaping).  Array indexing
(PATH[1]=/bin ls $PATH) is *not* yet supported, but can be added fairly
easily.

The right hand side may be any valid string token, like a command
substitution, or a brace expansion.

Since `a=* foo` is equivalent to `begin set -lx a *; foo; end`,
the assignment, like `set`, uses nullglob behavior, e.g. below command
can safely be used to check if a directory is empty.

x=/nothing/{,.}* test (count $x) -eq 0

Generic file completion is done after the equal sign, so for example
pressing tab after something like `HOME=/` completes files in the
root directory
Subcommand completion works, so something like
`GIT_DIR=repo.git and command git ` correctly calls git completions
(but the git completion does not use the variable as of now).

The variable assignment is highlighted like an argument.

Closes #6048
2019-11-25 09:20:51 +01:00
ridiculousfish
87f4f33600 Remove vars parameter from function_exists_no_autoload
This variable was unused.
2019-11-10 13:13:56 -08:00
ridiculousfish
151e75d141 Autosuggestions to validate the first command, not the last command
When considering an autosuggestion from history, we attempt to validate the
command to ensure that we don't suggest invalid (e.g. path-dependent)
commands. Prior to this fix, we would validate the last command in the
command line (e.g. in `cd /bin && ./stuff` we would validate "./stuff".
This doesn't really make sense; we should be validating the first command
because it has the potential to change the PWD. Switch to validating the
first command.

Also remove some helper functions that became dead through this change.
2019-11-02 13:40:31 -07:00
ridiculousfish
35671dd9f0 Clean up and unify pipes and redirections
This cleans up how pipes and redirections are recognized by the parser,
and unifies pipes and redirections into a single type.
2019-10-15 11:26:41 -07:00
ridiculousfish
82eca4bc86 Run clang-format on all files
The main change here is to reorder headers.
2019-10-13 15:50:48 -07:00
Aaron Gyes
cb79d8fa97 Colorize complete output
If interactive, `complete` commands are highlighted like they would
be if typed. Adds a little fun contrast and it's easier to read.

Moved a function out of fish_indent to highlight.h
2019-09-19 04:27:33 -07:00
Johannes Altmanninger
0ecfc25961 Fix highlighting of redirection to - (close file descriptor)
Fixes #6092
2019-09-14 13:04:27 -05:00
ridiculousfish
822b53c67a Don't color a whole string invalid because of an unclosed quote
When syntax highlighting a quoted string, if the string is not closed,
only show the opening quote as an error, not the whole string.
2019-07-24 12:43:47 -07:00
ridiculousfish
c0053ceef5 highlighter_t to return color array directly
Saves some copying and allocations.
2019-07-24 12:42:18 -07:00
Dawid Dziurla
0b3bb0e7c1 Underline every valid entered path (#5872)
* src/highlight: Underline every valid entered path

* update CHANGELOG

* fix highlight test
2019-05-19 10:03:56 +02:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
ridiculousfish
bffacd2fbf Thread a parser into expansion
Expansion may perform command substitution, which needs to know the parser
to use.
2019-05-04 19:30:00 -07:00
ridiculousfish
496529b20a Remove EXPAND prefix from expand_flags and lowercase them 2019-04-25 11:34:49 -07:00
ridiculousfish
d8ab6290e8 Switch expand_flags_t to enum_set 2019-04-25 11:23:03 -07:00
ridiculousfish
dcaac58f45 Rename expand_error_t to expand_result_t and make it class enum
Also lowercase it all.
2019-04-25 10:47:28 -07:00
ridiculousfish
a173c079d5 expand_abbreviation to always accept an environment_t
Now that snapshotting is fixed, we don't need to get the principal
environment stack any more.
2019-04-16 22:45:58 -07:00
Aaron Gyes
477b2e8d7c std::vector<wcstring> is wcstring_list_t 2019-03-14 11:17:26 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
ridiculousfish
717ac9a8d5 Switch highlight_spec_t to a struct
Rather than a janky bitmask, use a real struct with real fields.
2019-03-03 18:04:22 -08:00
ridiculousfish
d165d1df27 Remove highlight_modifier_sloppy_background
It's no longer ever set
2019-03-03 17:56:08 -08:00
Dan Zimmerman
50448e4319 Enable configuring more pager colors
Originally I sought out to configure the foreground color of the
selected text in the pager. After reading a thread on a github issue I
was inpired to do more: now you can conifgure any part of the pager when
selected, and when a row is secondary. More specifically this commit adds the
ability to specify a pager row's:

- Prefix
- Completion text
- Description
- Background

when said row is selected or secondary.
2019-01-26 15:43:23 -08:00