int flags; /* flags for the already parsed command */
} ExArg;
-typedef gboolean (*ExFunc)(const ExArg *arg);
+typedef VbCmdResult (*ExFunc)(const ExArg *arg);
typedef struct {
const char *name; /* full name of the command even if called abbreviated */
static gboolean parse_rhs(const char **input, ExArg *arg);
static void skip_whitespace(const char **input);
static void free_cmdarg(ExArg *arg);
-static gboolean execute(const ExArg *arg);
+static VbCmdResult execute(const ExArg *arg);
#ifdef FEATURE_AUTOCMD
-static gboolean ex_augroup(const ExArg *arg);
-static gboolean ex_autocmd(const ExArg *arg);
+static VbCmdResult ex_augroup(const ExArg *arg);
+static VbCmdResult ex_autocmd(const ExArg *arg);
#endif
-static gboolean ex_bookmark(const ExArg *arg);
-static gboolean ex_eval(const ExArg *arg);
-static gboolean ex_hardcopy(const ExArg *arg);
-static gboolean ex_map(const ExArg *arg);
-static gboolean ex_unmap(const ExArg *arg);
-static gboolean ex_normal(const ExArg *arg);
-static gboolean ex_open(const ExArg *arg);
+static VbCmdResult ex_bookmark(const ExArg *arg);
+static VbCmdResult ex_eval(const ExArg *arg);
+static VbCmdResult ex_hardcopy(const ExArg *arg);
+static VbCmdResult ex_map(const ExArg *arg);
+static VbCmdResult ex_unmap(const ExArg *arg);
+static VbCmdResult ex_normal(const ExArg *arg);
+static VbCmdResult ex_open(const ExArg *arg);
#ifdef FEATURE_QUEUE
-static gboolean ex_queue(const ExArg *arg);
+static VbCmdResult ex_queue(const ExArg *arg);
#endif
-static gboolean ex_register(const ExArg *arg);
-static gboolean ex_quit(const ExArg *arg);
-static gboolean ex_save(const ExArg *arg);
-static gboolean ex_set(const ExArg *arg);
-static gboolean ex_shellcmd(const ExArg *arg);
-static gboolean ex_shortcut(const ExArg *arg);
-static gboolean ex_handlers(const ExArg *arg);
+static VbCmdResult ex_register(const ExArg *arg);
+static VbCmdResult ex_quit(const ExArg *arg);
+static VbCmdResult ex_save(const ExArg *arg);
+static VbCmdResult ex_set(const ExArg *arg);
+static VbCmdResult ex_shellcmd(const ExArg *arg);
+static VbCmdResult ex_shortcut(const ExArg *arg);
+static VbCmdResult ex_handlers(const ExArg *arg);
static gboolean complete(short direction);
static void completion_select(char *match);
gboolean ex_run_string(const char *input)
{
+ VbCmdResult res;
ExArg *arg = g_slice_new0(ExArg);
arg->lhs = g_string_new("");
arg->rhs = g_string_new("");
history_add(HISTORY_COMMAND, input, NULL);
while (input && *input) {
- if (!parse(&input, arg) || !execute(arg)) {
+ if (!parse(&input, arg) || !(res = execute(arg))) {
free_cmdarg(arg);
return false;
}
}
+ /* check the result of the last executed command */
+ if (!(res & VB_CMD_KEEPINPUT)) {
+ /* clear input text on success if this is not explicit ommited */
+ vb_set_input_text("");
+ }
free_cmdarg(arg);
return true;
/**
* Executes the command given by ExArg.
*/
-static gboolean execute(const ExArg *arg)
+static VbCmdResult execute(const ExArg *arg)
{
return (commands[arg->idx].func)(arg);
}
}
#ifdef FEATURE_AUTOCMD
-static gboolean ex_augroup(const ExArg *arg)
+static VbCmdResult ex_augroup(const ExArg *arg)
{
- return autocmd_augroup(arg->lhs->str, arg->bang);
+ return autocmd_augroup(arg->lhs->str, arg->bang) ? VB_CMD_SUCCESS : VB_CMD_ERROR;
}
-static gboolean ex_autocmd(const ExArg *arg)
+static VbCmdResult ex_autocmd(const ExArg *arg)
{
- return autocmd_add(arg->rhs->str, arg->bang);
+ return autocmd_add(arg->rhs->str, arg->bang) ? VB_CMD_SUCCESS : VB_CMD_ERROR;
}
#endif
-static gboolean ex_bookmark(const ExArg *arg)
+static VbCmdResult ex_bookmark(const ExArg *arg)
{
if (arg->code == EX_BMR) {
if (bookmark_remove(*arg->rhs->str ? arg->rhs->str : vb.state.uri)) {
- vb_echo_force(VB_MSG_NORMAL, false, " Bookmark removed");
+ vb_echo_force(VB_MSG_NORMAL, true, " Bookmark removed");
- return true;
+ return VB_CMD_SUCCESS | VB_CMD_KEEPINPUT;
}
} else if (bookmark_add(vb.state.uri, webkit_web_view_get_title(vb.gui.webview), arg->rhs->str)) {
- vb_echo_force(VB_MSG_NORMAL, false, " Bookmark added");
+ vb_echo_force(VB_MSG_NORMAL, true, " Bookmark added");
- return true;
+ return VB_CMD_SUCCESS | VB_CMD_KEEPINPUT;
}
- return false;
+ return VB_CMD_ERROR;
}
-static gboolean ex_eval(const ExArg *arg)
+static VbCmdResult ex_eval(const ExArg *arg)
{
gboolean success;
- char *value = NULL;
+ char *value = NULL;
+ VbCmdResult res = VB_CMD_SUCCESS;
if (!arg->rhs->len) {
return false;
if (!arg->bang) {
if (success) {
vb_echo(VB_MSG_NORMAL, false, "%s", value);
+ res = VB_CMD_SUCCESS | VB_CMD_KEEPINPUT;
} else {
vb_echo(VB_MSG_ERROR, true, "%s", value);
+ res = VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
}
g_free(value);
- return success;
+ return res;
}
-static gboolean ex_hardcopy(const ExArg *arg)
+static VbCmdResult ex_hardcopy(const ExArg *arg)
{
webkit_web_frame_print(webkit_web_view_get_main_frame(vb.gui.webview));
- return true;
+ return VB_CMD_SUCCESS;
}
-static gboolean ex_map(const ExArg *arg)
+static VbCmdResult ex_map(const ExArg *arg)
{
if (!arg->lhs->len || !arg->rhs->len) {
- return false;
+ return VB_CMD_ERROR;
}
/* instead of using the EX_XMAP constants we use the first char of the
* command name as mode and the second to determine if noremap is used */
map_insert(arg->lhs->str, arg->rhs->str, arg->name[0], arg->name[1] != 'n');
- return true;;
+ return VB_CMD_SUCCESS;
}
-static gboolean ex_unmap(const ExArg *arg)
+static VbCmdResult ex_unmap(const ExArg *arg)
{
char *lhs;
if (!arg->lhs->len) {
- return false;
+ return VB_CMD_ERROR;
}
lhs = arg->lhs->str;
} else {
map_delete(lhs, 'i');
}
- return true;
+ return VB_CMD_SUCCESS;
}
-static gboolean ex_normal(const ExArg *arg)
+static VbCmdResult ex_normal(const ExArg *arg)
{
mode_enter('n');
/* if called with bang - don't apply mapping */
map_handle_string(arg->rhs->str, !arg->bang);
- return true;
+ return VB_CMD_SUCCESS;
}
-static gboolean ex_open(const ExArg *arg)
+static VbCmdResult ex_open(const ExArg *arg)
{
if (arg->code == EX_TABOPEN) {
- return vb_load_uri(&((Arg){VB_TARGET_NEW, arg->rhs->str}));
+ return vb_load_uri(&((Arg){VB_TARGET_NEW, arg->rhs->str})) ? VB_CMD_SUCCESS : VB_CMD_ERROR;
}
- return vb_load_uri(&((Arg){VB_TARGET_CURRENT, arg->rhs->str}));
+ return vb_load_uri(&((Arg){VB_TARGET_CURRENT, arg->rhs->str})) ? VB_CMD_SUCCESS :VB_CMD_ERROR;
}
#ifdef FEATURE_QUEUE
-static gboolean ex_queue(const ExArg *arg)
+static VbCmdResult ex_queue(const ExArg *arg)
{
Arg a = {0};
break;
default:
- return false;
+ return VB_CMD_ERROR;
}
/* if no argument is found in rhs, keep the uri in arg null to force
a.s = arg->rhs->str;
}
- return command_queue(&a);
+ return command_queue(&a)
+ ? VB_CMD_SUCCESS | VB_CMD_KEEPINPUT
+ : VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
#endif
/**
* Show the contents of the registers :reg.
*/
-static gboolean ex_register(const ExArg *arg)
+static VbCmdResult ex_register(const ExArg *arg)
{
int idx;
char *reg;
vb_echo(VB_MSG_NORMAL, false, "%s", str->str);
g_string_free(str, true);
- return true;
+ return VB_CMD_SUCCESS | VB_CMD_KEEPINPUT;
}
-static gboolean ex_quit(const ExArg *arg)
+static VbCmdResult ex_quit(const ExArg *arg)
{
vb_quit(arg->bang);
- return true;
+ return VB_CMD_SUCCESS;
}
-static gboolean ex_save(const ExArg *arg)
+static VbCmdResult ex_save(const ExArg *arg)
{
- return command_save(&((Arg){COMMAND_SAVE_CURRENT, arg->rhs->str}));
+ return command_save(&((Arg){COMMAND_SAVE_CURRENT, arg->rhs->str}))
+ ? VB_CMD_SUCCESS | VB_CMD_KEEPINPUT
+ : VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
-static gboolean ex_set(const ExArg *arg)
+static VbCmdResult ex_set(const ExArg *arg)
{
char *param = NULL;
return setting_run(arg->rhs->str, NULL);
}
-static gboolean ex_shellcmd(const ExArg *arg)
+static VbCmdResult ex_shellcmd(const ExArg *arg)
{
int status;
char *stdOut = NULL, *stdErr = NULL;
- gboolean success;
+ VbCmdResult res;
GError *error = NULL;
if (!*arg->rhs->str) {
- return false;
+ return VB_CMD_ERROR;
}
if (arg->bang) {
if (!g_spawn_command_line_async(arg->rhs->str, &error)) {
g_warning("Can't run '%s': %s", arg->rhs->str, error->message);
g_clear_error(&error);
- success = false;
+ res = VB_CMD_ERROR | VB_CMD_KEEPINPUT;
} else {
- success = true;
+ res = VB_CMD_SUCCESS;
}
} else {
if (!g_spawn_command_line_sync(arg->rhs->str, &stdOut, &stdErr, &status, &error)) {
g_warning("Can't run '%s': %s", arg->rhs->str, error->message);
g_clear_error(&error);
- success = false;
+ res = VB_CMD_ERROR | VB_CMD_KEEPINPUT;
} else {
/* the commands success depends not on the return code of the
* called shell command, so we know the result already here */
- success = true;
+ res = VB_CMD_SUCCESS | VB_CMD_KEEPINPUT;
}
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
}
}
- return success;
+ return res;
}
-static gboolean ex_handlers(const ExArg *arg)
+static VbCmdResult ex_handlers(const ExArg *arg)
{
char *p;
+ gboolean success = false;
switch (arg->code) {
case EX_HANDADD:
if (arg->rhs->len && (p = strchr(arg->rhs->str, '='))) {
*p++ = '\0';
- return handler_add(arg->rhs->str, p);
+ success = handler_add(arg->rhs->str, p);
}
- return false;
+ break;
case EX_HANDREM:
- return handler_remove(arg->rhs->str);
+ success = handler_remove(arg->rhs->str);
+ break;
default:
- return false;
+ break;
}
+
+ return success ? VB_CMD_SUCCESS : VB_CMD_ERROR;
}
-static gboolean ex_shortcut(const ExArg *arg)
+static VbCmdResult ex_shortcut(const ExArg *arg)
{
char *p;
+ gboolean success = false;
/* TODO allow to set shortcuts with set command like ':set
* shortcut[name]=http://donain.tld/?q=$0' */
case EX_SCA:
if (arg->rhs->len && (p = strchr(arg->rhs->str, '='))) {
*p++ = '\0';
- return shortcut_add(arg->rhs->str, p);
+ success = shortcut_add(arg->rhs->str, p);
}
- return false;
+ break;
case EX_SCR:
- return shortcut_remove(arg->rhs->str);
+ success = shortcut_remove(arg->rhs->str);
+ break;
case EX_SCD:
- return shortcut_set_default(arg->rhs->str);
+ success = shortcut_set_default(arg->rhs->str);
+ break;
default:
- return false;
+ break;
}
+ return success ? VB_CMD_SUCCESS : VB_CMD_ERROR;
}
/**
handler_add("magnet", "xdg-open '%s'");
}
-gboolean setting_run(char *name, const char *param)
+VbCmdResult setting_run(char *name, const char *param)
{
SettingType type = SETTING_SET;
char modifier;
Setting *s = g_hash_table_lookup(vb.config.settings, name);
if (!s) {
vb_echo(VB_MSG_ERROR, true, "Config '%s' not found", name);
- return false;
+ return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
if (type == SETTING_GET) {
setting_print(s);
- return true;
+ return VB_CMD_SUCCESS | VB_CMD_KEEPINPUT;
}
if (type == SETTING_TOGGLE) {
if (s->type != TYPE_BOOLEAN) {
vb_echo(VB_MSG_ERROR, true, "Could not toggle none boolean %s", s->name);
- return false;
+
+ return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
gboolean value = !s->value.b;
res = setting_set_value(s, &value, SETTING_SET);
if (!param) {
vb_echo(VB_MSG_ERROR, true, "No valid value");
- return false;
+ return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
/* convert sting value into internal used data type */
break;
}
}
- if (res == SETTING_OK || res & SETTING_USER_NOTIFIED) {
- return true;
+
+ if (res & (VB_CMD_SUCCESS | VB_CMD_KEEPINPUT)) {
+ return res;
}
vb_echo(VB_MSG_ERROR, true, "Could not set %s", s->name);
- return false;
+ return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
gboolean setting_fill_completion(GtkListStore *store, const char *input)
static int setting_set_value(Setting *prop, void *value, SettingType type)
{
- int res = SETTING_OK;
+ int res = VB_CMD_SUCCESS;
/* by default given value is also the new value */
void *newvalue = NULL;
gboolean free_newvalue;
if (prop->setter) {
res = prop->setter(prop->name, prop->type, newvalue, prop->data);
/* break here on error and don't change the setting */
- if (res & SETTING_ERROR) {
+ if (res & VB_CMD_ERROR) {
goto free;
}
}
g_object_set(G_OBJECT(web_setting), property, (char*)value, NULL);
break;
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int pagecache(const char *name, int type, void *value, void *data)
/* first set the setting on the web settings */
res = webkit(name, type, value, data);
- if (res == SETTING_OK && on) {
+ if (res == VB_CMD_SUCCESS && on) {
webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER);
} else {
/* reduce memory usage if caching is not used */
g_object_set(G_OBJECT(vb.session), property, (char*)value, NULL);
break;
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int internal(const char *name, int type, void *value, void *data)
OVERWRITE_STRING(*str, (char*)value);
break;
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int input_autohide(const char *name, int type, void *value, void *data)
gtk_widget_set_visible(GTK_WIDGET(vb.gui.input), true);
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int input_color(const char *name, int type, void *value, void *data)
VB_COLOR_PARSE((VbColor*)data, (char*)value);
vb_update_input_style();
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int statusbar(const char *name, int type, void *value, void *data)
{
gtk_widget_set_visible(GTK_WIDGET(vb.gui.statusbar.box), *(gboolean*)value);
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int status_color(const char *name, int type, void *value, void *data)
VB_COLOR_PARSE((VbColor*)data, (char*)value);
vb_update_status_style();
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int input_font(const char *name, int type, void *value, void *data)
*font = pango_font_description_from_string((char*)value);
vb_update_input_style();
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int status_font(const char *name, int type, void *value, void *data)
*font = pango_font_description_from_string((char*)value);
vb_update_status_style();
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
#ifdef FEATURE_COOKIE
if (!strcmp(map[i].name, policy)) {
g_object_set(jar, SOUP_COOKIE_JAR_ACCEPT_POLICY, map[i].policy, NULL);
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
}
vb_echo(VB_MSG_ERROR, true, "%s must be in [always, origin, never]", name);
- return SETTING_ERROR | SETTING_USER_NOTIFIED;
+ return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
#endif
g_warning("Could not load ssl database '%s': %s", (char*)value, error->message);
g_error_free(error);
- return SETTING_ERROR;
+ return VB_CMD_ERROR;
}
/* there is no function to get the file back from tls file database so
* it's saved as separate configuration */
g_object_set(vb.session, "tls-database", vb.config.tls_db, NULL);
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
#endif
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
static int user_style(const char *name, int type, void *value, void *data)
g_object_set(web_setting, "user-stylesheet-uri", NULL, NULL);
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
}
vb.config.headers = soup_header_parse_param_list((char*)value);
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
#ifdef FEATURE_ARH
/* add the new one */
vb.config.autoresponseheader = new;
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
} else {
vb_echo(VB_MSG_ERROR, true, "auto-response-header: %s", error);
- return SETTING_ERROR | SETTING_USER_NOTIFIED;
+ return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
}
#endif
} else {
OVERWRITE_STRING(vb.config.prevpattern, (char*)value);
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
- return SETTING_ERROR | SETTING_USER_NOTIFIED;
+ return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
}
static int fullscreen(const char *name, int type, void *value, void *data)
gtk_window_unfullscreen(GTK_WINDOW(vb.gui.window));
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
#ifdef FEATURE_HSTS
} else {
soup_session_remove_feature(vb.session, SOUP_SESSION_FEATURE(vb.config.hsts_provider));
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
#endif
if (!kilobytes) {
soup_cache_clear(vb.config.soup_cache);
}
- return SETTING_OK;
+ return VB_CMD_SUCCESS;
}
#endif