Tue May 8 19:53:56 PDT 2001 Michael Jennings <mej@eterm.org>

You can now create key, mouse button, menu item, and buttonbar button
	bindings which trigger the parsing of a "script."  I've thrown in a
	few functions already to replace some icky escape sequences; there
	will be many more functions forthcoming, although I don't know how
	many of them (if any) will make it in prior to release.

	The usage is pretty simple.  Where before you might've said:

	    action string "\e]6;70\a"

	you would now say:

	    action script "exit();"

	You can call as many functions as you like per script.  Use a
	semi-colon (';') to separate each function call.  If you only call
	one function, the ';' is optional.  If you aren't passing parameters
	to the function, the parentheses are also optional.  Parameters are
	separated by commas and/or whitespace.

	Valid functions currently are:

	    die():     die() is a synonym for exit().
	    exec():    exec() is a synonym for spawn().
	    exit():    Exit Eterm.  Takes an optional exit code or message.
	    quit():    quit() is a synonym for exit().
	    save():    Save the config.  Specify "theme" to save the theme
	               config.  Also takes an optional path & filename.
	    search():  Search the scrollback buffer for a string.
	    spawn():   Spawns a sub-program.  Defaults to "Eterm".

	You will need the libast dated today to build and run this Eterm.
	You will also need to update your themes.


SVN revision: 4748
This commit is contained in:
Michael Jennings 2001-05-09 03:14:18 +00:00
parent dc861870c3
commit 0291d6b7a1
20 changed files with 232 additions and 70 deletions

View File

@ -4089,3 +4089,40 @@ Fri May 4 23:56:12 PDT 2001 Michael Jennings <mej@eterm.org>
backgrounds.
-------------------------------------------------------------------------------
Tue May 8 19:53:56 PDT 2001 Michael Jennings <mej@eterm.org>
You can now create key, mouse button, menu item, and buttonbar button
bindings which trigger the parsing of a "script." I've thrown in a
few functions already to replace some icky escape sequences; there
will be many more functions forthcoming, although I don't know how
many of them (if any) will make it in prior to release.
The usage is pretty simple. Where before you might've said:
action string "\e]6;70\a"
you would now say:
action script "exit();"
You can call as many functions as you like per script. Use a
semi-colon (';') to separate each function call. If you only call
one function, the ';' is optional. If you aren't passing parameters
to the function, the parentheses are also optional. Parameters are
separated by commas and/or whitespace.
Valid functions currently are:
die(): die() is a synonym for exit().
exec(): exec() is a synonym for spawn().
exit(): Exit Eterm. Takes an optional exit code or message.
quit(): quit() is a synonym for exit().
save(): Save the config. Specify "theme" to save the theme
config. Also takes an optional path & filename.
search(): Search the scrollback buffer for a string.
spawn(): Spawns a sub-program. Defaults to "Eterm".
You will need the libast dated today to build and run this Eterm.
You will also need to update your themes.
-------------------------------------------------------------------------------

View File

@ -34,11 +34,26 @@ static const char cvs_ident[] = "$Id$";
#include <signal.h>
#include "command.h"
#include "startup.h"
#include "options.h"
#include "pixmap.h"
#include "system.h"
#include "screen.h"
#include "script.h"
#include "startup.h"
#include "system.h"
static eterm_script_handler_t script_handlers[] =
{
{ "die", script_handler_exit },
{ "exec", script_handler_spawn },
{ "exit", script_handler_exit },
{ "quit", script_handler_exit },
{ "save", script_handler_save },
{ "search", script_handler_search },
{ "spawn", script_handler_spawn },
{ "nop", script_handler_nop }
};
static size_t handler_count = sizeof(script_handlers) / sizeof(eterm_script_handler_t);
#if 0
void
@ -104,6 +119,81 @@ eterm_handle_winop(char *action)
}
#endif
/********* HANDLERS **********/
void
script_handler_exit(char **params)
{
unsigned char code = 0;
char *tmp;
if (params && *params) {
if (isdigit(params[0][0]) || (params[0][0] == '-' && isdigit(params[0][1]))) {
code = (unsigned char) atoi(params[0]);
} else {
tmp = join(" ", params);
printf("Exiting: %s\n", tmp);
FREE(tmp);
}
}
exit(code);
}
void
script_handler_save(char **params)
{
if (params && *params) {
if (!strcasecmp(params[0], "theme")) {
save_config(params[1], SAVE_THEME_CONFIG);
} else {
save_config(params[0], SAVE_USER_CONFIG);
}
} else {
save_config(NULL, SAVE_USER_CONFIG);
}
}
void
script_handler_search(char **params)
{
scr_search_scrollback(params ? params[0] : NULL);
}
void
script_handler_spawn(char **params)
{
char *tmp;
if (params && *params) {
tmp = join(" ", params);
system_no_wait(tmp);
FREE(tmp);
} else {
system_no_wait("Eterm");
}
}
void
script_handler_nop(char **params)
{
USE_VAR(params);
}
/********* ENGINE *********/
eterm_script_handler_t *
script_find_handler(const char *name)
{
register unsigned long i;
for (i = 0; i < handler_count; i++) {
/* Small optimization. Only call strcasecmp() if the first letter matches. */
if ((tolower(name[0]) == tolower(script_handlers[i].name[0]))
&& !strcasecmp(name, script_handlers[i].name)) {
return &script_handlers[i];
}
}
return NULL;
}
void
script_parse(char *s)
{
@ -112,6 +202,7 @@ script_parse(char *s)
register unsigned long i;
char *func_name, *params, *tmp;
size_t len;
eterm_script_handler_t *func;
REQUIRE(s != NULL);
@ -137,25 +228,37 @@ script_parse(char *s)
func_name[len] = 0;
} else {
print_error("Error in script \"%s\": Missing function name before \"%s\".\n", s, params);
free_array((void **) token_list, 0);
return;
}
} else {
func_name = STRDUP(pstr);
}
if (func_name) {
chomp(func_name);
if (!func_name) {
free_array((void **) token_list, 0);
return;
}
if (params) {
params++;
if ((tmp = strchr(params, ')')) != NULL) {
if ((tmp = strrchr(params, ')')) != NULL) {
*tmp = 0;
} else {
print_error("Error in script \"%s\": Missing closing parentheses for \"%s\".\n", s, token_list[i]);
free_array((void **) token_list, 0);
return;
}
param_list = split(", \t", params);
}
D_SCRIPT(("Calling function %s with parameters: %s\n", NONULL(func_name), NONULL(params)));
D_SCRIPT(("Calling function %s with parameters: %s\n", func_name, NONULL(params)));
if ((func = script_find_handler(func_name)) != NULL) {
(func->handler)(param_list);
} else {
print_error("Error in script \"%s\": No such function \"%s\".\n", s, func_name);
}
}
if (params) {
free_array((void **) param_list, 0);
}
free_array((void **) token_list, 0);
}

View File

@ -31,12 +31,26 @@
/************ Macros and Definitions ************/
/************ Structures ************/
typedef void (*eterm_script_handler_function_t)(char **);
typedef struct {
char *name;
eterm_script_handler_function_t handler;
} eterm_script_handler_t;
/************ Variables ************/
/************ Function Prototypes ************/
_XFUNCPROTOBEGIN
/* Handlers */
extern void script_handler_exit(char **);
extern void script_handler_save(char **);
extern void script_handler_search(char **);
extern void script_handler_spawn(char **);
extern void script_handler_nop(char **);
/* Engine */
extern eterm_script_handler_t *script_find_handler(const char *);
extern void script_parse(char *);
_XFUNCPROTOEND

View File

@ -1841,7 +1841,7 @@ xterm_seq(int op, const char *str)
30-39 Foreground/Text Color Configuration
40-49 Background Color Configuration
50-69 Window/Window Manager Configuration/Interaction
70-79 Internal Eterm Operations
70+ Internal Eterm Operations
*/
switch (eterm_seq_op) {
#ifdef PIXMAP_SUPPORT
@ -2269,6 +2269,7 @@ xterm_seq(int op, const char *str)
XSendEvent(Xdisplay, Xroot, False, SubstructureNotifyMask, (XEvent *) & xev);
}
break;
#if 0
case 70:
/* Exit Eterm */
exit(0);
@ -2287,6 +2288,7 @@ xterm_seq(int op, const char *str)
save_config(NULL, SAVE_USER_CONFIG);
}
break;
#endif
case 72:
/* Search scrollback buffer for a string. NULL to clear. */
nstr = (char *) strsep(&tnstr, ";");
@ -2296,6 +2298,7 @@ xterm_seq(int op, const char *str)
scr_search_scrollback(NULL);
}
break;
#if 0
case 73:
/* Spawn a subprogram */
nstr = (char *) strsep(&tnstr, ";");
@ -2303,6 +2306,7 @@ xterm_seq(int op, const char *str)
system_no_wait(nstr);
}
break;
#endif
case 80:
/* Set debugging level */
nstr = (char *) strsep(&tnstr, ";");

View File

@ -879,11 +879,11 @@ begin menu
separator
begin menuitem
text "Save Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end
@ -905,7 +905,7 @@ begin menu
-
begin menuitem
text "New Window..."
action string "\e]6;73;Eterm\a"
action script "spawn(Eterm)"
end
begin menuitem
text "Version"
@ -918,15 +918,15 @@ begin menu
separator
begin menuitem
text "Save User Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Save Theme Settings..."
action string "\e]6;71;theme\a"
action script "save(theme)"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end

View File

@ -19,7 +19,7 @@ begin main
begin color
# Foreground, background, cursor, scrollbar, pointer colors
foreground white
foreground #aaaaaa
background black
cursor #ffff00
cursor_text #880000
@ -304,8 +304,8 @@ begin main
button Font action menu Font
button Background action menu Background
button Terminal action menu Terminal
rbutton icon help.png action string "\e]6;73;Eterm -e man Eterm\a"
rbutton icon exit.png action string "\e]6;70\a"
rbutton icon help.png action script "spawn(Eterm -e man Eterm)"
rbutton icon exit.png action script "exit"
end button_bar
# The XIM support options.

View File

@ -879,11 +879,11 @@ begin menu
separator
begin menuitem
text "Save Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end
@ -905,7 +905,7 @@ begin menu
-
begin menuitem
text "New Window..."
action string "\e]6;73;Eterm\a"
action script "spawn(Eterm)"
end
begin menuitem
text "Version"
@ -918,15 +918,15 @@ begin menu
separator
begin menuitem
text "Save User Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Save Theme Settings..."
action string "\e]6;71;theme\a"
action script "save(theme)"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end

View File

@ -19,7 +19,7 @@ begin main
begin color
# Foreground, background, cursor, scrollbar, pointer colors
foreground white
foreground #aaaaaa
background black
cursor #ffff00
cursor_text #880000
@ -304,8 +304,8 @@ begin main
button Font action menu Font
button Background action menu Background
button Terminal action menu Terminal
rbutton icon help.png action string "\e]6;73;Eterm -e man Eterm\a"
rbutton icon exit.png action string "\e]6;70\a"
rbutton icon help.png action script "spawn(Eterm -e man Eterm)"
rbutton icon exit.png action script "exit"
end button_bar
# The XIM support options.

View File

@ -879,11 +879,11 @@ begin menu
separator
begin menuitem
text "Save Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end
@ -905,7 +905,7 @@ begin menu
-
begin menuitem
text "New Window..."
action string "\e]6;73;Eterm\a"
action script "spawn(Eterm)"
end
begin menuitem
text "Version"
@ -918,15 +918,15 @@ begin menu
separator
begin menuitem
text "Save User Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Save Theme Settings..."
action string "\e]6;71;theme\a"
action script "save(theme)"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end

View File

@ -19,7 +19,7 @@ begin main
begin color
# Foreground, background, cursor, scrollbar, pointer colors
foreground white
foreground #aaaaaa
background black
cursor #ffff00
cursor_text #880000
@ -303,8 +303,8 @@ begin main
button Font action menu Font
button Background action menu Background
button Terminal action menu Terminal
rbutton icon help.png action string "\e]6;73;Eterm -e man Eterm\a"
rbutton icon exit.png action string "\e]6;70\a"
rbutton icon help.png action script "spawn(Eterm -e man Eterm)"
rbutton icon exit.png action script "exit"
end button_bar
# The XIM support options.

View File

@ -12,6 +12,10 @@ define(SUBMENU_ITEM, `begin menuitem
text "$1"
action submenu "$1"
end')
define(SCRIPT_ITEM, `begin menuitem
text "$1"
action script "$2"
end')
define(FONT_ITEM, `begin menuitem
text "$1"
action string "\e]50;#$2"
@ -979,11 +983,11 @@ begin menu
SUBMENU_ITEM(Background)
SUBMENU_ITEM(Terminal)
-
STRING_ITEM(`New Eterm Window', `\e]6;73;Eterm\a')
SCRIPT_ITEM(`New Eterm Window', `spawn(Eterm)')
STRING_ITEM(`Version', `\e[8n')
STRING_ITEM(`Status', `\e[9n')
separator
STRING_ITEM(`Save User Settings...', `\e]6;71\a')
STRING_ITEM(`Save Theme Settings...', `\e]6;71;theme\a')
STRING_ITEM(`Exit', `\e]6;70\a')
SCRIPT_ITEM(`Save User Settings...', `save')
SCRIPT_ITEM(`Save Theme Settings...', `save(theme)')
SCRIPT_ITEM(`Exit', `exit')
end

View File

@ -19,7 +19,7 @@ begin main
begin color
# Foreground, background, cursor, scrollbar, pointer colors
foreground white
foreground #aaaaaa
background black
cursor #ffff00
cursor_text #880000
@ -305,8 +305,8 @@ begin main
button rlogin action menu rlogin
button telnet action menu telnet
button ftp action menu ftp
rbutton icon help.png action string "\e]6;73;Eterm -e man Eterm\a"
rbutton icon exit.png action string "\e]6;70\a"
rbutton icon help.png action script "spawn(Eterm -e man Eterm)"
rbutton icon exit.png action script "exit"
end button_bar
# The XIM support options.

View File

@ -1128,15 +1128,15 @@ begin menu
separator
begin menuitem
text "Save User Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Save Theme Settings..."
action string "\e]6;71;theme\a"
action script "save(theme)"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end

View File

@ -19,7 +19,7 @@ begin main
begin color
# Foreground, background, cursor, scrollbar, pointer colors
foreground white
foreground #aaaaaa
background black
cursor #ffff00
cursor_text #880000
@ -306,8 +306,8 @@ begin main
button Edit action menu Edit
button Search action menu Search
button Help action menu Help
rbutton icon help.png action string "\e]6;73;Eterm -e man Eterm\a"
rbutton icon exit.png action string "\e]6;70\a"
rbutton icon help.png action script "spawn(Eterm -e man Eterm)"
rbutton icon exit.png action script "exit"
end button_bar
# The XIM support options.

View File

@ -879,11 +879,11 @@ begin menu
separator
begin menuitem
text "Save Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end
@ -905,7 +905,7 @@ begin menu
-
begin menuitem
text "New Window..."
action string "\e]6;73;Eterm\a"
action script "spawn(Eterm)"
end
begin menuitem
text "Version"
@ -918,15 +918,15 @@ begin menu
separator
begin menuitem
text "Save User Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Save Theme Settings..."
action string "\e]6;71;theme\a"
action script "save(theme)"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end

View File

@ -306,8 +306,8 @@ begin main
button Font action menu Font
button Background action menu Background
button Terminal action menu Terminal
rbutton icon help.png action string "\e]6;73;Eterm -e man Eterm\a"
rbutton icon exit.png action string "\e]6;70\a"
rbutton icon help.png action script "spawn(Eterm -e man Eterm)"
rbutton icon exit.png action script "exit"
end button_bar
# The XIM support options.

View File

@ -1062,15 +1062,15 @@ begin menu
separator
begin menuitem
text "Save User Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Save Theme Settings..."
action string "\e]6;71;theme\a"
action script "save(theme)"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end

View File

@ -19,7 +19,7 @@ begin main
begin color
# Foreground, background, cursor, scrollbar, pointer colors
foreground white
foreground #aaaaaa
background black
cursor #ffff00
cursor_text #880000
@ -302,8 +302,8 @@ begin main
button Eterm action menu Eterm
button Messages action menu Messages
button Mailbox action menu Mailbox
rbutton icon help.png action string "\e]6;73;Eterm -e man Eterm\a"
rbutton icon exit.png action string "\e]6;70\a"
rbutton icon help.png action script "spawn(Eterm -e man Eterm)"
rbutton icon exit.png action script "exit"
end button_bar
# The XIM support options.

View File

@ -879,11 +879,11 @@ begin menu
separator
begin menuitem
text "Save Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end
@ -905,7 +905,7 @@ begin menu
-
begin menuitem
text "New Window..."
action string "\e]6;73;Eterm\a"
action script "spawn(Eterm)"
end
begin menuitem
text "Version"
@ -918,15 +918,15 @@ begin menu
separator
begin menuitem
text "Save User Settings..."
action string "\e]6;71\a"
action script "save()"
end
begin menuitem
text "Save Theme Settings..."
action string "\e]6;71;theme\a"
action script "save(theme)"
end
begin menuitem
text "Exit"
action string "\e]6;70\a"
action script "exit"
end
end

View File

@ -19,7 +19,7 @@ begin main
begin color
# Foreground, background, cursor, scrollbar, pointer colors
foreground white
foreground #aaaaaa
background black
cursor #ffff00
cursor_text #880000
@ -304,8 +304,8 @@ begin main
button Font action menu Font
button Background action menu Background
button Terminal action menu Terminal
rbutton icon help.png action string "\e]6;73;Eterm -e man Eterm\a"
rbutton icon exit.png action string "\e]6;70\a"
rbutton icon help.png action script "spawn(Eterm -e man Eterm)"
rbutton icon exit.png action script "exit"
end button_bar
# The XIM support options.