Adopt termsize_t in the pager

This commit is contained in:
ridiculousfish 2020-06-07 18:59:15 -07:00
parent db909605b8
commit 6bdbe732e4
4 changed files with 12 additions and 10 deletions

View File

@ -2201,7 +2201,7 @@ static void test_pager_navigation() {
pager_t pager;
pager.set_completions(completions);
pager.set_term_size(80, 24);
pager.set_term_size(termsize_t::defaults());
page_rendering_t render = pager.render();
if (render.term_width != 80) err(L"Wrong term width");
@ -2275,14 +2275,14 @@ static void test_pager_navigation() {
}
struct pager_layout_testcase_t {
size_t width;
int width;
const wchar_t *expected;
// Run ourselves as a test case.
// Set our data on the pager, and then check the rendering.
// We should have one line, and it should have our expected text.
void run(pager_t &pager) const {
pager.set_term_size(this->width, 24);
pager.set_term_size(termsize_t{this->width, 24});
page_rendering_t rendering = pager.render();
const screen_data_t &sd = rendering.screen_data;
do_test(sd.line_count() == 1);

View File

@ -393,9 +393,9 @@ void pager_t::set_completions(const completion_list_t &raw_completions) {
void pager_t::set_prefix(const wcstring &pref) { prefix = pref; }
void pager_t::set_term_size(size_t w, size_t h) {
available_term_width = w;
available_term_height = h;
void pager_t::set_term_size(termsize_t ts) {
available_term_width = ts.width > 0 ? ts.width : 0;
available_term_height = ts.height > 0 ? ts.height : 0;
}
/// Try to print the list of completions lst with the prefix prefix using cols as the number of

View File

@ -12,6 +12,7 @@
#include "complete.h"
#include "reader.h"
#include "screen.h"
#include "termsize.h"
#define PAGER_SELECTION_NONE static_cast<size_t>(-1)
@ -146,8 +147,8 @@ class pager_t {
// Sets the prefix.
void set_prefix(const wcstring &pref);
// Sets the terminal width and height.
void set_term_size(size_t w, size_t h);
// Sets the terminal size.
void set_term_size(termsize_t ts);
// Changes the selected completion in the given direction according to the layout of the given
// rendering. Returns true if the selection changed.

View File

@ -791,8 +791,9 @@ void reader_data_t::repaint() {
// term size, minus the number of lines consumed by our string. (Note this doesn't yet consider
// wrapping).
int full_line_count = 1 + std::count(full_line.cbegin(), full_line.cend(), L'\n');
pager.set_term_size(std::max(1, common_get_width()),
std::max(1, common_get_height() - full_line_count));
termsize_t curr_termsize = termsize_last();
pager.set_term_size(termsize_t{std::max(1, curr_termsize.width),
std::max(1, curr_termsize.height - full_line_count)});
pager.update_rendering(&current_page_rendering);
bool focused_on_pager = active_edit_line() == &pager.search_field_line;