-
-
Save dagon666/8199108 to your computer and use it in GitHub Desktop.
history keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void _cli_history_up(void* a_ctx) { | |
| t_cli_ctx *ctx = (t_cli_ctx *)a_ctx; | |
| char prompt[12] = {0x00}; | |
| if ((ctx->hhead != ctx->htail) && | |
| strlen(ctx->history[ctx->hpos])) { | |
| memset(ctx->cmd, 0x00, CLI_CMD_BUFFER_SIZE); | |
| strcpy(ctx->cmd, ctx->history[ctx->hpos]); | |
| ctx->pos = strlen(ctx->cmd); | |
| if (!ctx->hpos) | |
| ctx->hpos = CLI_CMD_HISTORY_LEN - 1; | |
| else | |
| ctx->hpos--; | |
| snprintf(prompt, sizeof(prompt), "\r\n(%d/%d)", | |
| ctx->hpos, CLI_CMD_HISTORY_LEN); | |
| CLI_IO_OUTPUT(prompt, strlen(prompt)); | |
| CLI_IO_OUTPUT(ctx->cmd, strlen(ctx->cmd)); | |
| } | |
| } | |
| static void _cli_history_down(void* a_ctx) { | |
| t_cli_ctx *ctx = (t_cli_ctx *)a_ctx; | |
| char prompt[12] = {0x00}; | |
| if ((ctx->hhead != ctx->htail) && | |
| strlen(ctx->history[ctx->hpos])) { | |
| memset(ctx->cmd, 0x00, CLI_CMD_BUFFER_SIZE); | |
| ctx->hpos++; | |
| ctx->hpos %= CLI_CMD_HISTORY_LEN; | |
| strcpy(ctx->cmd, ctx->history[ctx->hpos]); | |
| ctx->pos = strlen(ctx->cmd); | |
| snprintf(prompt, sizeof(prompt), "\r\n(%d/%d)", | |
| ctx->hpos, CLI_CMD_HISTORY_LEN); | |
| CLI_IO_OUTPUT(prompt, strlen(prompt)); | |
| CLI_IO_OUTPUT(ctx->cmd, strlen(ctx->cmd)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment