Commit Graph

146 Commits

Author SHA1 Message Date
Fabian Homborg
ee2d2caeaa escape_code_length: Test colors last
We have a *lot* of color sequences to try and tparm is slow (on the
whole, when you do this thousands of times).

So let's just check colors last, which makes everything else (which is
comparatively nothing) faster, while barely impacting
colors (benchmarking confirms no measurable difference).

Fixes #8253.
2021-08-26 21:01:55 +02:00
Mahmoud Al-Qudsi
426fa82f8f Fix recently broken escape_code_length() result
`escape_code_length()` was converted from returning a `size_t` to
returning a `maybe_t<size_t>` but that subtly broke all existing call
sites by forcing all input to go through the slow path of assuming a
zero-length escape sequence was found.

This is because all callers predicated their next action on what amounts
to `if (escape_code_length(...))` which would correctly skip the slow
path when `escape_code_length` returned zero, but after the conversion
to `maybe_t` contained not `maybe_t::none()` but rather
`maybe_t::some(0)` due to coercion of the result from the `size_t` local
`esc_seq_len` to the `maybe_t<size_t>` return value - which, when
coerced to a boolean returns *true* for `maybe_t::some(0)` rather than
false.

The regression was introduced in 7ad855a844
and did not ship in any released versions so no harm, no foul.
2021-08-17 19:04:10 -05:00
Fabian Homborg
7ad855a844 screen: Make escape_code_length public
Uncached, but we don't want to keep this globally, I think?

This is useful for doing string pad/length without escapes.
2021-08-04 21:09:47 +02:00
Fabian Homborg
4bb1c72a91 Revert "Clear to eol before outputting line in multi-line prompt"
This means, if we repaint with a shorter prompt, we won't overwrite the longer parts.

This reintroduces #8002, but that's a much rarer usecase - having a prompt that fills the entire screen,
in certain terminals.

This reverts commit d3ceba107e.

Fixes #8163.
2021-07-24 09:28:39 +02:00
Fabian Homborg
63dd046f99 screen: Remove errant line
This was an experiment that was accidentally committed. Sorry!
2021-05-18 11:27:30 +02:00
Fabian Homborg
4b2bce7b83 screen: Remove useless .c_str() and wcslen calls
This passed the wchar_t* to outputter::writestr(), which then had to
do a wcslen on it, when it already has a perfectly cromulent
wcstring overload.

Just use that one.
2021-05-18 09:11:56 +02:00
Fabian Homborg
25595a94c7 screen: Also move cursor after printing the prompt
This helps with width issues when no right prompt is used.
2021-05-18 09:09:59 +02:00
Fabian Homborg
0660ea5be7 Move the cursor to the beginning before printing right prompt
This makes the right prompt position independent of the width of the
commandline, which prevents staircase effects. That means, with "X"
standing in as a character that the terminal and fish disagree on:

```
> echo X           rightprompt
```

will stay like that instead of creating a staircase like

```
> echo X            rightpromp
t> echo X             rightpromp
pt> echo X
```

and so on.

The cursor still won't be *correct*, but it will be wrong in a less
annoying way.
2021-05-18 09:09:59 +02:00
ridiculousfish
d3ceba107e Clear to eol before outputting line in multi-line prompt
If the user has a multi-line prompt, we will emit a clr_eol on every
line except the last (see #7404). Prior to this change we would emit
clr_eol after the line, but in some terminals, if the line extended the
width of the tty, the last character would be deleted. Switch to
emitting clr_eol first; now the last character will not be cut off.

Fixes #8002
2021-05-17 21:44:17 -07:00
ridiculousfish
17fc542082 Revert "Stop caching line breaks in the prompt calculation"
This reverts commit a2ff32d904.

Per comments on the commit, the original code had correct handling of line
breaks inside escapes.
2020-11-12 10:55:11 -08:00
ridiculousfish
a2ff32d904 Stop caching line breaks in the prompt calculation
These are fast enough to find on demand.
2020-11-01 14:45:35 -08:00
Soumya
80aaae5b74 Clear to end of each line in left prompt 2020-11-01 13:29:26 -08:00
Fabian Homborg
0f7e2ca99c Don't put commandline on a new line if prompt is "long"
This was a weird special behavior where we'd put the commandline on a
new line if it wrapped *and* the prompt was > 33% of the screen.

It seems to be more confusing than anything.

Fixes #5118.
2020-09-27 13:12:06 +02:00
Fabian Homborg
5fd3ad624f screen: Show suggestion if the commandline was pushed to a new line
Pretty sure this was just overlooked, the comment mentions that it
should happen and it seems to work.

Fixes #7213.
2020-09-12 20:09:26 +02:00
ridiculousfish
eac0f35413 camelCase to snake_case a function name 2020-08-23 03:38:25 -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
Johannes Altmanninger
ada03d3509 Correct pager size when command line soft-wraps
When selectiong a large completion entry in the pager, it would clobber the
prompt. To reproduce, first run this command

	complete -c : -xa '(
		# completion entries that,  when applied to the commandline
		# need one, two, or three lines respectively
		echo 1
		echo 2(string repeat -n (math $COLUMNS - 5) x)
		echo 3(string repeat -n $COLUMNS x)
		printf %s\n n(seq $LINES)
	)'

then type ": " and hit Tab repeatedly. When cycling through completion
entries, observe that fish always tries to render the pager with the same
size, even though the number of lines occupied by the command line buffer
changes due to soft wrapping.

Fix this by rendering the pager after the command line has been rendered, so
we know how many lines we have left.
2020-07-05 08:55:17 +02:00
Mahmoud Al-Qudsi
b8a16a8ba0 Convert highlighted_char_t to a struct 2020-07-04 20:23:50 -05:00
ridiculousfish
7b486b4634 Factor s_reset better
Prior to this fix, s_reset would attempt to reset the screen, optionally
using the PROMPT_SP hack to go to the next line. This in turn required
passing in the screen width even if it wasn't needed (because we were
not going to abandon the line). Factor this into two functions:

- s_reset_line which does not apply the hack
- s_reset_abandoning_line which applies the PROMPT_SP hack
2020-06-07 20:00:41 -07:00
ridiculousfish
fc42516dfb Unwind some calls to common_get_width from inside screen
common_get_width will "lazily" decide the screen width, which means
changing the environment variable stack. This is a surprising thing
to do from the middle of screen rendering.

Switch to passing in widths explicitly to screen.
2020-06-07 20:00:41 -07:00
ridiculousfish
812cc1dbaf Clean up line_t
Use a single allocation instead of two for text and colors.
Comment and tighten up its methods.
2020-06-07 20:00:41 -07:00
ridiculousfish
064324984b Use consistent variable names in decl and def of calc_prompt_layout 2020-06-07 12:56:14 -07:00
Fabian Homborg
4d487f711d Don't use cbegin/cend
This has problems on old gcc, and isn't super necessary.
2020-06-01 15:52:15 +02:00
ridiculousfish
a2ae2d6c36 Attempt to truncate prompts that are too wide
Prior to this change, if the user's prompt was wider than the terminal, we
would reduce it to just `> `. With this change, attempt to truncate the
prompt.

For each line of the prompt, calculate its width. If the width exceeds
COLUMNS, prepend ellipsis to that line, and start removing characters
until it fits. Escape sequences are skipped.

Fixes #904
2020-05-31 09:58:47 -07:00
ridiculousfish
67a4b35838 Migrate cached_layouts into layout_cache_t 2020-05-30 15:00:28 -07:00
ksralgp
f55f98b064
Show autosuggestions when (left prompt + command) exceed right prompt (#7035)
* Show autosuggestions when (left prompt + command) exceed right prompt

* Fix indentation whitespace and run build_tools/fish.style on src/screen.cpp
2020-05-24 21:54:00 +02: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
ridiculousfish
4116829292 Do not issue clr_eos if we think the cursor will end up on its own line
If we output text and end up in the last column, the sticky right edge
will cause a clr_eos to erase the last character. Ensure this doesn't
happen by not issuing clr_eos in that case.

Fixes #6951
2020-04-29 14:22:54 -07:00
ridiculousfish
2951c05934 Do not consider dumb terminals to have wrapping
For the purpose of cursor_is_wrapped_to_own_line, always return false
for dumb terminals. Fixes the tests.
2020-04-28 16:30:52 -07:00
ridiculousfish
4f103d74fb Do not emit newline when running commands if the cursor is on its own line
If the cursor has been wrapped to the last line, and is the only thing
on that line, do not emit a newline when executing a command.

Fixes #6826
2020-04-28 11:51:46 -07:00
ridiculousfish
81af389258 Modernize screen_t
Use inline initializers rather than the constructor, and adopt some
maybe_t.

Also move post_buff_1 and post_buff_2 to local variables instead of
member variables.
2020-04-28 11:26:06 -07:00
ridiculousfish
520c83cbbf Make screen_reset_mode_t an enum class instead of an enum
Improves type safety.
2020-04-28 11:00:26 -07:00
ridiculousfish
8355285736 Add a category for screen repainting 2020-03-02 18:31:24 -08:00
Rosen Penev
925c7a998a [clang-tidy] mark single argument constructors explicit
Found with hicpp-explicit-conversions

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-02-22 09:33:17 +01:00
ridiculousfish
98e714f98f clang-format .cpp and .h files 2020-01-16 15:18:28 -08:00
Fabian Homborg
484e590b7b Readd unconst cast to tparm calls
Removed in 0dfa7421f3, breaks build with NetBSD curses.
2020-01-05 22:28:39 +01:00
Rosen Penev
b1349f44f6
[clang-tidy] Add const to reference
Found with performance-unnecessary-copy-initialization
2019-12-26 21:37:15 -08:00
Rosen Penev
e45ae9df49 [clang-tidy] Enclose macro arguments in ()
Found with bugprone-macro-parentheses

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
9507c3a159 [clang-tidy] Don't initialize member functions
Found with readability-redundant-member-init

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
Jason
3cf6ebc0e1 Amend typos and grammar errors 2019-11-25 13:07:15 +01:00
ridiculousfish
7bd134f795 Reformat all .cpp files 2019-11-09 16:07:33 -08:00
Per Bothner
5ece4481a5 Prefer using clr_eos to clear "remaining lines" - but reset color first
This un-reverts pull request #6190, but adds a missing
reset of the color before doing the clr_eos.
2019-11-02 14:34:04 -07:00
Fabian Homborg
ec4bbe248e Revert "Prefer using clr_eos to clear "remaining lines""
This reverts commit d502ad2c25.

Fixes #6263
2019-10-31 19:15:03 +01:00
ridiculousfish
d992480204 Clean up a few string handling bits 2019-10-27 16:22:42 -07:00
LawAbidingCactus
305a657694 fix typos 2019-10-23 19:38:44 +02: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
Per Bothner
d502ad2c25 Prefer using clr_eos to clear "remaining lines"
This is both more efficient than multiple clr_eol sequences,
and also works better with shell-integration.
2019-10-13 12:12:44 -07:00