1 /* Ex-mode-like commandline support */
12 #include "bfu/dialog.h"
13 #include "config/conf.h"
14 #include "config/kbdbind.h"
15 #include "config/options.h"
16 #include "dialogs/exmode.h"
17 #include "intl/gettext/libintl.h"
18 #include "main/module.h"
19 #include "session/session.h"
20 #include "session/task.h"
21 #include "terminal/terminal.h"
22 #include "util/error.h"
23 #include "util/memory.h"
24 #include "util/string.h"
25 #include "viewer/action.h"
28 /* The Ex-mode commandline is that blue-yellow thing which appears at the
29 * bottom of the screen when you press ':' and lets you enter various commands
30 * (just like in vi), especially actions, events (where they make sense) and
31 * config-file commands. */
34 #define EXMODE_HISTORY_FILENAME "exmodehist"
36 static INIT_INPUT_HISTORY(exmode_history
);
38 typedef int (*exmode_handler_T
)(struct session
*, unsigned char *, unsigned char *);
41 exmode_action_handler(struct session
*ses
, unsigned char *command
,
44 enum main_action action_id
= get_action_from_string(KEYMAP_MAIN
, command
);
46 if (action_id
== ACT_MAIN_NONE
) return 0;
47 if (action_id
== ACT_MAIN_QUIT
) action_id
= ACT_MAIN_REALLY_QUIT
;
50 return do_action(ses
, action_id
, 0) != FRAME_EVENT_IGNORED
;
53 case ACT_MAIN_GOTO_URL
:
54 goto_url_with_hook(ses
, args
);
63 exmode_confcmd_handler(struct session
*ses
, unsigned char *command
,
68 assert(ses
&& command
&& args
);
70 if (get_cmd_opt_bool("anonymous"))
73 /* Undo the arguments separation. */
74 if (*args
) *(--args
) = ' ';
76 err
= parse_config_exmode_command(command
);
80 static const exmode_handler_T exmode_handlers
[] = {
81 exmode_action_handler
,
82 exmode_confcmd_handler
,
87 exmode_exec(struct session
*ses
, unsigned char buffer
[INPUT_LINE_BUFFER_SIZE
])
89 /* First look it up as action, then try it as an event (but the event
90 * part should be thought out somehow yet, I s'pose... let's leave it
91 * off for now). Then try to evaluate it as configfile command. Then at
92 * least pop up an error. */
93 unsigned char *command
= buffer
;
94 unsigned char *args
= command
;
97 while (*command
== ':') command
++;
99 if (!*command
) return;
101 add_to_input_history(&exmode_history
, command
, 1);
104 if (*args
) *args
++ = 0;
106 for (i
= 0; exmode_handlers
[i
]; i
++) {
107 if (exmode_handlers
[i
](ses
, command
, args
))
113 static enum input_line_code
114 exmode_input_handler(struct input_line
*input_line
, int action_id
)
118 exmode_exec(input_line
->ses
, input_line
->buffer
);
119 return INPUT_LINE_CANCEL
;
122 return INPUT_LINE_PROCEED
;
127 exmode_start(struct session
*ses
)
129 input_field_line(ses
, ":", NULL
, &exmode_history
, exmode_input_handler
);
134 init_exmode(struct module
*module
)
136 load_input_history(&exmode_history
, EXMODE_HISTORY_FILENAME
);
140 done_exmode(struct module
*module
)
142 save_input_history(&exmode_history
, EXMODE_HISTORY_FILENAME
);
143 free_list(exmode_history
.entries
);
146 struct module exmode_module
= struct_module(
147 /* name: */ N_("Exmode"),
150 /* submodules: */ NULL
,
152 /* init: */ init_exmode
,
153 /* done: */ done_exmode