From 33d071875623dc90e8da00d0491f97bc2558c861 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 14 Dec 2023 19:40:29 +0100 Subject: [PATCH] FLUID: option to show terminal, clear terminal, and clear history --- fluid/alignment_panel.cxx | 100 ++++++++++++++++++++++++++++++++++++-- fluid/alignment_panel.fl | 83 +++++++++++++++++++++++++++++-- fluid/alignment_panel.h | 1 + fluid/shell_command.cxx | 35 ++++++++----- fluid/shell_command.h | 4 +- test/hello.cxx | 2 +- 6 files changed, 206 insertions(+), 19 deletions(-) diff --git a/fluid/alignment_panel.cxx b/fluid/alignment_panel.cxx index ce2a6a884..96d21c994 100644 --- a/fluid/alignment_panel.cxx +++ b/fluid/alignment_panel.cxx @@ -965,6 +965,10 @@ Fl_Menu_Item menu_w_settings_shell_menu[] = { {0,0,0,0,0,0,0,0,0} }; +static void cb_T(Fl_Button*, void* v) { + if (v!=LOAD) show_terminal_window(); +} + Fl_Button *w_settings_shell_play=(Fl_Button *)0; static void cb_w_settings_shell_play(Fl_Button* o, void* v) { @@ -1266,6 +1270,72 @@ static void cb_save2(Fl_Check_Button* o, void* v) { } } +static void cb_show(Fl_Check_Button* o, void* v) { + int selected = w_settings_shell_list_selected; + if (v == LOAD) { + if (selected) { + o->value(!(g_shell_config->list[selected-1]->flags & Fd_Shell_Command::DONT_SHOW_TERMINAL)); + } else { + o->value(0); + } + } else { + if (selected) { + Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; + int v = o->value(); + if (!v) { + cmd->flags |= Fd_Shell_Command::DONT_SHOW_TERMINAL; + } else { + cmd->flags &= ~Fd_Shell_Command::DONT_SHOW_TERMINAL; + } + if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); + } + } +} + +static void cb_clear(Fl_Check_Button* o, void* v) { + int selected = w_settings_shell_list_selected; + if (v == LOAD) { + if (selected) { + o->value(g_shell_config->list[selected-1]->flags & Fd_Shell_Command::CLEAR_TERMINAL); + } else { + o->value(0); + } + } else { + if (selected) { + Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; + int v = o->value(); + if (v) { + cmd->flags |= Fd_Shell_Command::CLEAR_TERMINAL; + } else { + cmd->flags &= ~Fd_Shell_Command::CLEAR_TERMINAL; + } + if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); + } + } +} + +static void cb_clear1(Fl_Check_Button* o, void* v) { + int selected = w_settings_shell_list_selected; + if (v == LOAD) { + if (selected) { + o->value(g_shell_config->list[selected-1]->flags & Fd_Shell_Command::CLEAR_HISTORY); + } else { + o->value(0); + } + } else { + if (selected) { + Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; + int v = o->value(); + if (v) { + cmd->flags |= Fd_Shell_Command::CLEAR_HISTORY; + } else { + cmd->flags &= ~Fd_Shell_Command::CLEAR_HISTORY; + } + if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); + } + } +} + Fl_Box *w_settings_shell_fd_project=(Fl_Box *)0; static const unsigned char idata_fd_project[] = @@ -2741,6 +2811,12 @@ itional data in code and project files."); o->hide(); Fl_Group::current()->resizable(o); } // Fl_Box* o + { Fl_Button* o = new Fl_Button(246, 200, 24, 22, "T"); + o->tooltip("show terminal window"); + o->labelfont(5); + o->labelsize(11); + o->callback((Fl_Callback*)cb_T); + } // Fl_Button* o { w_settings_shell_play = new Fl_Button(270, 200, 50, 22, "Run"); w_settings_shell_play->tooltip("run the selected shell command"); w_settings_shell_play->labelsize(11); @@ -2852,24 +2928,42 @@ le"); o->end(); Fl_Group::current()->resizable(o); } // Fl_Group* o - { Fl_Check_Button* o = new Fl_Check_Button(100, 458, 220, 20, "save .fl project file"); + { Fl_Check_Button* o = new Fl_Check_Button(100, 458, 110, 20, "save .fl project file"); o->tooltip("save the project to the .fl file before running the command"); o->down_box(FL_DOWN_BOX); o->labelsize(11); o->callback((Fl_Callback*)cb_save); } // Fl_Check_Button* o - { Fl_Check_Button* o = new Fl_Check_Button(100, 478, 220, 19, "save source code"); + { Fl_Check_Button* o = new Fl_Check_Button(100, 478, 110, 19, "save source code"); o->tooltip("generate the source code and header file before running the command"); o->down_box(FL_DOWN_BOX); o->labelsize(11); o->callback((Fl_Callback*)cb_save1); } // Fl_Check_Button* o - { Fl_Check_Button* o = new Fl_Check_Button(100, 497, 220, 20, "save i18n strings"); + { Fl_Check_Button* o = new Fl_Check_Button(100, 498, 110, 20, "save i18n strings"); o->tooltip("save the internationalisation strings before running the command"); o->down_box(FL_DOWN_BOX); o->labelsize(11); o->callback((Fl_Callback*)cb_save2); } // Fl_Check_Button* o + { Fl_Check_Button* o = new Fl_Check_Button(214, 458, 106, 20, "show terminal"); + o->tooltip("show the terminal window when launching this script"); + o->down_box(FL_DOWN_BOX); + o->labelsize(11); + o->callback((Fl_Callback*)cb_show); + } // Fl_Check_Button* o + { Fl_Check_Button* o = new Fl_Check_Button(214, 478, 106, 19, "clear terminal"); + o->tooltip("clear the teminal window before running this script"); + o->down_box(FL_DOWN_BOX); + o->labelsize(11); + o->callback((Fl_Callback*)cb_clear); + } // Fl_Check_Button* o + { Fl_Check_Button* o = new Fl_Check_Button(214, 498, 106, 19, "clear term history"); + o->tooltip("clear the teminal history in the terminal window"); + o->down_box(FL_DOWN_BOX); + o->labelsize(11); + o->callback((Fl_Callback*)cb_clear1); + } // Fl_Check_Button* o w_settings_shell_cmd->end(); Fl_Group::current()->resizable(w_settings_shell_cmd); } // Fl_Group* w_settings_shell_cmd diff --git a/fluid/alignment_panel.fl b/fluid/alignment_panel.fl index 71f8f18dc..9ce4439a6 100644 --- a/fluid/alignment_panel.fl +++ b/fluid/alignment_panel.fl @@ -1014,6 +1014,11 @@ if (v==LOAD) { Fl_Box {} { xywh {253 200 13 22} hide resizable } + Fl_Button {} { + label T + callback {if (v!=LOAD) show_terminal_window();} + tooltip {show terminal window} xywh {246 200 24 22} labelfont 5 labelsize 11 + } Fl_Button w_settings_shell_play { label Run callback {int selected = w_settings_shell_list_selected; @@ -1348,7 +1353,7 @@ if (v == LOAD) { if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); } }} - tooltip {save the project to the .fl file before running the command} xywh {100 458 220 20} down_box DOWN_BOX labelsize 11 + tooltip {save the project to the .fl file before running the command} xywh {100 458 110 20} down_box DOWN_BOX labelsize 11 } Fl_Check_Button {} { label {save source code} @@ -1371,7 +1376,7 @@ if (v == LOAD) { if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); } }} - tooltip {generate the source code and header file before running the command} xywh {100 478 220 19} down_box DOWN_BOX labelsize 11 + tooltip {generate the source code and header file before running the command} xywh {100 478 110 19} down_box DOWN_BOX labelsize 11 } Fl_Check_Button {} { label {save i18n strings} @@ -1394,7 +1399,76 @@ if (v == LOAD) { if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); } }} - tooltip {save the internationalisation strings before running the command} xywh {100 497 220 20} down_box DOWN_BOX labelsize 11 + tooltip {save the internationalisation strings before running the command} xywh {100 498 110 20} down_box DOWN_BOX labelsize 11 + } + Fl_Check_Button {} { + label {show terminal} + callback {int selected = w_settings_shell_list_selected; +if (v == LOAD) { + if (selected) { + o->value(!(g_shell_config->list[selected-1]->flags & Fd_Shell_Command::DONT_SHOW_TERMINAL)); + } else { + o->value(0); + } +} else { + if (selected) { + Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; + int v = o->value(); + if (!v) { + cmd->flags |= Fd_Shell_Command::DONT_SHOW_TERMINAL; + } else { + cmd->flags &= ~Fd_Shell_Command::DONT_SHOW_TERMINAL; + } + if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); + } +}} + tooltip {show the terminal window when launching this script} xywh {214 458 106 20} down_box DOWN_BOX labelsize 11 + } + Fl_Check_Button {} { + label {clear terminal} + callback {int selected = w_settings_shell_list_selected; +if (v == LOAD) { + if (selected) { + o->value(g_shell_config->list[selected-1]->flags & Fd_Shell_Command::CLEAR_TERMINAL); + } else { + o->value(0); + } +} else { + if (selected) { + Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; + int v = o->value(); + if (v) { + cmd->flags |= Fd_Shell_Command::CLEAR_TERMINAL; + } else { + cmd->flags &= ~Fd_Shell_Command::CLEAR_TERMINAL; + } + if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); + } +}} + tooltip {clear the teminal window before running this script} xywh {214 478 106 19} down_box DOWN_BOX labelsize 11 + } + Fl_Check_Button {} { + label {clear term history} + callback {int selected = w_settings_shell_list_selected; +if (v == LOAD) { + if (selected) { + o->value(g_shell_config->list[selected-1]->flags & Fd_Shell_Command::CLEAR_HISTORY); + } else { + o->value(0); + } +} else { + if (selected) { + Fd_Shell_Command *cmd = g_shell_config->list[selected-1]; + int v = o->value(); + if (v) { + cmd->flags |= Fd_Shell_Command::CLEAR_HISTORY; + } else { + cmd->flags &= ~Fd_Shell_Command::CLEAR_HISTORY; + } + if (cmd->storage == FD_STORE_PROJECT) set_modflag(1); + } +}} + tooltip {clear the teminal history in the terminal window} xywh {214 498 106 19} down_box DOWN_BOX labelsize 11 } } Fl_Box w_settings_shell_fd_project { @@ -1607,3 +1681,6 @@ shell_run_window->hide();} decl {Fl_Menu_Item *w_layout_menu_storage[4];} {private global } + +Function {make_window()} {open +} {} diff --git a/fluid/alignment_panel.h b/fluid/alignment_panel.h index de30e014f..c5e6c8036 100644 --- a/fluid/alignment_panel.h +++ b/fluid/alignment_panel.h @@ -134,4 +134,5 @@ extern Fl_Double_Window *shell_run_window; extern Fl_Terminal *shell_run_terminal; extern Fl_Return_Button *shell_run_button; Fl_Double_Window* make_shell_window(); +void make_window(); #endif diff --git a/fluid/shell_command.cxx b/fluid/shell_command.cxx index 79b1609e8..28382636b 100644 --- a/fluid/shell_command.cxx +++ b/fluid/shell_command.cxx @@ -383,6 +383,22 @@ static void expand_macros(Fl_String &cmd) { expand_macro(cmd, "@TMPDIR@", get_tmpdir()); } +/** + Show the terminal window where it was last positioned. + */ +void show_terminal_window() { + Fl_Preferences pos(fluid_prefs, "shell_run_Window_pos"); + int x, y, w, h; + pos.get("x", x, -1); + pos.get("y", y, 0); + pos.get("w", w, 640); + pos.get("h", h, 480); + if (x!=-1) { + shell_run_window->resize(x, y, w, h); + } + shell_run_window->show(); +} + /** Prepare for and run a shell command. @@ -400,20 +416,17 @@ void run_shell_command(const Fl_String &cmd, int flags) { Fl_String expanded_cmd = cmd; expand_macros(expanded_cmd); - if (!shell_run_window->visible()) { - Fl_Preferences pos(fluid_prefs, "shell_run_Window_pos"); - int x, y, w, h; - pos.get("x", x, -1); - pos.get("y", y, 0); - pos.get("w", w, 640); - pos.get("h", h, 480); - if (x!=-1) { - shell_run_window->resize(x, y, w, h); - } - shell_run_window->show(); + if ( ((flags & Fd_Shell_Command::DONT_SHOW_TERMINAL) == 0) + && (!shell_run_window->visible())) + { + show_terminal_window(); } // Show the output window and clear things... + if (flags & Fd_Shell_Command::CLEAR_TERMINAL) + shell_run_terminal->printf("\033[2J\033[H"); + if (flags & Fd_Shell_Command::CLEAR_HISTORY) + shell_run_terminal->printf("\033[3J"); shell_run_terminal->printf("\033[0;32m%s\033[0m\n", expanded_cmd.c_str()); shell_run_window->label(expanded_cmd.c_str()); diff --git a/fluid/shell_command.h b/fluid/shell_command.h index 353874dfd..660c398de 100644 --- a/fluid/shell_command.h +++ b/fluid/shell_command.h @@ -42,6 +42,7 @@ class Fl_Preferences; char preferences_get(Fl_Preferences &prefs, const char *key, Fl_String &value, const Fl_String &defaultValue); char preferences_set(Fl_Preferences &prefs, const char *key, const Fl_String &value); +void show_terminal_window(); void run_shell_command(const Fl_String &cmd, int flags); bool shell_command_running(void); @@ -79,7 +80,8 @@ protected: class Fd_Shell_Command { public: enum { ALWAYS, NEVER, MAC_ONLY, UX_ONLY, WIN_ONLY, MAC_AND_UX_ONLY, USER_ONLY, HOST_ONLY, ENV_ONLY }; // conditions - enum { SAVE_PROJECT = 1, SAVE_SOURCECODE = 2, SAVE_STRINGS = 4, SAVE_ALL = 7 }; // flags + enum { SAVE_PROJECT = 1, SAVE_SOURCECODE = 2, SAVE_STRINGS = 4, SAVE_ALL = 7, + DONT_SHOW_TERMINAL = 8, CLEAR_TERMINAL = 16, CLEAR_HISTORY = 32 }; // flags Fd_Shell_Command(); Fd_Shell_Command(const Fd_Shell_Command *rhs); Fd_Shell_Command(const Fl_String &in_name); diff --git a/test/hello.cxx b/test/hello.cxx index d7308cd78..299d58098 100644 --- a/test/hello.cxx +++ b/test/hello.cxx @@ -26,6 +26,6 @@ int main(int argc, char **argv) { box->labelsize(36); box->labeltype(FL_SHADOW_LABEL); window->end(); - window->show(argc, argv); + window->show();//argc, argv); return Fl::run(); }