summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2023-11-16 14:58:49 -0800
committerGreg Ercolano <erco@seriss.com>2023-11-16 15:45:29 -0800
commit38fc08c15f5f4dca0b5987bbae326bf8f5468aa5 (patch)
tree2f45e3b4b6061410cb3dfb607f811a9a12bcde99
parent01d30ed9cc4c080dea45ee85ec7af76cbd7e61bb (diff)
Added clear(), some methods protected->public
New public methods: void clear(void); void clear(Fl_Color val); old protected methods made public: void clear_screen(bool scroll_to_hist=true); // ESC [ 2 J void clear_screen_home(bool scroll_to_hist=true); // ESC [ H ESC [ 2 J void cursor_home(void); // ESC [ 0 H test/terminal modified to test these, and added separate tests for both the API and ANSI code ways to do these ops.
-rw-r--r--FL/Fl_Terminal.H12
-rw-r--r--src/Fl_Terminal.cxx19
-rw-r--r--test/terminal.fl126
3 files changed, 120 insertions, 37 deletions
diff --git a/FL/Fl_Terminal.H b/FL/Fl_Terminal.H
index d5ac13885..961713296 100644
--- a/FL/Fl_Terminal.H
+++ b/FL/Fl_Terminal.H
@@ -790,8 +790,6 @@ protected:
int w_to_col(int W) const;
int h_to_row(int H) const;
// API: Display clear operations
- void clear_screen(bool scroll_to_hist=true);
- void clear_screen_home(bool scroll_to_hist=true);
void clear_sod(void);
void clear_eod(void);
void clear_eol(void);
@@ -819,8 +817,13 @@ protected:
void history_use(int val, bool update=true);
public:
// API: Terminal operations
- void clear_history(void); // ESC [ 3 J
- void reset_terminal(void); // ESC c
+ void clear(void);
+ void clear(Fl_Color val);
+ void clear_screen(bool scroll_to_hist=true); // ESC [ 2 J
+ void clear_screen_home(bool scroll_to_hist=true); // ESC [ H ESC [ 2 J
+ void clear_history(void); // ESC [ 3 J
+ void reset_terminal(void); // ESC c
+ void cursor_home(void); // ESC [ 0 H
protected:
// Cursor management
int cursor_h(void) const;
@@ -841,7 +844,6 @@ protected:
void cursor_down(int count=1, bool do_scroll=false);
void cursor_left(int count=1);
void cursor_right(int count=1, bool do_scroll=false);
- void cursor_home(void);
void cursor_eol(void);
void cursor_sol(void);
void cursor_cr(void);
diff --git a/src/Fl_Terminal.cxx b/src/Fl_Terminal.cxx
index 75d174750..b9489edae 100644
--- a/src/Fl_Terminal.cxx
+++ b/src/Fl_Terminal.cxx
@@ -1591,6 +1591,25 @@ int Fl_Terminal::xy_to_glob_rowcol(int X, int Y, int &grow, int &gcol) const {
}
/**
+ Clears the screen to the current textbgcolor(), and homes the cursor.
+ \see clear_screen(), clear_screen_home(), cursor_home()
+*/
+void Fl_Terminal::clear(void) {
+ clear_screen_home();
+}
+
+/**
+ Clears the screen to a specific color \p val and homes the cursor.
+ \see clear_screen(), clear_screen_home(), cursor_home()
+*/
+void Fl_Terminal::clear(Fl_Color val) {
+ Fl_Color save = textbgcolor();
+ textbgcolor(val);
+ clear_screen_home();
+ textbgcolor(save);
+}
+
+/**
Clear the terminal screen only; does not affect the cursor position.
Also clears the current mouse selection.
diff --git a/test/terminal.fl b/test/terminal.fl
index a9d1aa7b8..9d519f5d1 100644
--- a/test/terminal.fl
+++ b/test/terminal.fl
@@ -1503,7 +1503,7 @@ switch ( G_tty->box() ) {
Fl_Window win {
label {Fl_Terminal Test}
callback {exit(0);} open
- xywh {437 156 857 838} type Double visible
+ xywh {0 0 897 838} type Double visible
} {
Fl_Spinner scrollhistory_input {
label {Scroll History}
@@ -1777,7 +1777,7 @@ Can be decimal (e.g. 12) or hex (e.g. \#0c, \#0000000c, etc)} xywh {521 151 77 2
}
Fl_Choice {} {
label {Terminal Color}
- xywh {364 187 145 20} down_box BORDER_BOX labelsize 12 textsize 12
+ xywh {389 187 145 20} down_box BORDER_BOX labelsize 9 textsize 9
} {
MenuItem {} {
label {White on DarkAmber}
@@ -1826,41 +1826,103 @@ add_lines(50);}
}
}
Fl_Group {} {
- label {Terminal Ops}
- xywh {608 21 115 210} box ENGRAVED_FRAME labelsize 11
+ label {Terminal Ops} open
+ xywh {608 21 152 210} box ENGRAVED_FRAME labelsize 11
} {
Fl_Button {} {
- label {Clear Screen}
- callback {G_tty->append("\\033[H\\033[2J"); // home, cls
+ label {Reset Terminal
+API}
+ callback {G_tty->reset_terminal();
G_tty->redraw();
// Reset the 'Add +50' line counter to 1
G_lines = 1;}
- tooltip {Clear terminal screen.
-Moves what was on the screen to the scroll history.} xywh {620 37 90 25} labelsize 11
+ tooltip {Reset terminal using reset_terminal()
+Clears: screen, history, sets default tabstops, etc.} xywh {616 26 64 24} labelsize 8
}
Fl_Button {} {
- label {Clear History}
- callback {G_tty->append("\\033[3J"); // clr history
+ label {Reset Terminal
+ANSI}
+ callback {G_tty->append("\\033c"); // reset terminal
+G_tty->redraw();
+// Reset the 'Add +50' line counter to 1
+G_lines = 1;}
+ tooltip {Reset terminal using ESC[c
+Clears: screen, history, sets default tabstops, etc.} xywh {686 26 64 24} labelsize 8
+ }
+ Fl_Button {} {
+ label {Home Cursor
+API}
+ callback {G_tty->cursor_home();
G_tty->redraw();}
- tooltip {Clear scrollback history.} xywh {620 68 90 25} labelsize 11
+ tooltip {Moves cursor to home position (top/left) using cursor_home()} xywh {616 54 64 24} labelsize 8
}
Fl_Button {} {
- label {Reset Terminal}
- callback {G_tty->append("\\033c"); // reset terminal
+ label {Home Cursor
+ANSI}
+ callback {G_tty->append("\\033[H");
+G_tty->redraw();}
+ tooltip {Moves cursor to home position (top/left) using ESC[H} xywh {686 54 64 24} labelsize 8
+ }
+ Fl_Button {} {
+ label {Clear History
+API}
+ callback {G_tty->clear_history();
G_tty->redraw();}
- tooltip {Reset terminal.
-Clears: screen, history, sets default tabstops, etc.} xywh {620 99 90 25} labelsize 11
+ tooltip {Clear scrollback history using clear_history()} xywh {616 82 64 24} labelsize 8
}
Fl_Button {} {
- label {Home Cursor}
- callback {G_tty->append("\\033[H");}
- tooltip {Moves cursor to home position (top/left) using ESC[H} xywh {620 130 90 25} labelsize 11
+ label {Clear History
+ANSI}
+ callback {G_tty->append("\\033[3J"); // clr history
+G_tty->redraw();}
+ tooltip {Clear scrollback history using ESC[3J} xywh {686 82 64 24} labelsize 8
+ }
+ Fl_Button {} {
+ label {Clear Screen
+API}
+ callback {G_tty->clear();
+G_tty->redraw();
+// Reset the 'Add +50' line counter to 1
+G_lines = 1;}
+ tooltip {Clear terminal screen using clear().
+Moves what was on the screen to the scroll history.} xywh {616 110 64 24} labelsize 8
+ }
+ Fl_Button {} {
+ label {Clear Screen
+ANSI}
+ callback {G_tty->append("\\033[H\\033[2J"); // home, cls
+G_tty->redraw();
+// Reset the 'Add +50' line counter to 1
+G_lines = 1;}
+ tooltip {Clear terminal screen using ESC[H + ESC[2J
+Moves what was on the screen to the scroll history.} xywh {686 110 64 24} labelsize 8
+ }
+ Fl_Group {} {open
+ xywh {616 138 134 24} box FLAT_BOX color 45
+ } {
+ Fl_Button {} {
+ label {Clear Screen
+To Color}
+ callback {Fl_Color c;
+if (parse_color(clear_color_input->value(), c) == -1 ) return;
+G_tty->clear(c);
+G_tty->redraw();
+// Reset the 'Add +50' line counter to 1
+G_lines = 1;}
+ tooltip {Clear terminal screen to specific color
+Moves what was on the screen to the scroll history.} xywh {616 138 64 24} labelsize 8
+ }
+ Fl_Input clear_color_input {
+ tooltip {The color used by "Clear Screen To Color" button
+Can be decimal (e.g. 12) or hex (e.g. \#0c, \#ff000000, etc)} xywh {686 138 64 24} labelsize 9 when 28 textfont 4 textsize 9
+ code0 {clear_color_input->value("\#ff000000");}
+ }
}
Fl_Button {} {
label {Speed Test}
callback {speed_test();}
tooltip {Runs a full screen random chars/colors
-Shortcut: S} xywh {620 161 90 25} shortcut 0x73 labelsize 11
+Shortcut: S} xywh {640 168 90 25} shortcut 0x73 labelsize 11
}
Fl_Button {} {
label {Ring Debug}
@@ -1871,52 +1933,52 @@ if (scrollhistory_input->value() > 35) {
}
// Show debug window
-G_tty->show_ring_debug_window();}
+G_tty->show_ring_debug_window();} selected
tooltip {Show the Fl_Terminal raw ring buffer contents.
-(Warning: This slows the UI and uses continuous cpu until closed)} xywh {620 193 90 25} labelsize 11
+(Warning: This slows the UI and uses continuous cpu until closed)} xywh {640 198 90 25} labelsize 11
}
}
Fl_Group {} {
label {Terminal Tests}
- xywh {731 21 115 210} box ENGRAVED_FRAME labelsize 11
+ xywh {767 21 115 210} box ENGRAVED_FRAME labelsize 11
} {
Fl_Button {} {
label {Unicode
Alignment}
callback {unicode_alignment();}
tooltip {Show a Unicode screen alignment test
-Checks that troublesome Unicode chars don't cause misalignment} xywh {742 31 90 30} labelsize 9
+Checks that troublesome Unicode chars don't cause misalignment} xywh {778 31 90 30} labelsize 9
}
Fl_Button {} {
label {+50 Lines}
callback {add_lines(50);}
tooltip {Add 50 lines of text to terminal.
-Tests screen history, scrollup} xywh {742 66 90 30} labelsize 9
+Tests screen history, scrollup} xywh {778 66 90 30} labelsize 9
}
Fl_Button {} {
label {Color Bars}
callback {show_colorbars();}
tooltip {Show colorbar test
Tests API for setting colors
-Does *NOT* use ESC codes} xywh {742 101 90 30} labelsize 11
+Does *NOT* use ESC codes} xywh {778 101 90 30} labelsize 11
}
Fl_Box {} {
label {Self Tests}
- xywh {746 173 90 15} labelsize 10
+ xywh {782 173 90 15} labelsize 10
}
Fl_Button {} {
label {@<<}
callback {NextEscapeTest(-1);}
comment {Move to previous test}
tooltip {Reverse through the ESC code self tests
-Shortcut: SHIFT+E} xywh {742 191 40 30} shortcut 0x10065 labelsize 11
+Shortcut: SHIFT+E} xywh {778 191 40 30} shortcut 0x10065 labelsize 11
}
Fl_Button {} {
label {@>>}
callback {NextEscapeTest(1);}
comment {Move to next test}
tooltip {Advance through the ESC code self tests
-Shortcut: 'e'} xywh {792 191 40 30} shortcut 0x65 labelsize 11
+Shortcut: 'e'} xywh {828 191 40 30} shortcut 0x65 labelsize 11
}
}
Fl_Input showfile_input {
@@ -1930,7 +1992,7 @@ showfile_input->activate();
command_input->activate();
Fl::focus(showfile_input); // return focus
win->redraw();}
- tooltip {Type in the pathname of a file to cat to the screen} xywh {109 238 737 25} labelsize 12 when 10 textfont 4
+ tooltip {Type in the pathname of a file to cat to the screen} xywh {109 238 773 25} labelsize 12 when 10 textfont 4
}
Fl_Input command_input {
label Command
@@ -1945,10 +2007,10 @@ Fl::focus(command_input); // return focus
win->redraw();}
tooltip {Command to run.
Hit ENTER to run command.
-The command's stdout will appear in terminal.} xywh {109 269 737 25} labelsize 12 when 12 textfont 4
+The command's stdout will appear in terminal.} xywh {109 269 773 25} labelsize 12 when 12 textfont 4
}
- Fl_Terminal tty {selected
- xywh {10 302 836 524} box DOWN_BOX
+ Fl_Terminal tty {
+ xywh {10 302 872 524} box DOWN_BOX
class MyTerminal
}
}