Add an option to set the character used for unused areas of the
[tmux-openbsd.git] / cmd-show-prompt-history.c
blobc85950b0a43eac97a880e38a7bbaa221f9f3a978
1 /* $OpenBSD$ */
3 /*
4 * Copyright (c) 2021 Anindya Mukherjee <anindya49@hotmail.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include "tmux.h"
21 #include <stdlib.h>
24 * Show or clear prompt history.
27 static enum cmd_retval cmd_show_prompt_history_exec(struct cmd *,
28 struct cmdq_item *);
30 const struct cmd_entry cmd_show_prompt_history_entry = {
31 .name = "show-prompt-history",
32 .alias = "showphist",
34 .args = { "T:", 0, 0, NULL },
35 .usage = "[-T type]",
37 .flags = CMD_AFTERHOOK,
38 .exec = cmd_show_prompt_history_exec
41 const struct cmd_entry cmd_clear_prompt_history_entry = {
42 .name = "clear-prompt-history",
43 .alias = "clearphist",
45 .args = { "T:", 0, 0, NULL },
46 .usage = "[-T type]",
48 .flags = CMD_AFTERHOOK,
49 .exec = cmd_show_prompt_history_exec
52 static enum cmd_retval
53 cmd_show_prompt_history_exec(struct cmd *self, struct cmdq_item *item)
55 struct args *args = cmd_get_args(self);
56 const char *typestr = args_get(args, 'T');
57 enum prompt_type type;
58 u_int tidx, hidx;
60 if (cmd_get_entry(self) == &cmd_clear_prompt_history_entry) {
61 if (typestr == NULL) {
62 for (tidx = 0; tidx < PROMPT_NTYPES; tidx++) {
63 free(status_prompt_hlist[tidx]);
64 status_prompt_hlist[tidx] = NULL;
65 status_prompt_hsize[tidx] = 0;
67 } else {
68 type = status_prompt_type(typestr);
69 if (type == PROMPT_TYPE_INVALID) {
70 cmdq_error(item, "invalid type: %s", typestr);
71 return (CMD_RETURN_ERROR);
73 free(status_prompt_hlist[type]);
74 status_prompt_hlist[type] = NULL;
75 status_prompt_hsize[type] = 0;
78 return (CMD_RETURN_NORMAL);
81 if (typestr == NULL) {
82 for (tidx = 0; tidx < PROMPT_NTYPES; tidx++) {
83 cmdq_print(item, "History for %s:\n",
84 status_prompt_type_string(tidx));
85 for (hidx = 0; hidx < status_prompt_hsize[tidx];
86 hidx++) {
87 cmdq_print(item, "%d: %s", hidx + 1,
88 status_prompt_hlist[tidx][hidx]);
90 cmdq_print(item, "%s", "");
92 } else {
93 type = status_prompt_type(typestr);
94 if (type == PROMPT_TYPE_INVALID) {
95 cmdq_error(item, "invalid type: %s", typestr);
96 return (CMD_RETURN_ERROR);
98 cmdq_print(item, "History for %s:\n",
99 status_prompt_type_string(type));
100 for (hidx = 0; hidx < status_prompt_hsize[type]; hidx++) {
101 cmdq_print(item, "%d: %s", hidx + 1,
102 status_prompt_hlist[type][hidx]);
104 cmdq_print(item, "%s", "");
107 return (CMD_RETURN_NORMAL);