diff options
Diffstat (limited to 'src/Fl_Terminal.cxx')
| -rw-r--r-- | src/Fl_Terminal.cxx | 122 |
1 files changed, 77 insertions, 45 deletions
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; col<tcols; col++ ) *dst++ = *src++; + int col; + for (col =0; col<tcols; col++ ) *dst++ = *src++; --src_row; --dst_row; } @@ -826,15 +827,18 @@ bool Fl_Terminal::RingBuffer::is_disp_ring_row(int grow) const { void Fl_Terminal::RingBuffer::move_disp_row(int src_row, int dst_row) { Utf8Char *src = u8c_disp_row(src_row); Utf8Char *dst = u8c_disp_row(dst_row); - for (int col=0; col<disp_cols(); col++) *dst++ = *src++; + int col; + for (col =0; col<disp_cols(); col++) *dst++ = *src++; } // Clear the display rows 'sdrow' thru 'edrow' inclusive using specified CharStyle 'style' void Fl_Terminal::RingBuffer::clear_disp_rows(int sdrow, int edrow, const CharStyle& style) { - for (int drow=sdrow; drow<=edrow; drow++) { + int drow; + for (drow =sdrow; drow<=edrow; drow++) { int row = hist_rows_ + drow + offset_; Utf8Char *u8c = u8c_ring_row(row); - for (int col=0; col<disp_cols(); col++) u8c++->clear(style); + int col; + for (col =0; col<disp_cols(); col++) u8c++->clear(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; row<ring_rows(); row++) { + int row; + for (row =0; row<ring_rows(); row++) { Utf8Char *u8c = u8c_ring_row(row); - for (int col=0; col<ring_cols(); col++,u8c++) { + int col; + for (col =0; col<ring_cols(); col++,u8c++) { ..make use of u8c->xxx() 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; row<hist_use(); row++) { + for (row =0; row<hist_use(); row++) { const Utf8Char *u8c = u8c_hist_use_row(row); // first char in row - for (int col=0; col<=hist_cols(); col++,u8c++) { // walk columns left-to-right + for (col =0; col<=hist_cols(); col++,u8c++) { // walk columns left-to-right // ..Do things here with each u8c char.. ::printf("%.*s", u8c->length(), 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; col<ecol; col++,u8c++) { // loop from first char to last + for (col =scol; col<ecol; col++,u8c++) { // loop from first char to last char *text = u8c->text_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; row<disp_rows() && row<=cursor_row(); row++) { + for (row =0; row<disp_rows() && row<=cursor_row(); row++) { const Utf8Char *u8c = u8c_disp_row(row); // first char in row - for (int col=0; col<=display_cols(); col++,u8c++) { // walk columns left-to-right + for (col =0; col<=display_cols(); col++,u8c++) { // walk columns left-to-right // ..Do things here with each u8c char.. ::printf("%.*s", u8c->text_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; t<newsize; t++) { // init new tabstops: + int t; + for (t =0; t<newsize; t++) { // init new tabstops: tabstops_[t] = (oldstops && t<oldsize) ? oldstops[t] // copy old : ((t % 8) == 0) ? 1 : 0; // new defaults @@ -1212,7 +1220,8 @@ void Fl_Terminal::init_tabstops(int newsize) { // Reset all tabstops to default 8th char void Fl_Terminal::default_tabstops(void) { init_tabstops(ring_cols()); // issue #882 - for (int t=1; t<tabstops_size_; t++) // t=1: skip 0 + int t; + for (t =1; t<tabstops_size_; t++) // t=1: skip 0 tabstops_[t] = ((t % 8) == 0) ? 1 : 0; // every 8th char is a tabstop } @@ -1345,8 +1354,9 @@ void Fl_Terminal::refit_disp_to_screen(void) { scrollbar->value(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<drow_diff; i++) { // carefully loop thru each change + for (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 @@ -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<disp_rows(); drow++) - for (int dcol=0; dcol<disp_cols(); dcol++) + int drow, dcol; + for (drow =0; drow<disp_rows(); drow++) + for (dcol =0; dcol<disp_cols(); dcol++) clear_char_at_disp(drow, dcol); clear_mouse_selection(); } @@ -1932,32 +1943,39 @@ void Fl_Terminal::clear_screen_home(bool scroll_to_hist) { /// Clear from cursor to Start Of Display (EOD), like \c "<ESC>[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<disp_cols(); dcol++) + } else { + for (dcol =0; dcol<disp_cols(); dcol++) plot_char(' ', drow, dcol); + } + } //TODO: Clear mouse selection? } /// Clear from cursor to End Of Display (EOD), like \c "<ESC>[J<ESC>[0J". void Fl_Terminal::clear_eod(void) { - for (int drow=cursor_.row(); drow<disp_rows(); drow++) - if (drow == cursor_.row()) - for (int dcol=cursor_.col(); dcol<disp_cols(); dcol++) + int drow, dcol; + for (drow =cursor_.row(); drow<disp_rows(); drow++) { + if (drow == cursor_.row()) { + for (dcol =cursor_.col(); dcol<disp_cols(); dcol++) plot_char(' ', drow, dcol); - else - for (int dcol=0; dcol<disp_cols(); dcol++) + } else { + for (dcol =0; dcol<disp_cols(); dcol++) plot_char(' ', drow, dcol); + } + } //TODO: Clear mouse selection? } /// Clear from cursor to End Of Line (EOL), like \c "<ESC>[K". void Fl_Terminal::clear_eol(void) { Utf8Char *u8c = u8c_disp_row(cursor_.row()) + cursor_.col(); // start at cursor - for (int col=cursor_.col(); col<disp_cols(); col++) // run from cursor to eol + int col; + for (col =cursor_.col(); col<disp_cols(); col++) // run from cursor to eol (u8c++)->clear(*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 "<ESC>[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; col<disp_cols(); col++) // run to eol + int col; + for (col =0; col<disp_cols(); col++) // run to eol (u8c++)->clear(*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<disp_cols(); dcol++) *dst++ = *src++; // move + for (dcol =0; dcol<disp_cols(); dcol++) *dst++ = *src++; // move } // Blank remaining rows upwards to and including cursor line while (dst_drow >= cursor_.row()) { // walk srcrow to curs line Utf8Char *dst = u8c_disp_row(dst_drow--); - for (int dcol=0; dcol<disp_cols(); dcol++) + for (dcol =0; dcol<disp_cols(); dcol++) dst++->clear(*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; dcol<disp_cols(); dcol++) + for (dcol =0; dcol<disp_cols(); dcol++) *dst++ = *src++; // move } // Blank remaining rows downwards to End Of Display while (dst_drow < disp_rows()) { // walk srcrow to EOD Utf8Char *dst = u8c_disp_row(dst_drow++); - for (int dcol=0; dcol<disp_cols(); dcol++) + for (dcol =0; dcol<disp_cols(); dcol++) dst++->clear(*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(); col++) // delete left-to-right + int col; + for (col =dcol; col<disp_cols(); col++) // delete left-to-right if (col+rep >= 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; hrow<hist_rows(); hrow++) { + int hrow; + for (hrow =0; hrow<hist_rows(); hrow++) { Utf8Char *u8c = u8c_hist_row(hrow); // walk history rows.. - for (int hcol=0; hcol<hist_cols(); hcol++) { // ..and history cols + int hcol; + for (hcol =0; hcol<hist_cols(); hcol++) { // ..and history cols (u8c++)->clear(*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=<r>, 3=<g>, 4=<b> int r=0,g=0,b=0; - for (int i=0; i<tot; i++) { // expect possibly many values + int i; + for (i =0; i<tot; i++) { // expect possibly many values int val = esc.val(i); // each val one at a time switch (rgbmode) { case 0: @@ -3602,7 +3631,8 @@ void Fl_Terminal::draw_row_bg(int grow, int X, int Y) const { int end_col = disp_cols(); const Utf8Char *u8c = u8c_ring_row(grow) + start_col; // start of spec'd row uchar lastattr = u8c->attrib(); - for (int gcol=start_col; gcol<end_col; gcol++,u8c++) { // walk columns + int gcol; + for (gcol =start_col; gcol<end_col; gcol++,u8c++) { // walk columns // Attribute changed since last char? if (gcol==0 || u8c->attrib() != 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; gcol<end_col; gcol++,u8c++) { // walk the columns + int gcol; + for (gcol =start_col; gcol<end_col; gcol++,u8c++) { // walk the columns const int &dcol = gcol; // dcol and gcol are the same // Are we drawing the cursor? Only if inside display is_cursor = inside_display ? cursor_.is_rowcol(drow-scrollval, dcol) : 0; @@ -3711,7 +3742,8 @@ void Fl_Terminal::draw_buff(int Y) const { int srow = disp_srow() - scrollbar->value(); int erow = srow + disp_rows(); const int rowheight = current_style_->fontheight(); - for (int grow=srow; (grow<erow) && (Y<scrn_.b()); grow++) { + int grow; + for (grow =srow; (grow<erow) && (Y<scrn_.b()); grow++) { draw_row(grow, Y); // draw global row at Y Y += rowheight; // advance Y to bottom left corner of row } |
