Introduce RZ_CMD_ARG_TYPE_FLAG and its autocomplete feature (#764)

This commit is contained in:
Aswin C 2021-03-05 14:58:22 +05:30 committed by GitHub
parent 9e5fff30e8
commit c997cc98f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -183,6 +183,18 @@ static void autocmplt_cmd_arg_macro(RzCore *core, RzLineNSCompletionResult *res,
}
}
static void autocmplt_cmd_arg_flag(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len) {
RzFlagItem *item;
RzListIter *iter;
RzList *list = rz_flag_all_list(core->flags, false);
rz_list_foreach (list, iter, item) {
char *flag = item->name;
if (!strncmp(flag, s, len)) {
rz_line_ns_completion_result_add(res, flag);
}
}
}
static bool offset_prompt_add_flag(RzFlagItem *fi, void *user) {
RzLineNSCompletionResult *res = (RzLineNSCompletionResult *)user;
rz_line_ns_completion_result_add(res, fi->name);
@ -428,6 +440,9 @@ static void autocmplt_cmd_arg(RzCore *core, RzLineNSCompletionResult *res, const
case RZ_CMD_ARG_TYPE_FCN_VAR:
autocmplt_cmd_arg_fcn_var(core, res, s, len);
break;
case RZ_CMD_ARG_TYPE_FLAG:
autocmplt_cmd_arg_flag(core, res, s, len);
break;
default:
break;
}

View file

@ -50,6 +50,7 @@ typedef enum rz_cmd_arg_type_t {
RZ_CMD_ARG_TYPE_EVAL_KEY, ///< Argument is the name of a evaluable variable (e.g. `et` command)
RZ_CMD_ARG_TYPE_EVAL_FULL, ///< Argument is the name+(optional)value of a evaluable variable (e.g. `e` command)
RZ_CMD_ARG_TYPE_FCN_VAR, ///< Argument is the name of a function variable/argument
RZ_CMD_ARG_TYPE_FLAG, ///< Argument is a rizin flag
} RzCmdArgType;
/**