Commit Graph

84 Commits

Author SHA1 Message Date
Fabian Homborg
4462f6d600 src/screen: Skip a wcswidth
This stops trying to see if the previous line is wider if it is a
prefix of the current one.

Which turns out to be true often enough that it's a net benefit.
2019-05-11 10:43:38 +02:00
Fabian Homborg
ac983f6c4b src/screen: Stop recomputing wcwidth
This passes character width as an argument for a few functions.

In particular, it hardcodes a width of "1" for a space literal.
There's no reason to compute wcwidth for the length of the prompt.
2019-05-11 10:43:38 +02:00
Fabian Homborg
567b6ed2b5 src/screen: Stop doing a bunch of unnecessary work
This measured *all* the characters on the commandline, and saved all
of them in another wcstring_list_t, just to then do... nothing with
that info.

Also, it did wcslen for something that we already have as wcstring,
reserved a vector and did a bunch of work for autosuggestions that
isn't necessary if we have more than one line.

Instead, we do what we need, which is to figure out if we are
multiline and how wide the first line is.

Fixes #5866.
2019-05-10 17:43:46 +02:00
Fabian Homborg
d2b02a8a61 src/screen: Only check for combining marks if necessary
line_shared_prefix explains in its comment that

> If the prefix ends on a combining character, do not include the
  previous character in the prefix.

But that's not what it does.

Instead, what it appears to do is to return idx for *every* combining
mark. This seems wrong to begin with, and it also requires checking
wcwidth for *every* character.

So instead we don't do that. If we find the mismatch, we check if it's
a combining mark, and then go back to the previous character (i.e. the
one before the one that the combining mark is for).

My tests found no issues with this, other than a 20% reduction in
pasting time.
2019-05-10 17:43:46 +02:00
Per Bothner
4c0a119557 Disable cursor_down optimization, but fix to check c_oflag, but c_iflag.
The old commit #3f820f0 "Disable ONLCR mapping of NL output to CR-NL"
incorrectly used c_iflag instead of c_oflag, and I copied that error
in my patch.  Fixed that. However, there seems to be other problems
trying to use "\x1B[A", which I have not tried to debug, so comment that out.

(However, #3f820f0 seems to mostly work if we fix it to use c_oflag.)
2019-05-08 17:22:44 +02:00
Per Bothner
50db10a422 Alternate fix for cursor_down bound to "\n" and ONLCR set.
See GitHub issue #4505 "Terminal mode confusion"
and commit #3f820f0 "Disable ONLCR mapping of NL output to CR-NL".
2019-05-08 17:22:44 +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
f66e010949 Turn a lot of common.h variables into getter functions
Improves thread safety.
2019-05-04 20:58:35 -07:00
Aaron Gyes
f309ae05b6 is_visual_escape_seq: whittle down the escape sequences attempted
Some of these we do not need to worry about actually being used
in a prompt.
2019-04-20 17:03:27 -07:00
Per Bothner
2edfab685a Some comment fixes and renaming of is_iterm2_escape_seq. (#5827)
* Some comment fixes and renaming of is_iterm2_escape_seq.

The comment for is_iterm2_escape_seq incorrectly says "CSI followed by ]".
This is wrong, because CSI is ESC followed by [ (or the seldom-used 0x9b).
The procedure  actually matches Operating System Command (OSC) escape codes.
Since there is nothing iterm2-specific about OSC, is_osc_escape_seq
would be a better name.

Also s_desired_append_char documents a non-existent parameter.

* Update broken iterm2 url in comment.
2019-04-19 09:29:35 -07:00
Fabian Homborg
42acbaa5af Remouve ouveroused U
Webster was right, gosh dang it!

[ci skip]
2019-03-28 12:31:52 +01: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
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
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
ridiculousfish
89a7cc5da3 Switch s_write to accepting const vector & instead of raw pointers 2019-03-03 18:49:57 -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
5134949a14 Factor color and terminal sequence outputting into outputter_t
Removes some static variables and simplifies the behavior of the tputs
singletone receiver.
2019-02-23 20:07:29 -08:00
ridiculousfish
77884bc21a Instantize env_get
This removes env_get(). All fish variable accesses must go through an
environment_t.
2019-01-10 20:08:06 -08:00
Fabian Homborg
b77a909a4f Make a few variables const
These are then passed to tparm, but we explicitly cast the const
away.
2018-12-31 14:24:23 +01:00
Fabian Homborg
58ceb00781 Make a few methods const
This helps on netbsd, because enter_standout_mode et al are const
there.

These methods don't alter their argument, so they should have been
const to begin with.
2018-12-31 14:24:23 +01:00
Fabian Homborg
c5f9f59555 Always cast to non-const for tparm
This is non-const on macOS, but some of the args we pass are always
const on netbsd.

I have no idea why you'd ever want this to modify its argument, but whatever.
2018-12-31 14:24:23 +01:00
Fabian Homborg
d91b48b866 screen: Avoid crash if clr_eol is undefined
This crashes if the terminfo entry does not have the el capability.
Which is unusual but happens with the (outdated) "terminology" entry.

Fixes #5371.
2018-11-28 13:37:40 +01:00
Mahmoud Al-Qudsi
6df29b2fd1 Revert "Disable ONLCR mapping of NL output to CR-NL"
This reverts commit 3f820f0edf.
While the premise described by @nbuwe is sound in #4505, we are now
apparently relying on this behavior is some places (although
inadvertently as there doesn't seem to be a deliberate acknowledgement
of that anywhere).

Turning off ONLCR causes things like indented multiline commands to not
appear correct at the tty (subsequent lines appear both at column 0 and
again indented).
2018-10-19 17:49:11 -05:00
Mahmoud Al-Qudsi
3f820f0edf Disable ONLCR mapping of NL output to CR-NL
Per @nbuwe's excellent explanation in #4505, we can save on output
to the tty by maintaining column location after NL by disabling the
ONLCR terminal mode.

Closes #4505.
2018-10-17 21:20:39 -05:00
ridiculousfish
e6863a90c8 Don't reset the screen after emitting a BEL
Fixes #3693
2018-09-16 16:25:49 -07:00
Mahmoud Al-Qudsi
dcced5f1bc Replace \e with \x1B, as the former is a gcc extension
While supported by gcc and clang, \e is a gcc-specific extension and not
formally defined in the C or C++ standards.

See [0] for a list of valid escapes.

[0]: https://stackoverflow.com/a/10220539/17027
2018-06-18 00:01:47 -05:00
Fabian Homborg
e35d248f64 Fix clearing abandoned line with VTE (#4243)
Turns out the segfaults we've been getting in our tests are because we set $TERM to "dumb".

So we only clear the line if the terminal isn't dumb.

This reverts commit 745a88f2f6.

Fixes #2320.
2018-05-08 13:07:47 +02:00
ridiculousfish
74e6a82849 Remove explicit 'void' parameters. 2018-02-18 19:12:45 -08:00
Mahmoud Al-Qudsi
7fafdee98e
Merge pull request #4704 from fish-shell/curses_ncurses
Fix curses includes on platforms offering real libcurses.
2018-02-06 10:44:29 -06:00
ridiculousfish
72208a9438 Use the layout cache instead of static variables for caching prompts
This correctly reacts to changes in TERM (which might affect prompt
width due to escape code differences), and eliminates some ugly
static variables.
2018-02-04 16:20:55 -08:00
ridiculousfish
1bd5946d23 Add prompt layout caching to layout_cache_t 2018-02-04 16:20:55 -08:00
ridiculousfish
d1436486e2 Rename cached_esc_sequences_t to layout_cache_t
Preparation for migrating the prompt cache into this struct.
2018-02-04 16:20:55 -08:00
ridiculousfish
a87970fbb5 Have the pager use a simple newline count to determine reserved lines
When the pager wants to use the full screen to show many options, it reserves
space at the top to see the command. Previously it pretended the command was a
prompt and engaged the prompt layout mechanism to compute these lines. Instead
let's juts count newlines since escape sequences within commands are very rare.
2018-02-04 14:14:37 -08:00
slama
27c1c06ed4 improve the size of completions page to show the entire prompt 2018-02-04 14:04:08 -08:00
ridiculousfish
9ba6b62791 Remove some ancient "#if 0' code and fix formatting errors 2018-02-04 14:03:08 -08:00
Mahmoud Al-Qudsi
63c8a197e5 [cmake] Clean up curses vs ncurses includes
There were several issues with the way that the include tests for curses.h
were being done that were ultimately causing fish to use the headers from
ncurses but link against curses on platforms that provide an actual
libcurses.so that isn't just a symlink to libncurses.so

In particular, the old code was first testing for curses's cureses.h and then
falling back to libncurses's implementation of the same - but that logic was
reversed when it came to including term.h, in which case it was testing for
the ncurses term.h and falling back to the curses.h header. Long story short,
while cmake will link against libcurses.so if both libcurses.so and
libncurses.so are present (unless CURSES_NEED_NCURSES evaluates to TRUE, but
that makes ncurses a hard requirement), but we were brining in some of the
defines from the ncurses headers, causing SIGSEGV panics when fish ultimately
tried to access variables that weren't exported or were mapped to undefined
areas of memory in the other library.

Additionally it is an error to include termios.h prior to including the plain
Jane curses.h (not ncurses/curses.h), causing errors about unimplemented types
SGTTY/chtype. So far as I can tell, both curses.h and ncurses/curses.h pull in
termios.h themselves so it shouldn't even be necessary to manually include it,
but I have just moved its #include below that of curses.h
2018-02-04 03:11:22 -06:00
ridiculousfish
cb352317bd Simplify the cached_esc_sequences_t structure
The type cached_esc_sequences_t caches escape sequences, and is tasked
with finding an escape sequence that prefixes a given string. Before
this fix, it did so by storing the lengths of cached escape sequences,
and searching for substrings of that length. The new implementation
instead stores all cached escape sequences in a sorted vector, and uses
binary search to find the shortest escape sequence that is a prefix of
the input. This is a substantial simplification that also reduces
allocations.
2017-09-01 14:36:16 -07:00
Fabian Homborg
745a88f2f6 Revert "Fix clearing abandoned line with VTE (#4243)"
Unfortunately, this breaks the expect tests.

So, until I can figure out how to unbreak them:

This reverts commit 09cb31a172.
2017-08-14 18:17:34 -07:00
Fabian Homborg
cf00162340 Fix clearing abandoned line with VTE (#4243)
* Fix clearing abandoned line with VTE

With VTE-based terminals, resizing currently causes multi-line prompts
to go weird.

This changes the sequence we use to clear the line to one suggested by
a VTE
developer (https://bugzilla.gnome.org/show_bug.cgi?id=763390#c4).

It changes nothing in konsole 17.04.3 and urxvt 9.22, but they already
work.

Note that this does not fix the case where output did not end in a
newline, but that doesn't seem to be up to us. Also, it only affects
those lines.

Fixes #2320.

* Use terminfo definition instead of hardcoding

Thanks to @ixjlyons.
2017-08-14 18:17:34 -07:00
Kurtis Rader
c36ad27618 stop subclassing env_var_t from wcstring
This is the first step to implementing issue #4200 is to stop subclassing
env_var_t from wcstring. Not too surprisingly doing this identified
several places that were incorrectly treating env_var_t and wcstring as
interchangeable types. I'm not talking about those places that passed
an env_var_t instance to a function that takes a wcstring. I'm talking
about doing things like assigning the former to the latter type, relying
on the implicit conversion, and thus losing information.

We also rename `env_get_string()` to `env_get()` for symmetry with
`env_set()` and to make it clear the function does not return a string.
2017-08-06 13:24:34 -07:00
Kurtis Rader
48d5342601 style cleanups
Time for another `make style-all`.
2017-05-01 22:05:35 -07:00
Kurtis Rader
6d02bec4c7 fix setting up and using the terminfo data
There should be just one place that calls `setupterm()`. While refactoring
the code I also decided to not make initializing the curses subsystem a
fatal error. We now try two fallback terminal names ("ansi" and "dumb")
and if those can't be used we still end up with a usable shell.

Fixes #3850
2017-03-08 20:54:37 -08:00
Kurtis Rader
509ee64fc9 implement our own assert() function
I recently upgraded the software on my macOS server and was dismayed to
see that cppcheck reported a huge number of format string errors due to
mismatches between the format string and its arguments from calls to
`assert()`. It turns out they are due to the macOS header using `%lu`
for the line number which is obviously wrong since it is using the C
preprocessor `__LINE__` symbol which evaluates to a signed int.

I also noticed that the macOS implementation writes to stdout, rather
than stderr. It also uses `printf()` which can be a problem on some
platforms if the stream is already in wide mode which is the normal case
for fish.

So implement our own `assert()` implementation. This also eliminates
double-negative warnings that we get from some of our calls to
`assert()` on some platforms by oclint.

Also reimplement the `DIE()` macro in terms of our internal
implementation.

Rewrite `assert(0 && msg)` statements to `DIE(msg)` for clarity and to
eliminate oclint warnings about constant expressions.

Fixes #3276, albeit not in the fashion I originally envisioned.
2017-02-14 18:48:27 -08:00
Kurtis Rader
0970cc8736 time for another make style-all 2017-02-07 21:52:35 -08:00
Kurtis Rader
c4f2210cc5 cache prompts and escape sequences we've seen
Cache the escape sequences we've seen when checking for those which
don't take any visual space when writing the prompt or similar strings.
This reduces the cost of determining the true cost of such strings by a
full order of magnitude if they include lots of such escape sequences.

Periodically sort the cached escape sequence lengths based on feedback
from cache hits so that we're always checking for the most likely
sequence lengths first.

Also cache the prompt layouts to avoid doing the calculations if the
prompt doesn't change.

Fixes #3793
2017-02-05 18:31:14 -08:00
Kurtis Rader
6d72d538a6 refactor escape_code_length()
Step one in addressing issue #3793
2017-02-05 18:31:14 -08:00
Kurtis Rader
2e9a349dd0 normalize use of stdio functions taking a stream
We should never use stdio functions that use stdout implicitly. Saving a
few characters isn't worth the inconsistency. Too, using the forms such
as `fwprintf()` which take an explicit stream makes it easier to find
the places we write to stdout versus stderr.

Fixes #3728
2017-01-13 20:48:55 -08:00
Fabian Homborg
6daa8d7e12 Replace puts() with wprintf() 2017-01-07 14:05:42 +01:00
Kurtis Rader
b118ed69d3 convert narrow stderr output to wide forms
On some platforms, notably GNU libc, you cannot mix narrow and wide
stdio functions on a stream like stdout or stderr. Doing so will drop
the output of one or the other. This change makes all output to the
stderr stream consistently use the wide forms.

This change also converts some fprintf(stderr,...) calls to debug()
calls where appropriate.

Fixes #3692
2017-01-03 16:14:42 -08:00