FLUID: shell code cleanup
This commit is contained in:
parent
f0375d6213
commit
828d8a0e2b
@ -1697,6 +1697,10 @@ Fl_Double_Window *shell_run_window=(Fl_Double_Window *)0;
|
||||
|
||||
Fl_Simple_Terminal *shell_run_terminal=(Fl_Simple_Terminal *)0;
|
||||
|
||||
static void cb_Clear(Fl_Button*, void*) {
|
||||
shell_run_terminal->clear();
|
||||
}
|
||||
|
||||
Fl_Return_Button *shell_run_button=(Fl_Return_Button *)0;
|
||||
|
||||
static void cb_shell_run_button(Fl_Return_Button*, void*) {
|
||||
@ -1713,9 +1717,13 @@ Fl_Double_Window* make_shell_window() {
|
||||
shell_run_window->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE));
|
||||
{ shell_run_terminal = new Fl_Simple_Terminal(10, 10, 535, 375);
|
||||
Fl_Group::current()->resizable(shell_run_terminal);
|
||||
shell_run_terminal->ansi(1);
|
||||
} // Fl_Simple_Terminal* shell_run_terminal
|
||||
{ Fl_Group* o = new Fl_Group(10, 395, 535, 25);
|
||||
{ Fl_Box* o = new Fl_Box(10, 395, 435, 25);
|
||||
{ Fl_Button* o = new Fl_Button(10, 395, 94, 25, "Clear");
|
||||
o->callback((Fl_Callback*)cb_Clear);
|
||||
} // Fl_Button* o
|
||||
{ Fl_Box* o = new Fl_Box(104, 395, 341, 25);
|
||||
o->hide();
|
||||
Fl_Group::current()->resizable(o);
|
||||
} // Fl_Box* o
|
||||
|
@ -116,7 +116,7 @@ Function {make_settings_window()} {open
|
||||
xywh {10 10 320 530} selection_color 12 labelsize 11 labelcolor 255
|
||||
} {
|
||||
Fl_Group {} {
|
||||
label General open selected
|
||||
label General open
|
||||
image {icons/general_64.png} compress_image 1 xywh {10 60 320 480} labelsize 11
|
||||
code0 {o->image()->scale(36, 24);}
|
||||
} {
|
||||
@ -981,12 +981,18 @@ Function {make_shell_window()} {open
|
||||
} {
|
||||
Fl_Simple_Terminal shell_run_terminal {
|
||||
xywh {10 10 535 375} resizable
|
||||
code0 {shell_run_terminal->ansi(1);}
|
||||
}
|
||||
Fl_Group {} {open
|
||||
xywh {10 395 535 25}
|
||||
} {
|
||||
Fl_Button {} {
|
||||
label Clear
|
||||
callback {shell_run_terminal->clear();} selected
|
||||
xywh {10 395 94 25}
|
||||
}
|
||||
Fl_Box {} {
|
||||
xywh {10 395 435 25} hide resizable
|
||||
xywh {104 395 341 25} hide resizable
|
||||
}
|
||||
Fl_Return_Button shell_run_button {
|
||||
label Close
|
||||
|
@ -721,6 +721,10 @@ void exit_cb(Fl_Widget *,void *) {
|
||||
delete sourceview_panel;
|
||||
sourceview_panel = 0;
|
||||
}
|
||||
if (shell_run_window) {
|
||||
save_position(shell_run_window,"shell_run_Window_pos");
|
||||
}
|
||||
|
||||
if (about_panel)
|
||||
delete about_panel;
|
||||
if (help_dialog)
|
||||
|
@ -262,6 +262,21 @@ static bool prepare_shell_command() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void shell_proc_done() {
|
||||
shell_run_terminal->append("... END SHELL COMMAND ...\n");
|
||||
shell_run_button->activate();
|
||||
shell_run_window->label("FLUID Shell");
|
||||
fl_beep();
|
||||
}
|
||||
|
||||
void shell_timer_cb(void*) {
|
||||
if (!s_proc.desc()) {
|
||||
shell_proc_done();
|
||||
} else {
|
||||
Fl::add_timeout(0.25, shell_timer_cb);
|
||||
}
|
||||
}
|
||||
|
||||
// Support the full piped shell command...
|
||||
void shell_pipe_cb(FL_SOCKET, void*) {
|
||||
char line[1024]=""; // Line from command output...
|
||||
@ -271,48 +286,46 @@ void shell_pipe_cb(FL_SOCKET, void*) {
|
||||
shell_run_terminal->append(line);
|
||||
} else {
|
||||
// End of file; tell the parent...
|
||||
Fl::remove_timeout(shell_timer_cb);
|
||||
Fl::remove_fd(s_proc.get_fileno());
|
||||
s_proc.close();
|
||||
shell_run_terminal->append("... END SHELL COMMAND ...\n");
|
||||
shell_proc_done();
|
||||
}
|
||||
}
|
||||
|
||||
void do_shell_command(Fl_Return_Button*, void*) {
|
||||
if (!prepare_shell_command()) return;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// Show the output window and clear things...
|
||||
shell_run_terminal->text("");
|
||||
shell_run_terminal->append(g_shell_command.c_str());
|
||||
shell_run_terminal->append("\n");
|
||||
shell_run_window->label("Shell Command Running...");
|
||||
shell_run_terminal->printf("\e[0;32m%s\e[0m\n", g_shell_command.c_str());
|
||||
shell_run_window->label(g_shell_command.c_str());
|
||||
|
||||
if (s_proc.popen((char *)g_shell_command.c_str()) == NULL) {
|
||||
fl_alert("Unable to run shell command: %s", strerror(errno));
|
||||
shell_run_terminal->printf("\e[1;31mUnable to run shell command: %s\e[0m\n",
|
||||
strerror(errno));
|
||||
shell_run_window->label("FLUID Shell");
|
||||
return;
|
||||
}
|
||||
|
||||
shell_run_button->deactivate();
|
||||
|
||||
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 the function below does not for some reason, we will check periodically
|
||||
// to see if the command is done
|
||||
Fl::add_timeout(0.25, shell_timer_cb);
|
||||
// this will tell us when the shell command is done
|
||||
Fl::add_fd(s_proc.get_fileno(), shell_pipe_cb);
|
||||
|
||||
while (s_proc.desc()) Fl::wait();
|
||||
|
||||
shell_run_button->activate();
|
||||
shell_run_window->label("Shell Command Complete");
|
||||
fl_beep();
|
||||
|
||||
while (shell_run_window->shown()) Fl::wait();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user