Addresses issue #879

This commit is contained in:
Greg Ercolano 2024-01-15 14:52:58 -08:00
parent 3142eb2fda
commit d3914ef90e
2 changed files with 85 additions and 8 deletions

View File

@ -1210,15 +1210,48 @@ void Fl_Terminal::update_scrollbar(void) {
scrollbar->redraw(); // redraw scroll always
}
// Refit the display to match screen
// Refit the display - (display_rows()/cols()) to match screen (scrn_.h()/w())
// This implements an xterm-like resizing behavior. Refer to README-Fl_Terminal.txt,
// section "TERMINAL RESIZING" for a diagram of cases showing how this is implemented.
// See also issue #879.
//
void Fl_Terminal::refit_disp_to_screen(void) {
int dh = h_to_row(scrn_.h()); // height in rows for tty pixel height
int dw = MAX(w_to_col(scrn_.w()), disp_cols()); // width in cols for tty pixel width - enlarge only!
int drows = clamp(dh, 2, dh); // 2 rows minimum
int dcols = clamp(dw, 10, dw); // 10 cols minimum
int drow_diff = drows - display_rows(); // change in rows?
ring_.resize(drows, dcols, hist_rows(), *current_style_);
cursor_.scroll(-drow_diff);
int dh = h_to_row(scrn_.h()); // disp height: in rows for tty pixel height
int dw = MAX(w_to_col(scrn_.w()), disp_cols()); // disp width: in cols from pixel width - enlarge only!
int drows = clamp(dh, 2, dh); // disp rows: 2 rows minimum
int dcols = clamp(dw, 10, dw); // disp cols: 10 cols minimum
int drow_diff = drows - display_rows(); // disp row diff: change in rows?
int is_enlarge = drows >= display_rows(); // enlarging display size?
// NOTE: Zeroing scrollbar can be avoided if we took the scroll position
// into account for the below calculations. But for now..
scrollbar->value(0); // force scrollbar to bottom before refit
if (drow_diff) { // change in display rows means shrink|enlarge
if (is_enlarge) { // enlarging widget?
for (int i=0; i<drow_diff; i++) { // carefully loop thru each change
if (history_use() > 0) { // CASE 1: Drag lines down from history
cursor_.scroll(-1); // cursor chases ring_.resize()
} else { // CASE 2: add blank lines below cursor
scroll(1); // scroll up to create blank lines at bottom
}
// Handle enlarging ring's display
ring_.resize(display_rows()+1, dcols, hist_rows(), *current_style_);
}
} else { // shrinking widget?
for (int i=0; i<(-drow_diff); i++) { // carefully loop thru each row change
int cur_row = cursor_.row(); // cursor row
int below_cur = (drows > cur_row); // shrink is below cursor row?
if (below_cur) { // CASE 3: shrinking below cursor? drop lines below
ring_.disp_rows(display_rows() - 1); // effectively "deletes" lines below cursor
} else { // CASE 4: need to move cursor + lines up into hist
cursor_up(-1, false); // move cursor down to follow ring_.resize()
// Handle shrinking ring's display up into history
ring_.resize(display_rows()-1, dcols, hist_rows(), *current_style_);
}
}
}
}
clear_mouse_selection();
update_screen(false);
}

View File

@ -303,7 +303,51 @@ Some terminal operations necessarily call redraw() directly, such as interactive
selection, or during user scrolling the terminal's scrollbar, where it's important there's
no delay in what the user sees while interacting directly with the widget.
TERMINAL RESIZING
=================
Resizing currently follows xterm(1) style behavior:
CASE 1: ENLARGE, USING HISTORY:
-2 Line 1 ┐_ scrollback
-1 Line 2 ┘ history
┌──────────────────┐ ┌──────────────────┐
1│ Hello! │ 1│ Line 1 │
2│ ▒ │ enlarge 2│ Line 2 │
└──────────────────┘ ──┐ 3│ Hello! │
│ 4│ ▒ │
└──────> └──────────────────┘
┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄
CASE 2: ENLARGE, ADDING LINES BELOW CURSOR
┌──────────────────┐ ┌──────────────────┐
1│ Line 1 │ 1│ Line 1 │
2│ Line 2 │ enlarge 2│ Line 2 │
3│ Hello! │ 3│ Hello! │
4│ ▒ │ 4│ ▒ │
└──────────────────┘ ──┐ 5│ │
│ 6│ │
└──────> └──────────────────┘
┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄
CASE 3: SHRINK, TRIMMING LINES BELOW CURSOR
┌──────────────────┐ ┌──────────────────┐
1│ Line 1 │ 1│ Line 1 │
2│ Line 2 │ 2│ Line 2 │
3│ Hello! │ resize 3│ Hello! │
4│ ▒ │ 4│ ▒ │
5│ │ ╭────> └──────────────────┘
6│ │ │ 5 ┐ Lines below cursor erased
└──────────────────┘ ──╯ 6 ┘ (regardless of contents)
┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄
CASE 4: SHRINK, PUSH TO HISTORY: -2 Line 1 ┐_ moved into
-1 Line 2 ┘ scrollback history
┌──────────────────┐ ┌──────────────────┐
1│ Line 1 │ 1│ Hello! │
2│ Line 2 │ resize 2│ ▒ │
3│ Hello! │ ╭────> └──────────────────┘
4│ ▒ │ │
└──────────────────┘ ──╯
These case numbers (CASE 1 tru 4) are referenced in the source code for
Fl_Terminal::refit_disp_to_screen(void).
OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD