Sun Oct 13 00:57:37 2002 Michael Jennings (mej)

Moved "Escreen" menu to the new Escreen theme so it's no longer
hard-coded.

Added interactive prompting to search() script routine.

Changed dialog() routine to exec_dialog() and added editing of its
command line.

Added msgbox() script routine to display a message and wait for a
keypress.

Fixed a memory leak in the menu_dialog() function.  Also cleaned up
its event handling.

Added comments to the script routines that were missing them.

Make sure we exit cleanly if our window is destroyed.

Fixed the missing menus in the Escreen theme.  You'll still get an
error message when it loads, but I'm not that worried about it.


SVN revision: 6421
This commit is contained in:
Michael Jennings 2002-10-13 05:03:47 +00:00
parent af599dfb9c
commit a74ae94c5a
14 changed files with 310 additions and 45 deletions

View File

@ -4841,3 +4841,26 @@ Wed Oct 9 00:32:34 2002 Michael Jennings (mej)
Tidying up a bit.
----------------------------------------------------------------------
Sun Oct 13 00:57:37 2002 Michael Jennings (mej)
Moved "Escreen" menu to the new Escreen theme so it's no longer
hard-coded.
Added interactive prompting to search() script routine.
Changed dialog() routine to exec_dialog() and added editing of its
command line.
Added msgbox() script routine to display a message and wait for a
keypress.
Fixed a memory leak in the menu_dialog() function. Also cleaned up
its event handling.
Added comments to the script routines that were missing them.
Make sure we exit cleanly if our window is destroyed.
Fixed the missing menus in the Escreen theme. You'll still get an
error message when it loads, but I'm not that worried about it.
----------------------------------------------------------------------

View File

@ -633,6 +633,9 @@ begin menu
-
STRING_ITEM(`Steal Focus', `Ctrl-Button1', `\e]5;\a')
SCRIPT_ITEM(`New Eterm Window', `spawn(Eterm)')
SCRIPT_ITEM(`Search...', `search()')
SCRIPT_ITEM(`Run...', `Eterm -e ')
-
STRING_ITEM(`Version', `\e[8n')
STRING_ITEM(`Status', `\e[9n')
separator
@ -672,6 +675,9 @@ ifdef(`VIM', `
-
')
SCRIPT_ITEM(`New Eterm Window', `spawn(Eterm)')
SCRIPT_ITEM(`Search...', `search()')
SCRIPT_ITEM(`Run...', `Eterm -e ')
-
STRING_ITEM(`Version', `\e[8n')
STRING_ITEM(`Status', `\e[9n')
separator
@ -683,6 +689,9 @@ end
begin menu
title "Eterm Operations"
SCRIPT_ITEM(`New Eterm Window', `spawn(Eterm)')
SCRIPT_ITEM(`Search...', `search()')
SCRIPT_ITEM(`Run...', `Eterm -e ')
-
STRING_ITEM(`Version', `\e[8n')
STRING_ITEM(`Status', `\e[9n')
separator

View File

@ -2810,8 +2810,10 @@ make_escreen_menu(buttonbar_t *bbar)
{
static int been_here = 0;
button_t *button;
#if 0
menu_t *m;
menuitem_t *i;
#endif
if (been_here) { /* the start function may be called more than once */
return 0; /* in later versions, but we only want one EScreen menu */
@ -2819,6 +2821,7 @@ make_escreen_menu(buttonbar_t *bbar)
been_here = 1;
#if 0
if ((m = menu_create(NS_MENU_TITLE))) {
char *sc[] = {
/* display functions */
@ -2882,6 +2885,7 @@ make_escreen_menu(buttonbar_t *bbar)
if (!k) {
menu_init();
}
#endif
if ((button = button_create(NS_MENU_TITLE))) {
bbar_add_rbutton(bbar, button);
@ -2889,8 +2893,11 @@ make_escreen_menu(buttonbar_t *bbar)
button_set_action(button, ACTION_MENU, NS_MENU_TITLE);
}
return 1;
#if 0
}
return 0;
#endif
}
/* Set everything up for escreen mode */

View File

@ -298,8 +298,14 @@ handle_destroy_notify(event_t *ev)
XSelectInput(Xdisplay, ipc_win, None);
ipc_win = None;
(void) check_image_ipc(1);
return 1;
} else if (XEVENT_IS_MYWIN(ev, &primary_data)) {
/* One of our main windows was deleted. Exit cleanly. */
D_EVENTS((" -> Primary window destroyed. Terminating.\n"));
exit(0);
ASSERT_NOTREACHED_RVAL(1);
}
return 1;
return 0;
}
unsigned char

View File

@ -1318,16 +1318,18 @@ menu_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (v
inp_tab = NULL;
maxlen = 0;
retstr = NULL;
if ((b = strdup("Press \"Return\" to continue...")) == NULL)
if ((b = STRDUP("Press \"Return\" to continue...")) == NULL) {
return ret;
}
} else {
if (((b = MALLOC(maxlen + 1)) == NULL))
if (((b = MALLOC(maxlen + 1)) == NULL)) {
return ret;
if (*retstr) {
} else if (*retstr) {
strncpy(b, *retstr, maxlen);
b[maxlen] = '\0';
} else
} else {
b[0] = '\0';
}
}
/* Hide any menu that might've brought up this dialog. */
@ -1371,10 +1373,23 @@ menu_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (v
ungrab_pointer();
do {
do {
while (!XPending(Xdisplay));
XNextEvent(Xdisplay, &ev);
} while (ev.type != KeyPress);
int ret;
for (;;) {
ret = XNextEvent(Xdisplay, &ev);
D_MENU(("In menu_dialog(%s): XNextEvent() returned %d with a %s event.\n",
NONULL(prompt), ret, event_type_to_name(ev.type)));
/* Handle all events normally *except* for keypresses; those are handled here. */
if (ev.type == KeyPress) {
break;
} else {
process_x_event(&ev);
if (ev.type == Expose) {
/* Not very efficient, but we're waiting for user input, so screw it. */
scr_refresh(refresh_type);
}
}
}
len = XLookupString(&ev.xkey, (char *) kbuf, sizeof(short_buf), &keysym, NULL);
ch = kbuf[0];
@ -1416,7 +1431,11 @@ menu_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (v
/* we could just return b, but it might be longer than we need */
if (retstr) {
*retstr = (!maxlen || (f == 2)) ? NULL : strdup(b);
if (*retstr) {
/* Free the old string so we don't leak memory. */
FREE(*retstr);
}
*retstr = (!maxlen || (f == 2)) ? NULL : STRDUP(b);
}
ret = (f == 2) ? -2 : 0;
}

View File

@ -46,18 +46,6 @@ static eterm_script_handler_t script_handlers[] = {
{"copy", script_handler_copy},
{"die", script_handler_exit},
{"echo", script_handler_echo},
{"exec", script_handler_spawn},
{"exit", script_handler_exit},
{"kill", script_handler_kill},
{"paste", script_handler_paste},
{"quit", script_handler_exit},
{"save", script_handler_save},
{"save_buff", script_handler_save_buff},
{"scroll", script_handler_scroll},
{"search", script_handler_search},
{"spawn", script_handler_spawn},
{"string", script_handler_string},
{"dialog", script_handler_dialog},
#ifdef ESCREEN
{"es_display", script_handler_es_display},
{"es_disp", script_handler_es_display},
@ -69,6 +57,19 @@ static eterm_script_handler_t script_handlers[] = {
{"es_reset", script_handler_es_reset},
{"es_rst", script_handler_es_reset},
#endif
{"exec", script_handler_spawn},
{"exec_dialog", script_handler_exec_dialog},
{"exit", script_handler_exit},
{"kill", script_handler_kill},
{"msgbox", script_handler_msgbox},
{"paste", script_handler_paste},
{"quit", script_handler_exit},
{"save", script_handler_save},
{"save_buff", script_handler_save_buff},
{"scroll", script_handler_scroll},
{"search", script_handler_search},
{"spawn", script_handler_spawn},
{"string", script_handler_string},
{"nop", script_handler_nop}
};
@ -383,7 +384,14 @@ script_handler_scroll(char **params)
void
script_handler_search(char **params)
{
scr_search_scrollback(params ? params[0] : NULL);
static char *search = NULL;
if (params && *params) {
search = STRDUP(*params);
}
if ((menu_dialog(NULL, "Enter Search Term:", TERM_WINDOW_GET_REPORTED_COLS(), &search, NULL)) != -2) {
scr_search_scrollback(search);
}
}
/* spawn(): Spawns a child process to execute a sub-command
@ -422,42 +430,76 @@ script_handler_string(char **params)
}
}
/* nop(): Do nothing
/* exec_dialog(): Execute a program after prompting
*
* Syntax: nop()
* Syntax: exec_dialog(<command>)
*
* This function can be used to cancel undesired default behavior.
* <command> is the command to be executed.
*/
void
script_handler_nop(char **params)
script_handler_exec_dialog(char **params)
{
USE_VAR(params);
char *tmp;
int ret;
if (params && *params) {
tmp = join(" ", params);
} else {
tmp = NULL;
}
scr_refresh(DEFAULT_REFRESH);
ret = menu_dialog(NULL, "Confirm Command (ESC to cancel)", PATH_MAX, &tmp, NULL);
if (ret != -2) {
system_no_wait(tmp);
}
if (tmp) {
FREE(tmp);
}
}
/* msgbox(): Present a brief message box and wait for a keypress
*
* Syntax: msgbox(<message>)
*
* <message> is the message to present.
*/
void
script_handler_dialog(char **params)
script_handler_msgbox(char **params)
{
char *tmp;
if (params && *params) {
tmp = join(" ", params);
scr_refresh(DEFAULT_REFRESH);
menu_dialog(NULL, tmp, 1, NULL, NULL);
system_no_wait(tmp);
FREE(tmp);
} else {
menu_dialog(NULL, "Press any key to continue...", 1, NULL, NULL);
}
}
#ifdef ESCREEN
/* es_display(): Master command for manipulating Escreen displays
*
* Syntax: es_display(<subcommand>[, <subcommand params>])
*
* <subcommand> is the secondary command, one of the following:
*
* goto - Switch to the specified display (e.g., goto 2)
* prev - Switch to previous display
* next - Switch to next display
* toggle - Toggle display
* new - Create a new display with optional name, or "ask" to
* prompt the user for its name
* rename - Change the name of the current/specified display
* kill - Terminate a display
* watch - Toggle monitoring of a display for activity
* scrollback - View the scrollback for a display
*/
void
script_handler_es_display(char **params)
{
_ns_sess *sess = TermWin.screen;
char *p, *a;
int inx = 1;
int index = 1;
int no = -1; /* which display? */
if (!params || !*params || !sess) {
@ -465,10 +507,10 @@ script_handler_es_display(char **params)
}
p = downcase_str(*params);
a = params[inx++];
a = params[index++];
if (a && isdigit(*a)) {
no = atoi(a);
a = params[inx++];
a = params[index++];
D_ESCREEN(("disp #%d\n", no));
}
@ -522,13 +564,31 @@ script_handler_es_display(char **params)
}
}
/* es_region(): Master command for manipulating Escreen regions
*
* Syntax: es_region(<subcommand>[, <subcommand params>])
*
* <subcommand> is the secondary command, one of the following:
*
* goto - Switch to the specified region (e.g., goto 2)
* prev - Switch to previous region
* next - Switch to next region
* toggle - Toggle region
* new - Create a new region with optional name, or "ask" to
* prompt the user for its name
* rename - Change the name of the current/specified region
* kill - Terminate a region
* only - Maximize this region to the full display
* watch - Toggle monitoring of a region for activity
* scrollback - View the scrollback for a region
*/
void
script_handler_es_region(char **params)
{
_ns_sess *sess = TermWin.screen;
_ns_disp *disp;
char *p, *a;
int inx = 1;
int index = 1;
int no = -1;
if (!params || !*params || !sess) {
@ -542,10 +602,10 @@ script_handler_es_region(char **params)
}
p = downcase_str(*params);
a = params[inx++];
a = params[index++];
if (a && isdigit(*a)) {
no = atoi(a);
a = params[inx++];
a = params[index++];
D_ESCREEN(("region #%d\n", no));
}
@ -599,6 +659,12 @@ script_handler_es_region(char **params)
}
}
/* es_statement(): Execute an Escreen statement
*
* Syntax: es_statement(<statement>)
*
* <statement> is the Escreen (screen) statement to execute.
*/
void
script_handler_es_statement(char **params)
{
@ -613,6 +679,10 @@ script_handler_es_statement(char **params)
}
}
/* es_reset(): Reset the Escreen session
*
* Syntax: es_reset()
*/
void
script_handler_es_reset(char **params)
{
@ -621,6 +691,18 @@ script_handler_es_reset(char **params)
}
#endif
/* nop(): Do nothing
*
* Syntax: nop()
*
* This function can be used to cancel undesired default behavior.
*/
void
script_handler_nop(char **params)
{
USE_VAR(params);
}
/********* ENGINE *********/

View File

@ -45,8 +45,10 @@ _XFUNCPROTOBEGIN
/* Handlers */
extern void script_handler_copy(char **);
extern void script_handler_echo(char **);
extern void script_handler_exec_dialog(char **);
extern void script_handler_exit(char **);
extern void script_handler_kill(char **);
extern void script_handler_msgbox(char **);
extern void script_handler_paste(char **);
extern void script_handler_save(char **);
extern void script_handler_save_buff(char **);
@ -55,7 +57,6 @@ extern void script_handler_search(char **);
extern void script_handler_spawn(char **);
extern void script_handler_string(char **);
extern void script_handler_nop(char **);
extern void script_handler_dialog(char **);
#ifdef ESCREEN
extern void script_handler_es_display(char **);

View File

@ -1,11 +1,75 @@
<Eterm-0.9.2>
%include "../Eterm/menus.cfg"
%include "../Eterm/theme.cfg"
begin attributes
name "%appname() -- Escreen Session"
end attributes
begin menu
title Escreen
begin menuitem
text "New"
action script "es_display(new)"
end
begin menuitem
text "New..."
action script "es_display(new, ask)"
end
begin menuitem
text "Rename..."
action script "es_display(name, ask)"
end
begin menuitem
text "Backlog..."
action script "es_display(backlog)"
end
begin menuitem
text "Monitor"
action script "es_display(monitor)"
end
begin menuitem
text "Close"
action script "es_display(close)"
end
-
begin menuitem
text "Split"
action script "es_region(new)"
end
begin menuitem
text "Unsplit"
action script "es_region(full)"
end
begin menuitem
text "Prev region"
action script "es_region(prev)"
end
begin menuitem
text "Next region"
action script "es_region(next)"
end
begin menuitem
text "Kill region"
action script "es_region(kill)"
end
-
begin menuitem
text "Reset"
action script "es_reset()"
end
begin menuitem
text "Statement"
action script "es_statement()"
end
-
begin menuitem
text "About..."
action script "msgbox(Screen/Twin compatibility layer by Azundris <scream@azundris.com>)"
end
end menu
begin actions
bind alt Left to script "es_display(prev)"
bind alt Right to script "es_display(next)"
@ -13,7 +77,7 @@ begin actions
bind alt Down to script "es_region(next)"
bind alt Prior to script "es_display(prev)"
bind alt Next to script "es_display(next)"
bind alt Space to script "es_display(toggle)"
bind alt space to script "es_display(toggle)"
bind ctrl Tab to script "es_display(next)"
# alt-1..alt-0 -> display(0)..display(9)

View File

@ -747,6 +747,15 @@ begin menu
text "New Eterm Window"
action script "spawn(Eterm)"
end
begin menuitem
text "Search..."
action script "search()"
end
begin menuitem
text "Run..."
action script "Eterm -e "
end
-
begin menuitem
text "Version"
action string "\e[8n"
@ -775,6 +784,15 @@ begin menu
text "New Eterm Window"
action script "spawn(Eterm)"
end
begin menuitem
text "Search..."
action script "search()"
end
begin menuitem
text "Run..."
action script "Eterm -e "
end
-
begin menuitem
text "Version"
action string "\e[8n"

View File

@ -1,4 +1,4 @@
<Eterm-0.9.1>
<Eterm-0.9.2>
# ^- This must be the first line of any Eterm config file!
# Format is: <Eterm-VERSION> where VERSION is replaced by
# the version it was written for,

View File

@ -747,6 +747,15 @@ begin menu
text "New Eterm Window"
action script "spawn(Eterm)"
end
begin menuitem
text "Search..."
action script "search()"
end
begin menuitem
text "Run..."
action script "Eterm -e "
end
-
begin menuitem
text "Version"
action string "\e[8n"
@ -775,6 +784,15 @@ begin menu
text "New Eterm Window"
action script "spawn(Eterm)"
end
begin menuitem
text "Search..."
action script "search()"
end
begin menuitem
text "Run..."
action script "Eterm -e "
end
-
begin menuitem
text "Version"
action string "\e[8n"

View File

@ -1,4 +1,4 @@
<Eterm-0.9.1>
<Eterm-0.9.2>
begin color
foreground #aaaaaa

View File

@ -747,6 +747,15 @@ begin menu
text "New Eterm Window"
action script "spawn(Eterm)"
end
begin menuitem
text "Search..."
action script "search()"
end
begin menuitem
text "Run..."
action script "Eterm -e "
end
-
begin menuitem
text "Version"
action string "\e[8n"
@ -775,6 +784,15 @@ begin menu
text "New Eterm Window"
action script "spawn(Eterm)"
end
begin menuitem
text "Search..."
action script "search()"
end
begin menuitem
text "Run..."
action script "Eterm -e "
end
-
begin menuitem
text "Version"
action string "\e[8n"

View File

@ -1,4 +1,4 @@
<Eterm-0.9.1>
<Eterm-0.9.2>
begin color
foreground #aaaaaa