From b4995f979d127cea667b4e2b71c91e9db4ab52ef Mon Sep 17 00:00:00 2001 From: maxim nikonov Date: Fri, 6 Feb 2026 18:12:40 +0500 Subject: wip --- src/Fl_Terminal.cxx | 122 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 45 deletions(-) (limited to 'src/Fl_Terminal.cxx') diff --git a/src/Fl_Terminal.cxx b/src/Fl_Terminal.cxx index ef57749cf..99ac7a6f2 100644 --- a/src/Fl_Terminal.cxx +++ b/src/Fl_Terminal.cxx @@ -743,7 +743,8 @@ void Fl_Terminal::RingBuffer::new_copy(int drows, int dcols, int hrows, const Ch while ((src_row >= src_stop_row) && (dst_row >= 0)) { Utf8Char *src = u8c_ring_row(src_row); Utf8Char *dst = new_ring_chars + (dst_row*dst_cols); - for (int col=0; colclear(style); + int col; + for (col =0; colclear(style); } } @@ -896,7 +900,8 @@ void Fl_Terminal::RingBuffer::scroll(int rows, const CharStyle& style) { // Memory // move rows = clamp(-rows, 1, disp_rows()); // make rows positive + sane - for (int row=disp_rows()-1; row>=0; row--) { // start at end of disp and work up + int row; + for (row =disp_rows()-1; row>=0; row--) { // start at end of disp and work up int src_row = (row - rows); // src is offset #rows being scrolled int dst_row = row; // dst is display if (src_row >= 0) move_disp_row(src_row, dst_row); // ok to move row? move row down @@ -1086,9 +1091,11 @@ const Fl_Terminal::Utf8Char* Fl_Terminal::u8c_disp_row(int drow) const // For walking the terminal lines in order, see examples // for u8c_hist_use_row() and u8c_disp_row(). // - for (int row=0; rowxxx() methods.. } } @@ -1118,9 +1125,9 @@ Fl_Terminal::Utf8Char* Fl_Terminal::u8c_hist_row(int hrow) Example to walk all "in use" lines of the history buffer: \code // Walk the entire screen history ("in use") and display to stdout - for (int row=0; rowlength(), u8c->text_utf8()); // show each utf8 char to stdout } @@ -1141,7 +1148,7 @@ Fl_Terminal::Utf8Char* Fl_Terminal::u8c_hist_use_row(int hurow) // Print all chars in first row of display (ASCII and UTF-8) Utf8Char *u8c = u8c_disp_row(0); // first char of first display row int scol = 0, ecol = disp_cols(); // start/end for column loop - for (int col=scol; coltext_utf8(); // text string for char int len = u8c->length(); // text string length for char ::printf("<%.*s>", len, text); // print potentially multibyte char @@ -1151,9 +1158,9 @@ Fl_Terminal::Utf8Char* Fl_Terminal::u8c_hist_use_row(int hurow) - This can also be used to walk all rows on the display screen up to the cursor row, e.g. \code // Write all chars in display up to cursor row to stdout - for (int row=0; rowtext_utf8(), u8c->length()); // write each utf8 char to stdout } @@ -1197,7 +1204,8 @@ void Fl_Terminal::init_tabstops(int newsize) { char *oldstops = tabstops_; // save old stops int oldsize = tabstops_size_; // save old size tabstops_ = (char*)malloc(newsize); // alloc new - for (int t=0; tvalue(0); // force scrollbar to bottom before refit if (drow_diff) { // change in display rows means shrink|enlarge + int i; if (is_enlarge) { // enlarging widget? - for (int i=0; i 0) { // CASE 1: Drag lines down from history cursor_.scroll(-1); // cursor chases ring_.resize() } else { // CASE 2: add blank lines below cursor @@ -1356,7 +1366,7 @@ void Fl_Terminal::refit_disp_to_screen(void) { 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 + for (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 @@ -1905,8 +1915,9 @@ void Fl_Terminal::clear(Fl_Color val) { */ void Fl_Terminal::clear_screen(bool scroll_to_hist) { if (scroll_to_hist) { scroll(disp_rows()); return; } - for (int drow=0; drow[1J". void Fl_Terminal::clear_sod(void) { - for (int drow=0; drow <= cursor_.row(); drow++) - if (drow == cursor_.row()) - for (int dcol=0; dcol<=cursor_.col(); dcol++) + int drow, dcol; + for (drow =0; drow <= cursor_.row(); drow++) { + if (drow == cursor_.row()) { + for (dcol =0; dcol<=cursor_.col(); dcol++) plot_char(' ', drow, dcol); - else - for (int dcol=0; dcol[J[0J". void Fl_Terminal::clear_eod(void) { - for (int drow=cursor_.row(); drow[K". void Fl_Terminal::clear_eol(void) { Utf8Char *u8c = u8c_disp_row(cursor_.row()) + cursor_.col(); // start at cursor - for (int col=cursor_.col(); colclear(*current_style_); //TODO: Clear mouse selection? } @@ -1965,7 +1983,8 @@ void Fl_Terminal::clear_eol(void) { /// Clear from cursor to Start Of Line (SOL), like \c "[1K". void Fl_Terminal::clear_sol(void) { Utf8Char *u8c = u8c_disp_row(cursor_.row()); // start at sol - for (int col=0; col<=cursor_.col(); col++) // run from sol to cursor + int col; + for (col =0; col<=cursor_.col(); col++) // run from sol to cursor (u8c++)->clear(*current_style_); //TODO: Clear mouse selection? } @@ -1973,7 +1992,8 @@ void Fl_Terminal::clear_sol(void) { /// Clear entire line for specified row. void Fl_Terminal::clear_line(int drow) { Utf8Char *u8c = u8c_disp_row(drow); // start at sol - for (int col=0; colclear(*current_style_); //TODO: Clear mouse selection? } @@ -2045,12 +2065,14 @@ const Fl_Terminal::Utf8Char* Fl_Terminal::walk_selection( int srow,scol,erow,ecol; if (get_selection(srow,scol,erow,ecol)) { // mouse selection exists? // Walk entire selection from start to end - for (int row=srow; row<=erow; row++) { // walk rows of selection + int row; + for (row =srow; row<=erow; row++) { // walk rows of selection const Utf8Char *u8c = u8c_ring_row(row); // ptr to first character in row int col_start = (row==srow) ? scol : 0; // start row? start at scol int col_end = (row==erow) ? ecol : ring_cols(); // end row? end at ecol u8c += col_start; // include col offset (if any) - for (int col=col_start; col<=col_end; col++,u8c++) { // walk columns + int col; + for (col =col_start; col<=col_end; col++,u8c++) { // walk columns ..do something with each char at *u8c.. } } @@ -2235,15 +2257,16 @@ void Fl_Terminal::scroll(int rows) { void Fl_Terminal::insert_rows(int count) { int dst_drow = disp_rows()-1; // dst is bottom of display int src_drow = clamp((dst_drow-count), 1, (disp_rows()-1)); // src is count lines up from dst + int dcol; while (src_drow >= cursor_.row()) { // walk srcrow upwards to cursor row Utf8Char *src = u8c_disp_row(src_drow--); Utf8Char *dst = u8c_disp_row(dst_drow--); - for (int dcol=0; dcol= cursor_.row()) { // walk srcrow to curs line Utf8Char *dst = u8c_disp_row(dst_drow--); - for (int dcol=0; dcolclear(*current_style_); } clear_mouse_selection(); @@ -2257,16 +2280,17 @@ void Fl_Terminal::insert_rows(int count) { void Fl_Terminal::delete_rows(int count) { int dst_drow = cursor_.row(); // dst is cursor row int src_drow = clamp((dst_drow+count), 1, (disp_rows()-1)); // src is count rows below cursor + int dcol; while (src_drow < disp_rows()) { // walk srcrow to EOD Utf8Char *src = u8c_disp_row(src_drow++); Utf8Char *dst = u8c_disp_row(dst_drow++); - for (int dcol=0; dcolclear(*current_style_); } clear_mouse_selection(); @@ -2298,7 +2322,8 @@ void Fl_Terminal::insert_char_eol(char c, int drow, int dcol, int rep) { const CharStyle &style = *current_style_; Utf8Char *src = u8c_disp_row(drow)+disp_cols()-1-rep; // start src at 'g' Utf8Char *dst = u8c_disp_row(drow)+disp_cols()-1; // start dst at 'j' - for (int col=(disp_cols()-1); col>=dcol; col--) { // loop col in reverse: eol -> dcol + int col; + for (col =(disp_cols()-1); col>=dcol; col--) { // loop col in reverse: eol -> dcol if (col >= (dcol+rep)) *dst-- = *src--; // let assignment do move else (dst--)->text_ascii(c,style);// assign chars displaced } @@ -2318,7 +2343,8 @@ void Fl_Terminal::delete_chars(int drow, int dcol, int rep) { if (rep == 0) return; const CharStyle &style = *current_style_; Utf8Char *u8c = u8c_disp_row(drow); - for (int col=dcol; col= disp_cols()) u8c[col].text_ascii(' ', style); // blanks else u8c[col] = u8c[col+rep]; // move } @@ -2337,9 +2363,11 @@ void Fl_Terminal::clear_history(void) { ring_.clear_hist(); scrollbar->value(0); // zero scroll position // Clear entire history buffer - for (int hrow=0; hrowclear(*current_style_); } } @@ -2667,7 +2695,8 @@ void Fl_Terminal::handle_SGR(void) { // ESC[...m? int rgbcode = 0; // 0=none, 38=fg, 48=bg int rgbmode = 0; // 0=none, 1="2", 2=, 3=, 4= int r=0,g=0,b=0; - for (int i=0; iattrib(); - for (int gcol=start_col; gcolattrib() != lastattr) { u8c->fl_font_set(*current_style_); // pwidth_int() needs fl_font set @@ -3652,7 +3682,8 @@ void Fl_Terminal::draw_row(int grow, int Y) const { int start_col = hscrollbar->visible() ? hscrollbar->value() : 0; int end_col = disp_cols(); const Utf8Char *u8c = u8c_ring_row(grow) + start_col; - for (int gcol=start_col; gcolvalue(); int erow = srow + disp_rows(); const int rowheight = current_style_->fontheight(); - for (int grow=srow; (grow