diff --git a/app/cli.c b/app/cli.c index e16913b5..d7ec9287 100644 --- a/app/cli.c +++ b/app/cli.c @@ -385,7 +385,7 @@ static struct zsv_ext_callbacks *zsv_ext_callbacks_init(struct zsv_ext_callbacks e->ext_opts_used = ext_opts_used; #ifdef ZSVSHEET_BUILD - e->ext_sheet_handler_key = zsvsheet_handler_key; + e->ext_sheet_keypress = zsvsheet_ext_keypress; e->ext_sheet_prompt = zsvsheet_ext_prompt; e->ext_sheet_handler_set_status = zsvsheet_handler_set_status; e->ext_sheet_handler_buffer_current = zsvsheet_handler_buffer_current; diff --git a/app/ext_example/my_extension.c b/app/ext_example/my_extension.c index f519859e..3283513b 100644 --- a/app/ext_example/my_extension.c +++ b/app/ext_example/my_extension.c @@ -9,9 +9,7 @@ #include #include #include -// #include -#include "../../include/zsv/ext/sheet.h" -#include "../../app/sheet/procedure.h" +#include #include /** @@ -71,15 +69,17 @@ static enum zsv_ext_status echo_main(zsv_execution_context ctx, int argc, const const char *opts_used); #ifdef ZSVSHEET_BUILD + /** * Here we define a custom command for the zsv `sheet` feature */ -zsvsheet_handler_status my_test_command_handler(struct zsvsheet_proc_context *ctx) { +zsvsheet_handler_status my_test_command_handler(zsvsheet_proc_context_t ctx) { char result_buffer[256] = {0}; - assert(ctx->invocation.type == zsvsheet_proc_invocation_type_keypress); + int ch = zsv_cb.ext_sheet_keypress(ctx); + if (ch < 0) + return zsvsheet_handler_status_error; zsv_cb.ext_sheet_prompt(ctx, result_buffer, sizeof(result_buffer), "You pressed %c. Now enter something here", - (char)ctx->invocation.u.keypress.ch); - + (char)ch); if (*result_buffer == '\0') return zsvsheet_handler_status_ok; diff --git a/app/sheet/handlers.c b/app/sheet/handlers.c index 69165146..d6a01321 100644 --- a/app/sheet/handlers.c +++ b/app/sheet/handlers.c @@ -52,8 +52,10 @@ zsvsheet_handler_status zsvsheet_handler_set_status(struct zsvsheet_proc_context /** * Get the key press that triggered this subcommand handler */ -int zsvsheet_handler_key(zsvsheet_subcommand_handler_context_t ctx) { - return ctx->ch; +int zsvsheet_ext_keypress(zsvsheet_proc_context_t ctx) { + if (ctx && ctx->invocation.type == zsvsheet_proc_invocation_type_keypress) + return ctx->invocation.u.keypress.ch; + return -1; } /** diff --git a/app/sheet/handlers_internal.h b/app/sheet/handlers_internal.h index c19d551e..bf2ff3bc 100644 --- a/app/sheet/handlers_internal.h +++ b/app/sheet/handlers_internal.h @@ -50,7 +50,7 @@ zsvsheet_handler_status zsvsheet_handler_set_status(struct zsvsheet_proc_context /** * Get the key press that triggered this subcommand handler */ -int zsvsheet_handler_key(zsvsheet_subcommand_handler_context_t ctx); +int zsvsheet_ext_keypress(zsvsheet_proc_context_t); /** * Get the current buffer diff --git a/include/zsv/ext.h b/include/zsv/ext.h index dbe24fcd..cb85744b 100644 --- a/include/zsv/ext.h +++ b/include/zsv/ext.h @@ -61,11 +61,6 @@ typedef void *zsv_execution_context; typedef enum zsv_ext_status (*zsv_ext_main)(zsv_execution_context ctx, int argc, const char *argv[], struct zsv_opts *opts, const char *opts_used); -typedef struct zsvsheet_proc_context *zsvsheet_proc_context_t; - -/* custom sheet handler id */ -typedef int zsvsheet_proc_id_t; - /** * ZSV callbacks structure * @@ -186,7 +181,7 @@ struct zsv_ext_callbacks { /** * Get the key press that triggered this subcommand handler */ - int (*ext_sheet_handler_key)(zsvsheet_subcommand_handler_context_t ctx); + int (*ext_sheet_keypress)(zsvsheet_proc_context_t ctx); /****** Managing buffers ******/ /** diff --git a/include/zsv/ext/sheet.h b/include/zsv/ext/sheet.h index 6e913c65..a35e9097 100644 --- a/include/zsv/ext/sheet.h +++ b/include/zsv/ext/sheet.h @@ -1,6 +1,11 @@ #ifndef ZSVSHEET_H #define ZSVSHEET_H +/* custom sheet handler id */ +typedef int zsvsheet_proc_id_t; + +typedef struct zsvsheet_proc_context *zsvsheet_proc_context_t; + typedef enum zsvsheet_handler_status { zsvsheet_handler_status_ok = 0, zsvsheet_handler_status_error, @@ -14,5 +19,6 @@ typedef struct zsvsheet_handler_context *zsvsheet_handler_context_t; typedef struct zsvsheet_subcommand_handler_context *zsvsheet_subcommand_handler_context_t; typedef void *zsvsheet_handler_buffer_t; +// int zsvsheet_ext_keypress(zsvsheet_proc_context_t); #endif