Commit Graph

68 Commits

Author SHA1 Message Date
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
f24f952991 Use in-line initialization for page_renderint_t's constructor 2020-08-22 12:04:47 -07:00
ridiculousfish
6bdbe732e4 Adopt termsize_t in the pager 2020-06-07 20:00:42 -07:00
Rosen Penev
d9ad5a2627 remove unreachable break statements
Found with clang's -Wunreachable-code-break

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-12 17:02:17 -07:00
Rosen Penev
220f0a132d [clang-tidy] use auto when casting
Found with modernize-use-auto

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Johannes Altmanninger
14c6a12782 Use accessor functions for editable_line_t::{text,position}
This is paving the way for undo, where we want to have one central place
for modifying an editable_line_t.
2020-02-06 01:30:45 +01:00
Johannes Altmanninger
f4d0bafbd4 remove stale typedef 2020-01-30 16:32:47 +01:00
ridiculousfish
4bb18eaf42 Use completion_list_t naming everywhere
std::vector<completion_t> -> completion_list_t
2020-01-16 15:18:49 -08: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
ridiculousfish
82eca4bc86 Run clang-format on all files
The main change here is to reorder headers.
2019-10-13 15:50:48 -07: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
ridiculousfish
d8ac051f89 Move selection_direction_t to pager.h and make it a class enum 2019-04-28 14:06:03 -07:00
Aaron Gyes
b879a2650c Fix 32-bit build
Fixes #5740
2019-03-13 07:44:05 -07: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
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
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
Mahmoud Al-Qudsi
333bf1fd9f Remove write-only desc_width local variable 2019-01-16 15:38:27 -06:00
Fabian Homborg
27c0ee92de Remove a few useless .c_str()
With .c_str(), these call the wchar_t* overloads, which frequently then go on to call wcslen.
Just directly use the wcstring we already have.
2018-10-20 20:51:05 +02:00
Fabian Homborg
6c1ea03e9c [pager] Do full fuzzy search
Just like the completion code, this now matches e.g. `f-p` to
`format-branch`.

Fixes #5213.
2018-09-27 13:18:26 +02:00
ridiculousfish
c0a332743f Escape less aggressively when showing completions in pager
Stop escaping [, spaces, etc. in the pager.
2018-08-12 03:37:13 -07:00
Fabian Homborg
535617623b Make pager background cover the entire candidate
Currently, there are two possibilities for holes in the background:

- When there are two candidates with the same meaning (a long and a
  short option or two candidates with the same description)

- When a candidate does not have a description (meaning the color
  won't continue after it)

This changes both so the background just goes on.

In addition, it avoids making the background multiple times.

Fixes #4866.
2018-03-31 13:04:30 +02:00
Mahmoud Al-Qudsi
1fbf810946 Unify ellipsis_str[ing] with common variable set once 2018-03-09 14:40:35 -06:00
Fabian Homborg
dc95bfc1b1 [Pager] Make up without selected contents jump back into the pager
This makes it possible to select the last element of the completions
with just one keypress.

Fixes #3115.
2018-01-25 13:26:53 +01:00
Fabian Homborg
13079911bc [Pager] Wrap cardinal direction movement
Fixes #4669.
2018-01-25 13:26:53 +01:00
ridiculousfish
91ae39008a Correct prefix length calculation in completion measurement
A completion may have zero length; in this case the length of the
prefix was omitted and the completion was not visible. Correct the
calculation to account for zero-width completions.

Fixes #4424
2017-09-23 13:06:44 -07:00
Mahmoud Al-Qudsi
a77cd98136 Removed XXHash and converted some wchar_t* to wcstring 2017-08-19 18:27:24 -05:00
Mahmoud Al-Qudsi
d54fbddb11 Using XXHash64 for all wcstring unordered_map/set hashing
Since we are including XXHash32/64 anyway for the wchar_t* hashing,
we might as well use it.

Use arch-specific hash size and xxhash for all wcstring hashing

Instead of using XXHash64 for all platforms, use the 32-bit version
when running on 32-bit platforms where XXHash64 is significantly slower
than XXHash32 (and the additional precision will not be used).

Additionally, manually specify wcstring_hash as hashing method for
non-const wcstring unordered_set/map instances (the const varieties
don't have an in-library hash and so already use our xxhash-based
specialization when calling std::hash<const wcstring>).
2017-08-19 15:36:45 -05:00
Mahmoud Al-Qudsi
61b4900a70 Switch from std::map<> to std::unordered_map<> where possible
Didn't switch env_var_t map because it seems to be mostly iterated in
order, but that decision may be revisited at a later date.
2017-08-19 11:55:06 -05:00
Kurtis Rader
4152bdc698 deal with fish_wcswidth() returning -1
Completion strings, especially the description, might contain characters,
such as backspace, which make it impossible to calculate the width of
the string.

Fixes #4179
2017-07-04 13:03:25 -07:00
Kurtis Rader
ce61ada623 remove some lint from pager.cpp
The primary pupose of this change is to make OpenSUSE builds happy by
adding a `DIE()` call so its build toolchain knows we won't fall off the
end of function `selection_direction_is_cardinal()`.
2017-02-15 15:21:35 -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
4ffb0adb78 lint cleanups 2017-02-11 21:30:38 -08:00
ridiculousfish
a40f491c93 Defeat some miscellaneous warnings in the g++ build 2017-01-26 17:33:48 -08:00
ridiculousfish
ed85393611 Restyle pager.cpp via make style 2016-12-03 13:38:50 -08:00
ridiculousfish
ffd4754cb2 Don't show the pager on terminals of height less than 4
Prevents some potential overflow bugs and janky UI
2016-12-03 13:35:24 -08:00
ridiculousfish
54dd4b7ed6 Untangle some pager code and fix some warnings
Fixes various warnings about implicit conversions
2016-12-03 13:29:16 -08:00
ridiculousfish
8041913e7a Stop including spacer width in width_by_column in pager
Additional refactoring to remove some sketchy-looking arithmetic
2016-12-03 13:29:16 -08:00
ridiculousfish
2d5ce72cb4 Remove the min_width parts of the pager
min_width dates back to the original full-screen pager.
After some careful inspection, the code path that uses min_width
is never executed and so the min_width machinery is useless.
Let's remove it!
2016-12-03 13:29:16 -08:00
ridiculousfish
d058d290be Factor pref_width into a function preferred_width()
Beginnings of some pager cleanup
2016-12-03 13:29:16 -08:00
Kurtis Rader
521546a986 fix some lint warnings
This fixes some of the IWYU and cppcheck lint warnings. And only on
macOS (formerly OS X). Fixing these types of warnings on a broader set
of platforms should be done but this is a baby step to making `make
lint-all` have few, if any, warnings. This reduces the number of lines
in the `make lint-all` output on macOS by over 500 lines.
2016-11-15 21:15:22 -08:00
Kurtis Rader
f05fe4e292 lint: problems with default in switch statements 2016-11-03 16:19:41 -07:00
Kurtis Rader
e35b91d38c lint: empty else block 2016-11-02 14:17:26 -07:00
Kurtis Rader
4f4d34e664 lint: missing break in switch statement 2016-11-02 14:07:12 -07:00
Kurtis Rader
f6047f02d6 lint: constant conditional operator 2016-11-01 21:19:34 -07:00