Commit Graph

2168 Commits

Author SHA1 Message Date
ridiculousfish
b7fceddfc8 Refactor some environment code into env_dispatch.cpp
This new file is supposed to encapsulate all of the logic around
reacting to variable changes, as opposed to the environment core.
This is to help break up the env.cpp monolith.
2019-04-08 16:22:04 -07:00
Aaron Gyes
e5362a4ae5 wutil.cpp: fixup: don't involve the uninitialized parameter 2019-04-08 16:02:00 -07:00
Aaron Gyes
8eb05f8731 parse_execution.cpp: validate 'for' variable name
Fixes #5800
(that's a nice round number)
2019-04-08 11:23:00 -07:00
Aaron Gyes
dd9a26715d fcntl a little less
Setting O_CLOEXEC on closed file descriptors and getting E_BADF
should be faster than actually checking if an fd is open first.
2019-04-08 11:23:00 -07:00
ridiculousfish
bf40f84b06 Remove an unused variable 2019-04-07 15:07:36 -07:00
ridiculousfish
f5bb8639d6 More aggressively inherit pgrps from parent jobs
Prior to this fix, a job would only inherit a pgrp from its parent if the
first command were external. There seems to be no reason for this
restriction and this causes tcsetgrp() churn, potentially cuasing SIGTTIN.
Switch to unconditionally inheriting a pgrp from parents.

This should fix most of #5765, the only remaining question is
tcsetpgrp from builtins.
2019-04-07 13:35:00 -07:00
ridiculousfish
39a9740997 Be less aggressive about reclaiming the foreground pgrp
Prior to this fix, in every call to job_continue, fish would reclaim the
foreground pgrp. This would cause other jobs in the pipeline (which may
have another pgrp) to receive SIGTTIN / SIGTTOU.

Only reclaim the foreground pgrp if it was held at the point of job_continue.

This partially addresses #5765
2019-04-07 09:20:32 -07:00
ridiculousfish
23d88e0e03 Add fish_test_helper executable
In tests we would like to arrange for an executable to invoke certain
system calls, e.g. to claim or relinquish control of the terminal. This is
annoying to do portably via e.g. perl. fish_test_helper is a little
program where we can add custom commands to make it act in certain ways.
2019-04-07 09:20:19 -07:00
Aaron Gyes
4e555aebec Remove is_whitespace and whitespace character string declarations
I don't doubt such functions and character arrays could be useful,
to keep things consistent, but they are not actually being used.
2019-04-06 02:07:56 -07:00
Fabian Homborg
2a3677b386 Stop setting term-modes early
This set the term modes to the shell-modes, including disabling
ICRNL (translating \cm to \cj) and echo.

The rationale given was that `reader_interactive_init()` would only be
called >= 250ms later, which I _highly_ doubt considering fish's total
startup time is 8ms for me.

The main idea was that this would stop programs like tmuxinator that
send shortcuts early from failing _iff_ the shortcut was \cj, which
also seems quite unusual.

This works both with `rm -i` and `read` in config.fish, because `read`
explicitly calls `reader_push`, which then initializes the shell modes.

The real fix would involve reordering our init so we set up the
modesetting first, but that's quite involved and the remaining issue
should barely happen, while it's fairly common to have issues with a
prompt in config.fish, and the workaround for the former is simpler, so let's leave it for now.

Partially reverts #2578.

Fixes #2980.
2019-04-05 12:55:13 +02:00
Aaron Gyes
be80a56ad4 expand.cpp: use wcspbrk for is_quotable 2019-04-04 17:32:39 -07:00
Aaron Gyes
b4ddd797e3 remove unused wcstring 2019-04-04 14:24:36 -07:00
Aaron Gyes
b064eaa571 use std::move in a couple spots where things were unsed after copy 2019-04-04 14:16:34 -07:00
Aaron Gyes
09e8f0fd7c rearrange structure fields
Putting larger members before smaller ones will reduce structure
sizes. bools are 1 byte. on 64bit systems I think they reduced:

wgetopt.h:46: 64 to 56 bytes
builtin_history.cpp:30: 48 to 32 bytes
builtin_status.cpp:91: 32 to 24 bytes
tinyexpr.cpp:69: 40 to 32 bytes
2019-04-04 13:47:10 -07:00
Mahmoud Al-Qudsi
bc66921ac9 Optimize keyword detection
The data stored in these containers is small enough that it is worth
creating distinct sets for each lookup.

In a microbenchmark of these changes, the single-lookup version of the
function with lookups gated on the length of input (bypassed entirely if
the input is longer than the longest key in the container) provided a
1.5x-3.5x speedup over the previous implementation.

Additionally, as the collections are static and their contents are never
modified after startup, it makes no sense to continously calculate the
location of and allocate an iterator for the `!= foo.end()` comparison;
the end iterator is now statically cached.

I'm not expecting massive speed gains out of this change, but the parser
does perform enough of these to make it worth optimizing in this way.
2019-04-03 20:53:29 -05:00
ridiculousfish
dd007c29f4 Revert "parser: try to avoid some strings being copied"
This reverts commit 7a74198aa3.

Believe it or not this commit actually increased copying. When accepting
a value you know you're going to take ownership of, just accept it by
value; then temporaries can invoke the move ctor and blah blah blah.

We really need a lightweight refcounted pass-by-value string to make this
less error prone.
2019-04-01 20:22:02 -07:00
Fabian Homborg
99dd6d7394 Let repaint-mode act like a repaint if no fish_mode_prompt exists
Otherwise I'm pretty sure we'd get complaints from people who use a
mode-indicator elsewhere in their prompts.
2019-04-01 16:04:14 +02:00
Fabian Homborg
8ff866b26b Add repaint-mode bind function
If we switch the bind mode, we add a "force-repaint" there just to
redraw the mode indicator.

That's quite wasteful and annoying, considering that sometimes the prompt can take
half a second.

So we add a "repaint-mode" function that just reexecutes the
mode-prompt and uses the cached values for the others.

Fixes #5783.
2019-04-01 15:59:39 +02:00
Fabian Homborg
da1b32f0ad
Remove option to use system wcwidth (#5777)
As it turns out it didn't work much better, and it fell behind in
support when it comes to things that wcwidth traditionally can't
express like variation selectors and hangul combining characters, but
also simply $fish_*_width.

I've had to tell a few people now to rebuild with widecharwidth after
sending them on a fool's errand to set X variable.

So keeping this option is doing our users a disservice.
2019-04-01 15:59:33 +02:00
Fabian Homborg
0d72912641
Expand abbr explicitly (#5762)
* Add "expand-abbr" bind function

This can be used to explictly allow expanding abbreviations.

* Make expanding abbr explicit

NOTE: This accepts them for space only, we currently also do it for \n
and \r.

* Remove now dead code

We no longer trigger an abbr implicitly, so we can remove the code
that does it.

* Fix comment

[ci skip]
2019-04-01 15:59:15 +02:00
Mahmoud Al-Qudsi
eb2d829bc5 Use explicit lock.exchange()
There's really no point in using std::atomic if we're not going to
actually guarantee the entire read & write process is atomic.
2019-03-31 18:17:33 -05:00
Mahmoud Al-Qudsi
b5b9406711 Use explicit atomic/CAS to prevent race conditions
They are probably equivalent on x86/64 being single-byte reads/writes,
but it never hurts to be safe.
2019-03-31 18:09:59 -05:00
Mahmoud Al-Qudsi
3c537bfa65 Optimize get_deferred_process() traversal 2019-03-31 13:20:49 -05:00
ridiculousfish
0aa0dceeb3 End coalescing repaints on check-exits
Hopeful fix for #5766
2019-03-29 20:56:23 -07:00
ridiculousfish
0b11b8cffb Revert "Optimize identification of deferred process"
This reverts commit 4aea4c09b3.

Said commit broke many tests
2019-03-28 20:22:58 -07:00
Mahmoud Al-Qudsi
4aea4c09b3 Optimize identification of deferred process 2019-03-28 22:12:50 -05:00
Mahmoud Al-Qudsi
f8b2e818ed Remove legacy generic process/job exit events 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
7f5e58ae69 Only send JOB_EXIT after the job has been actually erased 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
06adb1dc38 Store jobs to erase in separate list 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
36f3a6d7e0 Use const auto for all jobs 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
d4d5c03a03 Clean up invalid job id detection in fg builtin 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
1f59976c2c Further clean up job list manipulation 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
6fab783647 Convert job_list to a dequeue again
Now that we have cleaned up access to the job list and removed
transparent invalidation of iterators, it is safe to convert it to a
dequeue.
2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
f8e0e0ef82 Remove abstractions around job list
Directly access the job list without the intermediate job_iterator_t,
and remove functions that are ripe for abuse by modifying a local
enumeration of the same list instead of operating on the iterators
directly (e.g. proc.cpp iterates jobs, and mid-iteration calls
parser::job_remove(j) with the job (and not the iterator to the job),
causing an invisible invalidation of the pre-existing local iterators.
2019-03-28 18:55:36 -05:00
Fabian Homborg
42acbaa5af Remouve ouveroused U
Webster was right, gosh dang it!

[ci skip]
2019-03-28 12:31:52 +01:00
ridiculousfish
5441ebc91f Remove some dead code 2019-03-28 00:38:12 -07:00
Fabian Homborg
785945c861 src/builtin_test: Print backtrace on error
`test` is a common source of problems, and with the current system
they can be quite hard to find.

So we print a backtrace with line numbers and all.
2019-03-28 08:35:32 +01:00
Fabian Homborg
d8ec4685ff src/builtin_test: Remove weird leading tab from error message
This is a remainder from when we used to speak of "eval errors".
2019-03-28 08:35:32 +01:00
Fabian Homborg
7fa454666d Only append newline if stacktrace isn't empty
This printed weird things like

```fish
$ functions -x
functions: Unknown option '-x'

(Type 'help functions' for related documentation)
```

Instead, let's make it

```fish
$ functions -x
functions: Unknown option '-x'
(Type 'help functions' for related documentation)
```
2019-03-26 19:32:18 +01:00
Fabian Homborg
88d2d54276 Stop printing help summary on error
This now displays

- the error message

- a (significantly shorter) backtrace

- A call to open `help $cmd` if necessary

See #5434.
Fixes #3404.
2019-03-26 19:24:48 +01:00
Fabian Homborg
88a935d8d1 Escape arguments in stacktraces
See #5434.
2019-03-26 17:45:25 +01:00
Fabian Homborg
7095de628c Remove "called on standard input" message
This was printed basically everywhere.

The user knows what they executed on standard input.

A good example:

```fish
set c (subme 513)
```

used to print

```
fish: Too much data emitted by command substitution so it was discarded

    set -l x (string repeat -n $argv x)
             ^
in function 'subme'
	called on standard input
	with parameter list '513'
in command substitution
	called on standard input
```

and now it is

```
fish: Too much data emitted by command substitution so it was discarded

    set -l x (string repeat -n $argv x)
             ^
in function 'subme' with arguments '513'
in command substitution
```

See #5434.
2019-03-26 17:38:41 +01:00
Fabian Homborg
975023faf2 Print arguments on the same line as the function
Now:

```
cd: Unknown option '-r'
~/dev/fish-shell/share/functions/cd.fish (line 40):
    builtin cd $argv
    ^
in function 'cd' with arguments '-r'
in function 'f'
in function 'd'
in function 'b' with arguments '-1q --wurst'
in function 'a'
	called on standard input
```

See #5434.
2019-03-26 17:37:16 +01:00
Fabian Homborg
e723f02aa7 Remove empty line also for event handlers 2019-03-26 17:18:25 +01:00
Fabian Homborg
39a601927f Remove useless empty lines from stack traces
This printed things like

```
in function 'f'
        called on standard input

in function 'd'
        called on standard input

in function 'b'
        called on standard input

in function 'a'
        called on standard input

```

As a first step, it removes the empty lines so it's now

```
in function 'f'
        called on standard input
in function 'd'
        called on standard input
in function 'b'
        called on standard input
in function 'a'
        called on standard input
```

See #5434.
2019-03-26 16:47:42 +01:00
Fabian Homborg
b86200938f Always use "." for cd
Nobody doesn't want to use $PWD to cd, so if $CDPATH does not include
it that was a mistake.

Bash also appends "." here.

Fixes #4484.
2019-03-26 10:11:36 +01:00
ridiculousfish
eeec6cc2fc Remove a single use of env_stack_t::principal 2019-03-25 02:27:02 -07:00
ridiculousfish
989f992a75 Rearrange and inline some env code 2019-03-25 00:49:52 -07:00
ridiculousfish
ea3a368c50 Make env_var_t store its values via shared_ptr
This switches env_var_t to be an immutable value type, and stores its
contents via a shared_ptr. This eliminates string copying when fetching
env_var_t values.
2019-03-25 00:41:04 -07:00
ridiculousfish
5eade35257 Stop buffering deferred function processes
If a function process is deferred, allow it to be unbuffered.
This permits certain simple cases where functions are piped to external
commands to execute without buffering.

This is a somewhat-hacky stopgap measure that can't really be extended
to more general concurrent processes. However it is overall an improvement
in user experience that might help flush out some bugs too.
2019-03-24 21:23:26 -07:00
ridiculousfish
3bbee06248 Introduce the notion of a deferred process
In a job, a deferred process is the last fish internal process which pipes
to an external command. Execute the deferred process last; this will allow
for streaming its output.
2019-03-24 14:27:23 -07:00
ridiculousfish
165c82e68a Promote process_type_t to an enum class 2019-03-24 12:29:25 -07:00
ridiculousfish
96b8ac7013 Promote job_control_t to an enum class 2019-03-24 12:12:44 -07:00
ridiculousfish
71f26a6813 Remove INPUT_COMMON_BASE
We no longer store readline commands as characters, so there's no need to
reserve character space for them.
2019-03-23 23:31:37 -07:00
ridiculousfish
e7d7eff0ee Rename all readline commands to lowercase and remove R_ prefix 2019-03-23 23:31:35 -07:00
ridiculousfish
9187458d51 Continued refactoring of reader_data_t::readline 2019-03-23 23:31:34 -07:00
ridiculousfish
6ba94fd81b Factor readline command handling into new function handle_readline_command() 2019-03-23 23:31:33 -07:00
ridiculousfish
42f4d2bd86 Factor out the "read coalescing" part of reader_data_t::readline 2019-03-23 23:31:31 -07:00
ridiculousfish
7ae7865071 Factor reader_data_t::readline state into a new struct
Will help break up this monster.
2019-03-23 23:31:29 -07:00
ridiculousfish
6aba28ad3d Add missing cases to readline loop
Handle all readline commands in our switch.
2019-03-23 23:31:27 -07:00
ridiculousfish
2c56e27d37 Switch readline commands to readline_cmd_t enum class 2019-03-23 23:31:25 -07:00
ridiculousfish
0841072462 Minor cleanup of kill ring 2019-03-23 23:31:24 -07:00
ridiculousfish
b68d3b84de Switch input_function_get_code() to return maybe_t 2019-03-23 23:31:22 -07:00
ridiculousfish
c2be5e8986 Introduce char_event_type_t::readline
Baby steps towards eliminating readline actions as characters.
2019-03-23 23:31:18 -07:00
ridiculousfish
14663089c8 Finish removing R_NULL 2019-03-23 23:31:09 -07:00
ridiculousfish
28b79a2c88 Some further steps towards removing R_NULL
Introduce char_event_type_t::check_exit to represent "check for exit"
instead of R_NULL.
2019-03-23 23:31:01 -07:00
ridiculousfish
70a92a9710 Switch interrupt_handler to return maybe_t<char_event_t>
Prepares to remove R_NULL
2019-03-23 23:13:19 -07:00
ridiculousfish
1ef2404e1c readb to return char_event_t
Avoids some annoying type conversions.
2019-03-23 23:12:50 -07:00
ridiculousfish
46dfad52d9 Switch the input interrupt function to return maybe_t
Allow returning none() to mean do nothing.
2019-03-23 23:12:12 -07:00
ridiculousfish
1e5c1c82c7 Rename and simplify input_read_characters_eof_only
Clarify its role.
2019-03-23 23:11:45 -07:00
ridiculousfish
00f24695fe Remove R_EOF
Promote R_EOF to a new char_event_type_t instead of keeping it as a char
value.
2019-03-23 23:11:23 -07:00
ridiculousfish
185805641c Remove R_TIMEOUT
Promote timeout to a char_event_type_t, moving it out of the "char" namespace.
This will help simplify the readline implementation.
2019-03-23 20:10:06 -07:00
Aaron Gyes
a2a9709fd9 Don't truncate hostnames over 32 characters
I believe this was selected to be artificially low for the sake
of it displaying well in prompts. But people should expect to get
the same output as can be gotten from `hostname`.

Fixes #5758
2019-03-23 12:34:48 -07:00
Aaron Gyes
7a74198aa3 parser: try to avoid some strings being copied 2019-03-23 12:34:48 -07:00
Mahmoud Al-Qudsi
c50cce298d Allow the omitted new line character to be more than one char
The code already allowed for variable width (multicell) *display* of the
newline omitted character, but there was no way to define it as being
more than one `wchar_t`.

This lets us use a string on console sessions (^J aka newline feed)
instead of an ambiguous character like `@` (used in some versions of
vim for ^M) or `~` (what we were using).
2019-03-20 21:47:34 -05:00
Mahmoud Al-Qudsi
753d489376 Fall back to simpler special characters in console sessions 2019-03-20 21:47:34 -05:00
Mahmoud Al-Qudsi
da8e343076 Use is_console_session() to signal using system wcwidth()
The system version of `wcwidth()` reflects the capabilities of the
system's own virtual terminal's view of the width of the character in
question, while fish's enhanced version (`widechar_wcwidth`) is much too
smart for most login terminals, which generally barely support anything
beyond ASCII text.

If, at startup, it is detected that we are running under a physical
console rather than within a terminal emulator running in a desktop
environment, take that as a hint to use the system-provided `wcwidth`.
2019-03-20 21:47:34 -05:00
Mahmoud Al-Qudsi
4aded78fc9 Add is_console_session() to detect physical vty 2019-03-20 21:47:32 -05:00
Mahmoud Al-Qudsi
f2896b2d83 Fix junk memory read introduced in 1cd5b2f4e1
The commit began passing the length of the wide string rather than the
length of the narrowed string after conversion via `wcstombs`. We *do*
have the actual length, but it's not (necessarily) the same as the
original value. We need to pass the result of `wcstombs` instead.
2019-03-20 20:51:22 -05:00
Fabian Homborg
a8b01e1c99 src/output: Unconst-cast tputs
Fixes the build on Solaris/OpenIndiana/Illumos.
2019-03-20 09:01:46 +01:00
Fabian Homborg
1a53bbeb9d src/fallback: Include locale.h for the wcstod_l fallback
Fixes #5753.
2019-03-20 08:54:40 +01:00
ridiculousfish
03454b7dcd Use a real struct type in fish_indent pending node stack 2019-03-18 09:13:36 -07:00
ridiculousfish
a58662dd46 Make maybe_t conditionally copyable
This allows it to be used with both e.g. unique_ptr and std::vector.
2019-03-17 13:38:18 -07:00
Fabian Homborg
0bde698f81 printf: Don't die on incomplete conversions
POSIX dictates here that incomplete conversions, like in

    printf %d\n 15.2

or

    printf %d 14g

are still printed along with any error.

This seems alright, as it allows users to silence stderr to accept incomplete conversions.

This commit implements it, but what's a bit weird is the ordering between stdout and stderr,
causing the error to be printed _after_, like

    15
    14
    15.1: value not completely converted
    14,2: value not completely converted

but that seems like a general issue with how we buffer the streams.

(I know that nonfatal_error is a copy of most of fatal_error - I tried
differently, and va_* is weird)

Fixes #5532.
2019-03-17 17:00:55 +01:00
Aaron Gyes
6e525cc5d9 wcsfilecmp: sort - after everything else
Before this change, - was sorted with other punctuation before
A-Z. Now, it sorts above the rest of the characters.

This has a practical effect on completions, where when there are
both -s and --long with the same description, the short option
is now before the long option in the pager, which is what is now
selected when navigating `foo -<TAB>`. The long options can be
picked out with `foo --<TAB>`. Before, short options which
duplicated a long option literally could not be selected by
any means from the pager.

Fixes #5634
2019-03-16 01:31:56 -07:00
Aaron Gyes
74a22ff426 wcsfilecmp: punctuation [\]^_` after A-Z.
This tweaks wcsfilecmp such that certain punctuation characters will
come after A-Z.

A big win with `set <TAB>` - the __prefixed fish junk now comes
after the stuff users should care about.
2019-03-16 01:18:16 -07:00
ridiculousfish
88d20e257b Remove some unused variables 2019-03-15 20:21:05 -07:00
Fabian Homborg
864bb1f7a6 Add string-replace-fewer-backslashes feature
This disables an extra round of escaping in the `string replace -r`
replacement string.

Currently, to add a backslash to an a or b (to "escape" it):

    string replace -ra '([ab])' '\\\\\\\$1' a

7 backslashes!

This removes one of the layers, so now 3 or 4 works (each one escaped
for the single-quotes, so pcre receives two, which it reads as one literal):

    string replace -ra '([ab])' '\\\\$1' a

This is backwards-incompatible as replacement strings will change
meaning, so we put it behind a feature flag.

The name is kinda crappy, though.

Fixes #5474.
2019-03-15 15:18:19 +01:00
Fabian Homborg
e7a964fdfa [count] Allow counting lines from stdin
As a simple replacement for `wc -l`.

This counts both lines on stdin _and_ arguments.

So if "file" has three lines, then `count a b c < file` will print 6.

And since it counts newlines, like wc, `echo -n foo | count` prints 0.
2019-03-15 14:31:36 +01:00
Aaron Gyes
cb36a9ca36 builtin.cpp: ensure builtin_get_desc returns something initialized 2019-03-14 21:45:31 -07:00
Aaron Gyes
9a5022514f builtin_argparse: use std::swap 2019-03-14 16:47:23 -07:00
Aaron Gyes
d837eee09d remove some wcstring -> wchar_t* -> wcstring conversions
Mostly related to usage _(L"foo"), keeping in mind the _
macro does a wcstring().c_str() already.

And a smattering of other trivial micro-optimizations certain
to not help tangibly.
2019-03-14 15:21:08 -07:00
Aaron Gyes
477b2e8d7c std::vector<wcstring> is wcstring_list_t 2019-03-14 11:17:26 -07:00
Aaron Gyes
0ee9862809 Write out backtrace in one debug(), add \n after it.
The goal here is to make fish -dn -Dn output a little easier
to scan visually.
2019-03-14 10:56:24 -07:00
Aaron Gyes
cf570d4b11 fixup previous commit 2019-03-14 10:37:13 -07:00
Aaron Gyes
2636876472 simplify append_yaml_to_buffer 2019-03-14 10:29:16 -07:00
Aaron Gyes
2bf554ae5e Simplify valid_var_name 2019-03-14 10:29:16 -07:00
Fabian Homborg
f798a02a2a Remove unused variable 2019-03-14 13:23:47 +01:00
Aaron Gyes
6fc542dfca Revert "simplify append_yaml_to_buffer"
This reverts commit f0998fed6a.
2019-03-13 14:05:23 -07:00
Aaron Gyes
f0998fed6a simplify append_yaml_to_buffer 2019-03-13 13:52:11 -07:00
Aaron Gyes
b879a2650c Fix 32-bit build
Fixes #5740
2019-03-13 07:44:05 -07:00
Fabian Homborg
05b9c07816 wcwidth: Return 0 for median/final jamo
Fixes #5729.
2019-03-13 12:39:08 +01:00
Fabian Homborg
5a9d153363 input: Use range-for
Also adds a couple of consts.
2019-03-13 12:39:08 +01:00
Aaron Gyes
f92c2921d2 Remove mini() and maxi()
C++11 provides std::min/std::max which we're using all over,
obviating the need for our own templates for this.

util.h now only provides two things: get_time and wcsfilecmp.
This commit removes everything that includes it which doesn't
use either; most because they no longer need mini or maxi from
it but some others were #including it unnecessarily.
2019-03-12 23:25:15 -07:00
Fabian Homborg
b318ab17d2 wcwidth: Classify some Hangul Jamo as combiners
Hangul uses three codepoints to combine to one glyph. The first has a
width of 2 (like the final glyph), but the second and third were
assigned a width of 1, which seems to match EastAsianWidth.txt:

> 1160..11FF;N # Lo [160] HANGUL JUNGSEONG FILLER..HANGUL JONGSEONG SSANGNIEUN

Instead, we override that and treat the middle and end codepoint as combiners,
always, because there's no way to figure out what the terminal will
think and that's the way it's supposed to work.

If they stand by themselves or in another combination, they'll indeed
show up with a width of 1 so we'll get it wrong, but that's less
likely and not expressible with wcwidth().

Fixes #5729.
2019-03-12 23:42:50 +01:00
Aaron Gyes
2e4948e1f4 Fix switch nesting in handler_matches
I guess this worked, but whoops.
2019-03-12 15:27:13 -07:00
Aaron Gyes
b7c069a765 Remove two duplicated #includes 2019-03-12 15:09:36 -07:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -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
Fabian Homborg
ecfe4acd0c complete: Do fuzzy match for --do-complete
This only did prefix matching, which is generally less useful.

All existing users _should_ be okay with this since they want to
provide completions.

Fixes #5467.
Fixes #2318.
2019-03-12 20:27:20 +01:00
Aaron Gyes
66887ca4bc Fix OpenSUSE build
They treat -Wreturn-type as a critical thing apparently.
2019-03-12 09:45:39 -07:00
Aaron Gyes
2ae6e5a585 Explicitly handle all enum values in more switch statements
This addresses a few places where -Wswitch-enum showed one or two missing
case's for enum values.

It did uncover and fix one apparent oversight:

$ function asd -p 100
   echo foo
end

$ functions --handlers-type exit
Event exit
asd

It looks like this should be showing a PID before 'asd' just like
job_exit handlers show the job id. It was falling
through to default: which just printed the function name.

$ functions --handlers-type exit
Event exit
100 asd
2019-03-11 15:02:18 -07:00
Fabian Homborg
1cd5b2f4e1 Pass string length instead of recomputing
This called `writestr(char*)`, which then just called `writestr(char*,
strlen(char*))`, when it had the string length right there!
2019-03-07 10:04:18 +01:00
Fabian Homborg
2b0b3d3193 Outputter_t: Handle C locale like everything else
This tried to skip conversion if the locale had MB_CUR_MAX == 1, but
in doing so it just entered an infinite recursion (because
writestr(wchar_t*) called writestr(wchar_t*)).

Instead, just let wcstombs handle it.

Fixes #5724.
2019-03-07 10:04:18 +01:00
Fabian Homborg
c633c06e11 Guess emoji width via system wcwidth
Since Unicode 9, the width of some characters changed to 2.

Depending on the system, it might have support for it, or it might
not.

Instead of hardcoding specific glibc etc versions, we check what the
system wcwidth says to "😃", U+1F603 "Grinning Face With Big Eyes".

The intention is to, in most cases, make setting $fish_emoji_width
unnecessary, but since it sets the "guessed_emoji_width", that variable still takes precedence if it is set.

Unfortunately this approach has some caveats:

- It relies on the locale being set to a unicode-supporting one.
  (C.UTF-8 is unfortunately not standard, so we can't use it)
- It relies on the terminal's wcwidth having unicode9 support IFF the
  system wcwidth does.

This is like #5722, but at runtime.

The additional caveat is that we don't try to achieve a unicode
locale, but since we re-run the heuristic when the locale changes (and
we try to get a unicode locale), we should still often get the correct
value.

Plus if you use a C locale and your terminal still displays emoji,
you've misconfigured your system.

Fixes #5722.
2019-03-06 22:27:21 +01:00
David Adam
b443808452 event.cpp: die if invalid event type passed
Fixes the build with -Wreturn-type.
2019-03-05 07:27:56 +08:00
ridiculousfish
89a7cc5da3 Switch s_write to accepting const vector & instead of raw pointers 2019-03-03 18:49:57 -08:00
ridiculousfish
ccbc9d57f2 Remove reader_data_t::next
It's no longer used
2019-03-03 18:14:41 -08:00
ridiculousfish
9b9c1aa745 Fix some unused variable warnings 2019-03-03 18:06:31 -08: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
ridiculousfish
43a11af5e4 Reorganize reader.cpp to separate te current_data users from reader_data_t 2019-03-03 15:49:56 -08:00
ridiculousfish
c09544b288 Migrate more functions to instance methods on reader_data_t 2019-03-03 15:10:47 -08:00
ridiculousfish
29db076f4a exec_prompt to be an instance method on reader_data_t 2019-03-03 14:38:53 -08:00
ridiculousfish
7ff4b5e5fe Switch highlighting to instance methods on reader_data_t 2019-03-03 14:34:52 -08:00
ridiculousfish
e477b99a8b Switch more autosuggestions to instance methods on reader_data_t 2019-03-03 14:30:32 -08:00
ridiculousfish
b014c327a2 reader_data_t to become enable_shared_from_this
For background operations such as autosuggestions, we need a way for the
completion handler to keep the reader_data alive.
2019-03-03 14:21:15 -08:00
ridiculousfish
c334a41f96 Switch accept_autosuggestion to an instance method on reader_data_t 2019-03-03 14:11:09 -08:00
ridiculousfish
d7a156e7d9 Switch clear_pager to an instance method on reader_data_t 2019-03-03 14:09:23 -08:00
ridiculousfish
164c5b1c18 Migrate a lot of free functions in reader into reader_data_t 2019-03-03 14:02:27 -08:00
ridiculousfish
ecf51b575e Clean up input initialization and destruction 2019-03-03 12:59:55 -08:00
ridiculousfish
dc1073f905 reader_set_buffer_maintaining_pager to take reader_data directly 2019-03-03 12:19:46 -08:00
ridiculousfish
0bc08c6197 highlight_search to take reader_data directly 2019-03-03 12:11:32 -08:00
ridiculousfish
b07345ed18 set_command_line_and_position to take reader_data directly 2019-03-03 12:07:51 -08:00
ridiculousfish
968152ddc7 clear_pager to accept reader_data directly 2019-03-03 12:00:09 -08:00
ridiculousfish
e11c3f352f Clean up handle_child_status
Now that we only call waitpid() on specific processes, we no longer need
to search to find the process returned by waitpid.
2019-03-03 11:47:32 -08:00
ridiculousfish
dac5d79059 Switch wait command to use topics
Prior to this fix, the wait command used waitpid() directly. Switch it to
calling process_mark_finished_children() along with the rest of the job
machinery. This centralizes the waitpid call to a single location.
2019-03-02 16:58:27 -08:00
ridiculousfish
dc27de8190 Rename reader_interrupted to reader_test_and_clear_interrupted 2019-03-02 15:17:00 -08:00
ridiculousfish
1a4bb50cd5 Combine status and pipestatus into statuses_t
In most places where we set one, we want to set both. Make this less
error-prone by combining them into a single type statuses_t.
2019-02-26 20:07:37 -08:00
Fabian Homborg
47ff060b89 string: Fix split0 return status
It turns out that `string split0` didn't actually ever do any
splitting. The arg_iterator_t already split stdin on NUL, and split0 just
performed an additional search that could never succeed (since
arguments from argv already can't contain NUL).

Let the arg_iterator_t not perform any splitting if asked, and then
let split0 split in 0.

One slight wart is that split0 ignores a trailing NUL, which normal
split doesn't.

Fixes #5701.
2019-02-26 20:03:40 +01:00
Fabian Homborg
c66015c2c1 Readd tparm unconst-cast
Fixes the build on NetBSD.

CC @ridiculousfish.
2019-02-25 22:17:56 +01:00
Fabian Homborg
92b1f4df07 Include wait.h in proc.h, not proc.cpp
Should fix the build in FreeBSD - https://builds.sr.ht/~faho/job/33304.
2019-02-25 22:12:09 +01:00
Fabian Homborg
2418e1e50b Don't mix up pgroup and pid
This is another case where we used pid when we meant pgroup.

Since 55b3c45f95, the assumption that
both are the same no longer holds in all cases, so this check was wrong.

Might fix #5663.
2019-02-25 20:23:34 +01:00
zabereer
a5659132f6 Compilation error on gcc8.2.1 2019-02-25 20:19:52 +01:00
ridiculousfish
bb36274e6b Introduce proc_status_t
In fish we play fast and loose with status codes as set directly (e.g. on
failed redirections), vs status codes returned from waitpid(), versus the
value $status. Introduce a new value type proc_status_t to encapsulate
this logic.
2019-02-25 10:14:45 -08:00
ridiculousfish
24efa45e3e Remove an unused variable 2019-02-25 09:01:48 -08:00
ridiculousfish
2c3214cabd Make $pipestatus thread safe and other misc cleanup 2019-02-24 23:29:33 -08:00
zabereer
2c8abdf5cb add $pipestatus support 2019-02-24 21:46:52 -08:00
Janczar Kurek
efa88b171a prettify_node function now does not use recursion
prettify_node_recursive is replaced with prettify_node_nrecursive
explicite stack is used instead.

Signed-off-by: Janczar Kurek <janczar.kurek@student.uj.edu.pl>
2019-02-24 21:01:45 -08:00
ridiculousfish
31dc1f9a8c Correct the builtin.cpp comment about how to add a new builtin
Teach it about Sphinx
2019-02-24 19:41:51 -08:00