color configuration menu adapted to handle user-defined key bindings

This commit is contained in:
Frederic Culot 2008-12-08 19:17:06 +00:00
parent 639058740a
commit 7ff22e9b3f
9 changed files with 102 additions and 55 deletions

View File

@ -1,8 +1,14 @@
2008-12-08 Frederic Culot <frederic@culot.org>
* src/custom.c (custom_color_config_bar): new function
2008-12-07 Frederic Culot <frederic@culot.org> 2008-12-07 Frederic Culot <frederic@culot.org>
* src/keys.c: arrow keys can now also be used to define key * src/keys.c: arrow keys can now also be used to define key
bindings bindings
* src/keys.c (keys_check_missing_bindings): new function
2008-12-06 Frederic Culot <frederic@culot.org> 2008-12-06 Frederic Culot <frederic@culot.org>
* src/io.c (io_load_keys): use of a temporary file to log errors * src/io.c (io_load_keys): use of a temporary file to log errors

View File

@ -1,4 +1,4 @@
/* $calcurse: custom.c,v 1.28 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: custom.c,v 1.29 2008/12/08 19:17:07 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -432,6 +432,26 @@ custom_confwin_init (window_t *confwin, char *label)
} }
} }
static void
custom_color_config_bar (void)
{
binding_t quit = {_("Exit"), KEY_GENERIC_QUIT};
binding_t select = {_("Select"), KEY_GENERIC_SELECT};
binding_t nocolor = {_("No color"), KEY_GENERIC_CANCEL};
binding_t up = {_("Up"), KEY_MOVE_UP};
binding_t down = {_("Down"), KEY_MOVE_DOWN};
binding_t left = {_("Left"), KEY_MOVE_LEFT};
binding_t right = {_("Right"), KEY_MOVE_RIGHT};
binding_t *binding[] = {
&quit, &nocolor, &up, &down, &left, &right, &select
};
int binding_size = sizeof (binding) / sizeof (binding[0]);
keys_display_bindings_bar (win[STA].p, binding, 0, binding_size);
}
/* /*
* Used to display available colors in color configuration menu. * Used to display available colors in color configuration menu.
* This is useful for window resizing. * This is useful for window resizing.
@ -444,7 +464,6 @@ display_color_config (window_t *cwin, int *mark_fore, int *mark_back,
#define DEFAULTCOLOR 255 #define DEFAULTCOLOR 255
#define DEFAULTCOLOR_EXT -1 #define DEFAULTCOLOR_EXT -1
#define CURSOR (32 | A_REVERSE) #define CURSOR (32 | A_REVERSE)
#define SPACE 32
#define MARK 88 #define MARK 88
char *fore_txt = _("Foreground"); char *fore_txt = _("Foreground");
@ -452,9 +471,6 @@ display_color_config (window_t *cwin, int *mark_fore, int *mark_back,
char *default_txt = _("(terminal's default)"); char *default_txt = _("(terminal's default)");
char *bar = " "; char *bar = " ";
char *box = "[ ]"; char *box = "[ ]";
char *choose_color_1 = _("Use 'X' or SPACE to select a color, "
"'H/L' 'J/K' or arrow keys to move");
char *choose_color_2 = _("('0' for no color, 'Q' to exit) :");
char label[BUFSIZ]; char label[BUFSIZ];
const unsigned Y = 3; const unsigned Y = 3;
const unsigned XOFST = 5; const unsigned XOFST = 5;
@ -559,7 +575,7 @@ display_color_config (window_t *cwin, int *mark_fore, int *mark_back,
} }
mvwaddch (cwin->p, pos[cursor][YPOS], pos[cursor][XPOS] + 1, CURSOR); mvwaddch (cwin->p, pos[cursor][YPOS], pos[cursor][XPOS] + 1, CURSOR);
status_mesg (choose_color_1, choose_color_2); custom_color_config_bar ();
wnoutrefresh (win[STA].p); wnoutrefresh (win[STA].p);
wnoutrefresh (cwin->p); wnoutrefresh (cwin->p);
doupdate (); doupdate ();
@ -585,7 +601,7 @@ custom_color_config (void)
display_color_config (&conf_win, &mark_fore, &mark_back, cursor, display_color_config (&conf_win, &mark_fore, &mark_back, cursor,
need_reset, theme_changed); need_reset, theme_changed);
while ((ch = wgetch (win[STA].p)) != 'q') while ((ch = keys_getch (win[STA].p)) != KEY_GENERIC_QUIT)
{ {
need_reset = 0; need_reset = 0;
theme_changed = 0; theme_changed = 0;
@ -599,9 +615,7 @@ custom_color_config (void)
need_reset = 1; need_reset = 1;
break; break;
case SPACE: case KEY_GENERIC_SELECT:
case 'X':
case 'x':
colorize = true; colorize = true;
need_reset = 1; need_reset = 1;
theme_changed = 1; theme_changed = 1;
@ -611,35 +625,27 @@ custom_color_config (void)
mark_fore = cursor; mark_fore = cursor;
break; break;
case KEY_DOWN: case KEY_MOVE_DOWN:
case 'J':
case 'j':
if (cursor < SIZE - 1) if (cursor < SIZE - 1)
++cursor; ++cursor;
break; break;
case KEY_UP: case KEY_MOVE_UP:
case 'K':
case 'k':
if (cursor > 0) if (cursor > 0)
--cursor; --cursor;
break; break;
case KEY_LEFT: case KEY_MOVE_LEFT:
case 'H':
case 'h':
if (cursor > NBUSERCOLORS) if (cursor > NBUSERCOLORS)
cursor -= (NBUSERCOLORS + 1); cursor -= (NBUSERCOLORS + 1);
break; break;
case KEY_RIGHT: case KEY_MOVE_RIGHT:
case 'L':
case 'l':
if (cursor <= NBUSERCOLORS) if (cursor <= NBUSERCOLORS)
cursor += (NBUSERCOLORS + 1); cursor += (NBUSERCOLORS + 1);
break; break;
case '0': case KEY_GENERIC_CANCEL:
colorize = false; colorize = false;
need_reset = 1; need_reset = 1;
break; break;
@ -1073,6 +1079,8 @@ custom_keys_config (void)
delwin (grabwin); delwin (grabwin);
} }
while (used); while (used);
nbrowelm++;
if (selelm < nbrowelm - 1)
selelm++; selelm++;
#undef WINROW #undef WINROW
#undef WINCOL #undef WINCOL
@ -1081,10 +1089,16 @@ custom_keys_config (void)
keystr = keys_action_nkey (selrow, selelm); keystr = keys_action_nkey (selrow, selelm);
keyval = keys_str2int (keystr); keyval = keys_str2int (keystr);
keys_remove_binding (keyval, selrow); keys_remove_binding (keyval, selrow);
if (selelm > 0) nbrowelm--;
if (selelm > 0 && selelm <= nbrowelm)
selelm--; selelm--;
break; break;
case KEY_GENERIC_QUIT: case KEY_GENERIC_QUIT:
if (keys_check_missing_bindings () != 0)
{
ERROR_MSG (_("Some actions do not have any associated "
"key bindings!"));
}
wins_scrollwin_delete (&kwin); wins_scrollwin_delete (&kwin);
return; return;
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: day.c,v 1.39 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: day.c,v 1.40 2008/12/08 19:17:07 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -736,7 +736,7 @@ day_edit_item (conf_t *conf)
case RECUR_EVNT: case RECUR_EVNT:
re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT)); re = recur_get_event (date, day_item_nb (date, item_num, RECUR_EVNT));
status_mesg (_("Edit: (1)Description or (2)Repetition?"), "[1/2] "); status_mesg (_("Edit: (1)Description or (2)Repetition?"), "[1/2] ");
while (ch != '1' && ch != '2' && ch != KEY_GENERIC_ESCAPE) while (ch != '1' && ch != '2' && ch != KEY_GENERIC_CANCEL)
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
switch (ch) switch (ch)
{ {
@ -759,7 +759,7 @@ day_edit_item (conf_t *conf)
status_mesg (_("Edit: (1)Start time, (2)End time, " status_mesg (_("Edit: (1)Start time, (2)End time, "
"(3)Description or (4)Repetition?"), "[1/2/3/4] "); "(3)Description or (4)Repetition?"), "[1/2/3/4] ");
while (ch != STRT && ch != END && ch != DESC && while (ch != STRT && ch != END && ch != DESC &&
ch != REPT && ch != KEY_GENERIC_ESCAPE) ch != REPT && ch != KEY_GENERIC_CANCEL)
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
switch (ch) switch (ch)
{ {
@ -775,7 +775,7 @@ day_edit_item (conf_t *conf)
case REPT: case REPT:
update_rept (&ra->rpt, ra->start, conf); update_rept (&ra->rpt, ra->start, conf);
break; break;
case KEY_GENERIC_ESCAPE: case KEY_GENERIC_CANCEL:
return; return;
} }
break; break;
@ -783,7 +783,7 @@ day_edit_item (conf_t *conf)
a = apoint_get (date, day_item_nb (date, item_num, APPT)); a = apoint_get (date, day_item_nb (date, item_num, APPT));
status_mesg (_("Edit: (1)Start time, (2)End time " status_mesg (_("Edit: (1)Start time, (2)End time "
"or (3)Description?"), "[1/2/3] "); "or (3)Description?"), "[1/2/3] ");
while (ch != STRT && ch != END && ch != DESC && ch != KEY_GENERIC_ESCAPE) while (ch != STRT && ch != END && ch != DESC && ch != KEY_GENERIC_CANCEL)
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);
switch (ch) switch (ch)
{ {
@ -796,7 +796,7 @@ day_edit_item (conf_t *conf)
case DESC: case DESC:
update_desc (&a->mesg); update_desc (&a->mesg);
break; break;
case KEY_GENERIC_ESCAPE: case KEY_GENERIC_CANCEL:
return; return;
} }
break; break;
@ -852,7 +852,7 @@ day_erase_item (long date, int item_number, erase_flag_e flag)
{ {
if (flag == ERASE_FORCE_ONLY_NOTE) if (flag == ERASE_FORCE_ONLY_NOTE)
ch = 'a'; ch = 'a';
while ((ch != 'a') && (ch != 'o') && (ch != KEY_GENERIC_ESCAPE)) while ((ch != 'a') && (ch != 'o') && (ch != KEY_GENERIC_CANCEL))
{ {
status_mesg (erase_warning, erase_choice); status_mesg (erase_warning, erase_choice);
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);

View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.45 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: io.c,v 1.46 2008/12/08 19:17:07 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -1707,7 +1707,6 @@ ical_unformat_line (char *line)
static char * static char *
ical_unfold_content (FILE *fd, char *line, unsigned *lineno) ical_unfold_content (FILE *fd, char *line, unsigned *lineno)
{ {
const int CHAR_SPACE = 32;
char *content; char *content;
int c; int c;
@ -1718,7 +1717,7 @@ ical_unfold_content (FILE *fd, char *line, unsigned *lineno)
for (;;) for (;;)
{ {
c = getc (fd); c = getc (fd);
if (c == CHAR_SPACE || c == TAB) if (c == SPACE || c == TAB)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -2703,7 +2702,7 @@ void
io_log_print (io_file_t *log, int line, char *msg) io_log_print (io_file_t *log, int line, char *msg)
{ {
if (log && log->fd) if (log && log->fd)
fprintf (log->fd, "[%d]: %s\n", line, msg); fprintf (log->fd, "line %d: %s\n", line, msg);
} }
void void

View File

@ -1,4 +1,4 @@
/* $calcurse: keys.c,v 1.7 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: keys.c,v 1.8 2008/12/08 19:17:07 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -50,6 +50,7 @@ static keys_e actions[MAXKEYVAL];
static struct keydef_s keydef[NBKEYS] = { static struct keydef_s keydef[NBKEYS] = {
{"generic-escape", "ESC"}, {"generic-escape", "ESC"},
{"generic-select", "SPC"},
{"generic-credits", "@"}, {"generic-credits", "@"},
{"generic-help", "?"}, {"generic-help", "?"},
{"generic-quit", "q Q"}, {"generic-quit", "q Q"},
@ -105,9 +106,10 @@ dump_intro (FILE *fd)
"#\n" "#\n"
"# To define bindings which use the CONTROL key, prefix the key with " "# To define bindings which use the CONTROL key, prefix the key with "
"'C-'.\n" "'C-'.\n"
"# The escape and horizontal Tab key can be specified using the 'ESC'\n" "# The escape, space bar and horizontal Tab key can be specified using\n"
"# and 'TAB' keyword, respectively. Arrow keys can also be specified\n" "# the 'ESC', 'SPC' and 'TAB' keyword, respectively.\n"
"# with the UP, DWN, LFT, RGT keywords.\n#\n" "# Arrow keys can also be specified with the UP, DWN, LFT, RGT keywords."
"\n#\n"
"# A description of what each ACTION keyword is used for is available\n" "# A description of what each ACTION keyword is used for is available\n"
"# from calcurse online configuration menu.\n"); "# from calcurse online configuration menu.\n");
@ -164,8 +166,13 @@ keys_getch (WINDOW *win)
int ch; int ch;
ch = wgetch (win); ch = wgetch (win);
switch (ch)
{
case KEY_RESIZE:
return KEY_RESIZE;
default:
return keys_get_action (ch); return keys_get_action (ch);
}
} }
static void static void
@ -253,6 +260,7 @@ keys_str2int (char *key)
{ {
const string_t CONTROL_KEY = STRING_BUILD ("C-"); const string_t CONTROL_KEY = STRING_BUILD ("C-");
const string_t TAB_KEY = STRING_BUILD ("TAB"); const string_t TAB_KEY = STRING_BUILD ("TAB");
const string_t SPACE_KEY = STRING_BUILD ("SPC");
const string_t ESCAPE_KEY = STRING_BUILD ("ESC"); const string_t ESCAPE_KEY = STRING_BUILD ("ESC");
const string_t CURSES_KEY_UP = STRING_BUILD ("UP"); const string_t CURSES_KEY_UP = STRING_BUILD ("UP");
const string_t CURSES_KEY_DOWN = STRING_BUILD ("DWN"); const string_t CURSES_KEY_DOWN = STRING_BUILD ("DWN");
@ -273,6 +281,8 @@ keys_str2int (char *key)
return TAB; return TAB;
else if (!strncmp (key, ESCAPE_KEY.str, ESCAPE_KEY.len)) else if (!strncmp (key, ESCAPE_KEY.str, ESCAPE_KEY.len))
return ESCAPE; return ESCAPE;
else if (!strncmp (key, SPACE_KEY.str, SPACE_KEY.len))
return SPACE;
else if (!strncmp (key, CURSES_KEY_UP.str, CURSES_KEY_UP.len)) else if (!strncmp (key, CURSES_KEY_UP.str, CURSES_KEY_UP.len))
return KEY_UP; return KEY_UP;
else if (!strncmp (key, CURSES_KEY_DOWN.str, CURSES_KEY_DOWN.len)) else if (!strncmp (key, CURSES_KEY_DOWN.str, CURSES_KEY_DOWN.len))
@ -293,6 +303,8 @@ keys_int2str (int key)
{ {
case TAB: case TAB:
return "TAB"; return "TAB";
case SPACE:
return "SPC";
case ESCAPE: case ESCAPE:
return "ESC"; return "ESC";
case KEY_UP: case KEY_UP:
@ -348,7 +360,7 @@ keys_action_allkeys (keys_e action)
{ {
static char keystr[BUFSIZ]; static char keystr[BUFSIZ];
struct key_str_s *i; struct key_str_s *i;
const char *SPACE = " "; const char *CHAR_SPACE = " ";
if (keys[action] == NULL) if (keys[action] == NULL)
return NULL; return NULL;
@ -357,7 +369,7 @@ keys_action_allkeys (keys_e action)
{ {
const int MAXLEN = sizeof (keystr) - 1 - strlen (keystr); const int MAXLEN = sizeof (keystr) - 1 - strlen (keystr);
strncat (keystr, i->str, MAXLEN - 1); strncat (keystr, i->str, MAXLEN - 1);
strncat (keystr, SPACE, 1); strncat (keystr, CHAR_SPACE, 1);
} }
return keystr; return keystr;
@ -442,8 +454,10 @@ keys_popup_info (keys_e key)
char *info[NBKEYS]; char *info[NBKEYS];
WINDOW *infowin; WINDOW *infowin;
info[KEY_GENERIC_ESCAPE] = info[KEY_GENERIC_CANCEL] =
_("Cancel the ongoing action."); _("Cancel the ongoing action.");
info[KEY_GENERIC_SELECT] =
_("Select the highlighted item.");
info[KEY_GENERIC_CREDITS] = info[KEY_GENERIC_CREDITS] =
_("Print general information about calcurse's authors, license, etc."); _("Print general information about calcurse's authors, license, etc.");
info[KEY_GENERIC_HELP] = info[KEY_GENERIC_HELP] =
@ -545,3 +559,16 @@ keys_save_bindings (FILE *fd)
for (i = 0; i < NBKEYS; i++) for (i = 0; i < NBKEYS; i++)
fprintf (fd, "%s %s\n", keydef[i].label, keys_action_allkeys (i)); fprintf (fd, "%s %s\n", keydef[i].label, keys_action_allkeys (i));
} }
int
keys_check_missing_bindings (void)
{
int i;
for (i = 0; i < NBKEYS; i++)
{
if (keys[i] == 0)
return 1;
}
return 0;
}

View File

@ -1,4 +1,4 @@
/* $calcurse: keys.h,v 1.5 2008/11/25 20:48:58 culot Exp $ */ /* $calcurse: keys.h,v 1.6 2008/12/08 19:17:07 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -31,6 +31,7 @@
#define CTRL(x) ((x) & CTRLVAL) #define CTRL(x) ((x) & CTRLVAL)
#define ESCAPE 27 #define ESCAPE 27
#define TAB 9 #define TAB 9
#define SPACE 32
#define KEYS_KEYLEN 3 /* length of each keybinding */ #define KEYS_KEYLEN 3 /* length of each keybinding */
#define KEYS_LABELEN 8 /* length of command description */ #define KEYS_LABELEN 8 /* length of command description */
@ -38,7 +39,8 @@
typedef enum typedef enum
{ {
KEY_GENERIC_ESCAPE, KEY_GENERIC_CANCEL,
KEY_GENERIC_SELECT,
KEY_GENERIC_CREDITS, KEY_GENERIC_CREDITS,
KEY_GENERIC_HELP, KEY_GENERIC_HELP,
KEY_GENERIC_QUIT, KEY_GENERIC_QUIT,
@ -103,5 +105,6 @@ char *keys_action_allkeys (keys_e);
void keys_display_bindings_bar (WINDOW *, binding_t **, int, int); void keys_display_bindings_bar (WINDOW *, binding_t **, int, int);
void keys_popup_info (keys_e); void keys_popup_info (keys_e);
void keys_save_bindings (FILE *); void keys_save_bindings (FILE *);
int keys_check_missing_bindings (void);
#endif /* CALCURSE_KEYS_H */ #endif /* CALCURSE_KEYS_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: recur.c,v 1.40 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: recur.c,v 1.41 2008/12/08 19:17:07 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -694,7 +694,7 @@ recur_repeat_item (conf_t *conf)
} }
while ((ch != 'D') && (ch != 'W') && (ch != 'M') while ((ch != 'D') && (ch != 'W') && (ch != 'M')
&& (ch != 'Y') && (ch != KEY_GENERIC_ESCAPE)) && (ch != 'Y') && (ch != KEY_GENERIC_CANCEL))
{ {
status_mesg (mesg_type_1, mesg_type_2); status_mesg (mesg_type_1, mesg_type_2);
ch = wgetch (win[STA].p); ch = wgetch (win[STA].p);

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.c,v 1.25 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: todo.c,v 1.26 2008/12/08 19:17:07 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -274,7 +274,7 @@ todo_delete (conf_t *conf)
if (has_note == 0) if (has_note == 0)
answer = 't'; answer = 't';
while (answer != 't' && answer != 'n' && answer != KEY_GENERIC_ESCAPE) while (answer != 't' && answer != 'n' && answer != KEY_GENERIC_CANCEL)
{ {
status_mesg (erase_warning, erase_choice); status_mesg (erase_warning, erase_choice);
answer = wgetch (win[STA].p); answer = wgetch (win[STA].p);

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.c,v 1.55 2008/12/07 09:20:38 culot Exp $ */ /* $calcurse: utils.c,v 1.56 2008/12/08 19:17:07 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -226,9 +226,7 @@ showcursor (WINDOW *win, int y, int pos, char *str, int l, int offset)
nc = str + pos; nc = str + pos;
wmove (win, y, pos - offset); wmove (win, y, pos - offset);
#define SPACE 32
(pos >= l) ? waddch (win, SPACE | A_REVERSE) : waddch (win, *nc | A_REVERSE); (pos >= l) ? waddch (win, SPACE | A_REVERSE) : waddch (win, *nc | A_REVERSE);
#undef SPACE
} }
/* Print the string at the desired position. */ /* Print the string at the desired position. */
@ -368,7 +366,7 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
newpos++; newpos++;
break; break;
case KEY_GENERIC_ESCAPE: /* cancel editing */ case KEY_GENERIC_CANCEL: /* cancel editing */
return (GETSTRING_ESC); return (GETSTRING_ESC);
break; break;