mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Factor pref_width into a function preferred_width()
Beginnings of some pager cleanup
This commit is contained in:
parent
85d697f13d
commit
d058d290be
2 changed files with 16 additions and 9 deletions
|
@ -88,10 +88,10 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s
|
|||
UNUSED(column);
|
||||
UNUSED(row);
|
||||
UNUSED(rendering);
|
||||
int comp_width, desc_width;
|
||||
size_t comp_width, desc_width;
|
||||
line_t line_data;
|
||||
|
||||
if (c->pref_width <= width) {
|
||||
if (c->preferred_width() <= width) {
|
||||
// The entry fits, we give it as much space as it wants.
|
||||
comp_width = c->comp_width;
|
||||
desc_width = c->desc_width;
|
||||
|
@ -293,9 +293,6 @@ void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring &
|
|||
|
||||
// Compute desc_width.
|
||||
comp->desc_width = fish_wcswidth(comp->desc.c_str());
|
||||
|
||||
// Compute preferred width.
|
||||
comp->pref_width = comp->comp_width + comp->desc_width + (comp->desc_width ? 4 : 0);
|
||||
}
|
||||
|
||||
recalc_min_widths(infos);
|
||||
|
@ -417,7 +414,7 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
|
|||
if (lst.size() <= col * row_count + row) continue;
|
||||
|
||||
c = &lst.at(col * row_count + row);
|
||||
pref = c->pref_width;
|
||||
pref = c->preferred_width();
|
||||
min = c->min_width;
|
||||
|
||||
if (col != cols - 1) {
|
||||
|
|
16
src/pager.h
16
src/pager.h
|
@ -74,8 +74,6 @@ class pager_t {
|
|||
size_t comp_width;
|
||||
/// On-screen width of the description information.
|
||||
size_t desc_width;
|
||||
/// Preferred total width.
|
||||
size_t pref_width;
|
||||
/// Minimum acceptable width.
|
||||
size_t min_width;
|
||||
|
||||
|
@ -85,8 +83,20 @@ class pager_t {
|
|||
representative(L""),
|
||||
comp_width(0),
|
||||
desc_width(0),
|
||||
pref_width(0),
|
||||
min_width(0) {}
|
||||
|
||||
// Returns the width of the separator between the
|
||||
// completion and description. If we have no description,
|
||||
// we have no separator width
|
||||
size_t separator_width() const {
|
||||
return this->desc_width > 0 ? 4 : 0;
|
||||
}
|
||||
|
||||
// Returns the preferred width, containing the sum of the
|
||||
// width of the completion, separator, and description
|
||||
size_t preferred_width() const {
|
||||
return this->comp_width + this->desc_width + this->separator_width();
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue