Skip to content

Instantly share code, notes, and snippets.

@dagon666
Created December 31, 2013 16:23
Show Gist options
  • Save dagon666/8199108 to your computer and use it in GitHub Desktop.
Save dagon666/8199108 to your computer and use it in GitHub Desktop.
history keys
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