More work on implementing user-definable keybindings

This commit is contained in:
Frederic Culot 2008-11-16 17:42:53 +00:00
parent e8f12c65ca
commit 9d4899110a
18 changed files with 586 additions and 418 deletions

View File

@ -1,3 +1,13 @@
2008-11-16 Frederic Culot <frederic@culot.org>
* src/keys.c (keys_dump_defaults, dump_intro, keys_str2int)
(keys_int2str, keys_init, add_key_str, del_key_str): new functions
* src/io.c (key_to_ascii): moved to src/keys.c
* src/utils.c (status_bar): updated to display user keybindings
* src/utils.c (format_key): new function
2008-11-09 Frederic Culot <frederic@culot.org> 2008-11-09 Frederic Culot <frederic@culot.org>
* src/io.c (io_load_keys, key_to_ascii): new function * src/io.c (io_load_keys, key_to_ascii): new function

View File

@ -1,4 +1,4 @@
/* $calcurse: apoint.c,v 1.23 2008/04/19 21:05:15 culot Exp $ */ /* $calcurse: apoint.c,v 1.24 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -32,12 +32,13 @@
#include "i18n.h" #include "i18n.h"
#include "vars.h" #include "vars.h"
#include "event.h" #include "event.h"
#include "apoint.h"
#include "day.h" #include "day.h"
#include "custom.h" #include "custom.h"
#include "notify.h" #include "notify.h"
#include "recur.h" #include "recur.h"
#include "keys.h"
#include "calendar.h" #include "calendar.h"
#include "apoint.h"
apoint_llist_t *alist_p; apoint_llist_t *alist_p;
static int hilt = 0; static int hilt = 0;
@ -150,7 +151,7 @@ apoint_add (void)
else if (check_time (item_time) != 1) else if (check_time (item_time) != 1)
{ {
status_mesg (format_message_1, enter_str); status_mesg (format_message_1, enter_str);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
else else
sscanf (item_time, "%u:%u", &heures, &minutes); sscanf (item_time, "%u:%u", &heures, &minutes);
@ -174,7 +175,7 @@ apoint_add (void)
else if (check_time (item_time) == 0) else if (check_time (item_time) == 0)
{ {
status_mesg (format_message_2, enter_str); status_mesg (format_message_2, enter_str);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
else else
{ {
@ -241,7 +242,7 @@ apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
if (conf->confirm_delete) if (conf->confirm_delete)
{ {
status_mesg (del_app_str, choices); status_mesg (del_app_str, choices);
answer = wgetch (win[STA].p); answer = keys_getch (win[STA].p);
if ((answer == 'y') && (nb_items != 0)) if ((answer == 'y') && (nb_items != 0))
go_for_deletion = true; go_for_deletion = true;
else else

View File

@ -1,4 +1,4 @@
/* $calcurse: calcurse.c,v 1.69 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: calcurse.c,v 1.70 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -133,6 +133,7 @@ main (int argc, char **argv)
} }
vars_init (&conf); vars_init (&conf);
keys_init ();
wins_init (); wins_init ();
wins_slctd_init (); wins_slctd_init ();
notify_init_bar (); notify_init_bar ();
@ -162,14 +163,10 @@ main (int argc, char **argv)
/* User input */ /* User input */
for (;;) for (;;)
{ {
int ch, key; int key;
do_update = true; do_update = true;
ch = wgetch (win[STA].p); key = keys_getch (win[STA].p);
key = keys_get_key (ch);
if (key == -1)
key = ch;
switch (key) switch (key)
{ {
case ERR: case ERR:
@ -229,7 +226,7 @@ main (int argc, char **argv)
case KEY_GENERIC_GOTO_TODAY: case KEY_GENERIC_GOTO_TODAY:
erase_status_bar (); erase_status_bar ();
calendar_set_current_date (); calendar_set_current_date ();
if (ch == KEY_GENERIC_GOTO_TODAY) if (key == KEY_GENERIC_GOTO_TODAY)
calendar_goto_today (); calendar_goto_today ();
else else
calendar_change_day (conf.input_datefmt); calendar_change_day (conf.input_datefmt);
@ -237,8 +234,7 @@ main (int argc, char **argv)
day_changed = true; day_changed = true;
break; break;
case KEY_APT_VIEW_ITEM: case KEY_VIEW_ITEM:
case KEY_TODO_VIEW_ITEM:
if ((wins_slctd () == APP) && (apoint_hilt () != 0)) if ((wins_slctd () == APP) && (apoint_hilt () != 0))
day_popup_item (); day_popup_item ();
else if ((wins_slctd () == TOD) && (todo_hilt () != 0)) else if ((wins_slctd () == TOD) && (todo_hilt () != 0))
@ -248,9 +244,9 @@ main (int argc, char **argv)
case KEY_GENERIC_CONFIG_MENU: case KEY_GENERIC_CONFIG_MENU:
erase_status_bar (); erase_status_bar ();
config_bar (); config_bar ();
while ((ch = wgetch (win[STA].p)) != 'q') while ((key = wgetch (win[STA].p)) != 'q')
{ {
switch (ch) switch (key)
{ {
case 'C': case 'C':
case 'c': case 'c':
@ -297,8 +293,7 @@ main (int argc, char **argv)
todo_hilt_increase (); todo_hilt_increase ();
break; break;
case KEY_APT_ADD_ITEM: case KEY_ADD_ITEM:
case KEY_TODO_ADD_ITEM:
switch (wins_slctd ()) switch (wins_slctd ())
{ {
case APP: case APP:
@ -315,8 +310,7 @@ main (int argc, char **argv)
} }
break; break;
case KEY_APT_EDIT_ITEM: case KEY_EDIT_ITEM:
case KEY_TODO_EDIT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_item (&conf); day_edit_item (&conf);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -324,8 +318,7 @@ main (int argc, char **argv)
do_storage = true; do_storage = true;
break; break;
case KEY_APT_DEL_ITEM: case KEY_DEL_ITEM:
case KEY_TODO_DEL_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints); apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -333,20 +326,20 @@ main (int argc, char **argv)
do_storage = true; do_storage = true;
break; break;
case KEY_APT_REPEAT: case KEY_REPEAT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
recur_repeat_item (&conf); recur_repeat_item (&conf);
do_storage = true; do_storage = true;
break; break;
case KEY_APT_FLAG_ITEM: case KEY_FLAG_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_switch_notify (); apoint_switch_notify ();
do_storage = true; do_storage = true;
break; break;
case KEY_TODO_RAISE_PRIORITY: case KEY_RAISE_PRIORITY:
case KEY_TODO_LOWER_PRIORITY: case KEY_LOWER_PRIORITY:
if (wins_slctd () == TOD && todo_hilt () != 0) if (wins_slctd () == TOD && todo_hilt () != 0)
{ {
todo_chg_priority (key); todo_chg_priority (key);
@ -357,8 +350,7 @@ main (int argc, char **argv)
} }
break; break;
case KEY_APT_EDIT_NOTE: case KEY_EDIT_NOTE:
case KEY_TODO_EDIT_NOTE:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_note (conf.editor); day_edit_note (conf.editor);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -366,8 +358,7 @@ main (int argc, char **argv)
do_storage = true; do_storage = true;
break; break;
case KEY_APT_VIEW_NOTE: case KEY_VIEW_NOTE:
case KEY_TODO_VIEW_NOTE:
if (wins_slctd () == APP && apoint_hilt () != 0) if (wins_slctd () == APP && apoint_hilt () != 0)
day_view_note (conf.pager); day_view_note (conf.pager);
else if (wins_slctd () == TOD && todo_hilt () != 0) else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -392,9 +383,9 @@ main (int argc, char **argv)
case KEY_GENERIC_EXPORT: case KEY_GENERIC_EXPORT:
erase_status_bar (); erase_status_bar ();
io_export_bar (); io_export_bar ();
while ((ch = wgetch (win[STA].p)) != 'q') while ((key = keys_getch (win[STA].p)) != 'q')
{ {
switch (ch) switch (key)
{ {
case 'I': case 'I':
case 'i': case 'i':
@ -415,7 +406,7 @@ main (int argc, char **argv)
break; break;
case KEY_GENERIC_NEXT_DAY: case KEY_GENERIC_NEXT_DAY:
case KEY_CAL_NEXT_DAY: case KEY_MOVE_RIGHT:
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY) if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY)
{ {
do_storage = true; do_storage = true;
@ -425,7 +416,7 @@ main (int argc, char **argv)
break; break;
case KEY_GENERIC_PREV_DAY: case KEY_GENERIC_PREV_DAY:
case KEY_CAL_PREV_DAY: case KEY_MOVE_LEFT:
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY) if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY)
{ {
do_storage = true; do_storage = true;
@ -435,61 +426,49 @@ main (int argc, char **argv)
break; break;
case KEY_GENERIC_PREV_WEEK: case KEY_GENERIC_PREV_WEEK:
case KEY_CAL_PREV_WEEK: case KEY_MOVE_UP:
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK) if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK)
{ {
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
calendar_move (UP); calendar_move (UP);
} }
else if ((wins_slctd () == APP) && (apoint_hilt () > 1))
{
apoint_hilt_decrease ();
apoint_scroll_pad_up (inday.nb_events);
}
else if ((wins_slctd () == TOD) && (todo_hilt () > 1))
{
todo_hilt_decrease ();
if (todo_hilt_pos () < 0)
todo_first_decrease ();
}
break; break;
case KEY_GENERIC_NEXT_WEEK: case KEY_GENERIC_NEXT_WEEK:
case KEY_CAL_NEXT_WEEK: case KEY_MOVE_DOWN:
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK) if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK)
{ {
do_storage = true; do_storage = true;
day_changed = true; day_changed = true;
calendar_move (DOWN); calendar_move (DOWN);
} }
break; else if ((wins_slctd () == APP) &&
case KEY_APT_MOVE_UP:
if ((wins_slctd () == APP) && (apoint_hilt () > 1))
{
apoint_hilt_decrease ();
apoint_scroll_pad_up (inday.nb_events);
}
break;
case KEY_APT_MOVE_DOWN:
if ((wins_slctd () == APP) &&
(apoint_hilt () < inday.nb_events + inday.nb_apoints)) (apoint_hilt () < inday.nb_events + inday.nb_apoints))
{ {
apoint_hilt_increase (); apoint_hilt_increase ();
apoint_scroll_pad_down (inday.nb_events, win[APP].h); apoint_scroll_pad_down (inday.nb_events, win[APP].h);
} }
break; else if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
case KEY_TODO_MOVE_UP:
if ((wins_slctd () == TOD) && (todo_hilt () > 1))
{
todo_hilt_decrease ();
if (todo_hilt_pos () < 0)
todo_first_decrease ();
}
break;
case KEY_TODO_MOVE_DOWN:
if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
{ {
todo_hilt_increase (); todo_hilt_increase ();
if (todo_hilt_pos () == win[TOD].h - 4) if (todo_hilt_pos () == win[TOD].h - 4)
todo_first_increase (); todo_first_increase ();
} }
break; break;
case KEY_CAL_START_OF_WEEK: case KEY_START_OF_WEEK:
if (wins_slctd () == CAL) if (wins_slctd () == CAL)
{ {
do_storage = true; do_storage = true;
@ -498,7 +477,7 @@ main (int argc, char **argv)
} }
break; break;
case KEY_CAL_END_OF_WEEK: case KEY_END_OF_WEEK:
if (wins_slctd () == CAL) if (wins_slctd () == CAL)
{ {
do_storage = true; do_storage = true;
@ -514,8 +493,8 @@ main (int argc, char **argv)
if (conf.confirm_quit) if (conf.confirm_quit)
{ {
status_mesg (_(quit_message), choices); status_mesg (_(quit_message), choices);
ch = wgetch (win[STA].p); key = wgetch (win[STA].p);
if (ch == 'y') if (key == 'y')
exit_calcurse (EXIT_SUCCESS); exit_calcurse (EXIT_SUCCESS);
else else
{ {

View File

@ -1,4 +1,4 @@
/* $calcurse: calendar.c,v 1.17 2008/08/10 09:24:46 culot Exp $ */ /* $calcurse: calendar.c,v 1.18 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -35,10 +35,11 @@
#include "day.h" #include "day.h"
#include "apoint.h" #include "apoint.h"
#include "event.h" #include "event.h"
#include "calendar.h"
#include "custom.h" #include "custom.h"
#include "vars.h" #include "vars.h"
#include "keys.h"
#include "utils.h" #include "utils.h"
#include "calendar.h"
#ifndef M_PI #ifndef M_PI
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
@ -387,7 +388,7 @@ calendar_change_day (int datefmt)
if (wrong_day) if (wrong_day)
{ {
status_mesg (mesg_line1, mesg_line2); status_mesg (mesg_line1, mesg_line2);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
} }
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: custom.c,v 1.24 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: custom.c,v 1.25 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -31,6 +31,7 @@
#include "i18n.h" #include "i18n.h"
#include "io.h" #include "io.h"
#include "utils.h" #include "utils.h"
#include "keys.h"
#include "apoint.h" #include "apoint.h"
static struct attribute_s attr; static struct attribute_s attr;
@ -225,7 +226,7 @@ custom_load_conf (conf_t *conf, int background)
status_mesg (mesg_line1, mesg_line2); status_mesg (mesg_line1, mesg_line2);
wnoutrefresh (win[STA].p); wnoutrefresh (win[STA].p);
doupdate (); doupdate ();
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
var = CUSTOM_CONF_NOVARIABLE; var = CUSTOM_CONF_NOVARIABLE;
pthread_mutex_lock (&nbar->mutex); pthread_mutex_lock (&nbar->mutex);
@ -392,11 +393,11 @@ layout_config (void)
_(" [1]AT [2]AC [3]TA [4]CA [5]TA [6]TC [7]AT [8]CT"); _(" [1]AT [2]AC [3]TA [4]CA [5]TA [6]TC [7]AT [8]CT");
status_mesg (layout_mesg, choice_mesg); status_mesg (layout_mesg, choice_mesg);
wgetch (win[STA].p); keys_getch (win[STA].p);
status_mesg (layout_up_mesg, layout_down_mesg); status_mesg (layout_up_mesg, layout_down_mesg);
wnoutrefresh (win[STA].p); wnoutrefresh (win[STA].p);
doupdate (); doupdate ();
while ((ch = wgetch (win[STA].p)) != 'q') while ((ch = keys_getch (win[STA].p)) != 'q')
{ {
if (ch <= '8' && ch >= '1') if (ch <= '8' && ch >= '1')
{ {
@ -581,7 +582,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)) != 'q')
{ {
need_reset = 0; need_reset = 0;
theme_changed = 0; theme_changed = 0;
@ -809,7 +810,7 @@ custom_general_config (conf_t *conf)
cwin.total_lines = print_general_options (cwin.pad.p, conf); cwin.total_lines = print_general_options (cwin.pad.p, conf);
wins_scrollwin_display (&cwin); wins_scrollwin_display (&cwin);
while ((ch = wgetch (win[STA].p)) != 'q') while ((ch = keys_getch (win[STA].p)) != 'q')
{ {
switch (ch) switch (ch)
{ {
@ -831,10 +832,10 @@ custom_general_config (conf_t *conf)
notify_update_bar (); notify_update_bar ();
} }
break; break;
case CTRL ('n'): case KEY_MOVE_DOWN:
wins_scrollwin_down (&cwin); wins_scrollwin_down (&cwin);
break; break;
case CTRL ('p'): case KEY_MOVE_UP:
wins_scrollwin_up (&cwin); wins_scrollwin_up (&cwin);
break; break;
case '1': case '1':

View File

@ -1,4 +1,4 @@
/* $calcurse: day.c,v 1.37 2008/04/19 21:05:15 culot Exp $ */ /* $calcurse: day.c,v 1.38 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -34,6 +34,7 @@
#include "apoint.h" #include "apoint.h"
#include "event.h" #include "event.h"
#include "custom.h" #include "custom.h"
#include "keys.h"
#include "day.h" #include "day.h"
static struct day_item_s *day_items_ptr; static struct day_item_s *day_items_ptr;
@ -526,7 +527,7 @@ day_edit_time (long time)
if (check_time (timestr) != 1 || strlen (timestr) == 0) if (check_time (timestr) != 1 || strlen (timestr) == 0)
{ {
status_mesg (fmt_msg, enter_str); status_mesg (fmt_msg, enter_str);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
else else
return (timestr); return (timestr);
@ -558,7 +559,7 @@ update_start_time (long *start, long *dur)
else else
{ {
status_mesg (msg_wrong_time, msg_enter); status_mesg (msg_wrong_time, msg_enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
valid_date = 0; valid_date = 0;
} }
} }
@ -641,7 +642,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
if (newfreq == 0) if (newfreq == 0)
{ {
status_mesg (msg_wrong_freq, msg_enter); status_mesg (msg_wrong_freq, msg_enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
} }
} }
@ -684,7 +685,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
if (newuntil < start) if (newuntil < start)
{ {
status_mesg (msg_wrong_time, msg_enter); status_mesg (msg_wrong_time, msg_enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
date_entered = 0; date_entered = 0;
} }
else else
@ -695,7 +696,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
snprintf (outstr, BUFSIZ, msg_fmts, snprintf (outstr, BUFSIZ, msg_fmts,
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (msg_wrong_date, _(outstr)); status_mesg (msg_wrong_date, _(outstr));
wgetch (win[STA].p); keys_getch (win[STA].p);
date_entered = 0; date_entered = 0;
} }
} }
@ -735,8 +736,8 @@ 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 != ESCAPE) while (ch != '1' && ch != '2' && ch != KEY_GENERIC_ESCAPE)
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
switch (ch) switch (ch)
{ {
case '1': case '1':
@ -758,8 +759,8 @@ 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 != ESCAPE) ch != REPT && ch != KEY_GENERIC_ESCAPE)
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
switch (ch) switch (ch)
{ {
case STRT: case STRT:
@ -774,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 ESCAPE: case KEY_GENERIC_ESCAPE:
return; return;
} }
break; break;
@ -782,8 +783,8 @@ 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 != ESCAPE) while (ch != STRT && ch != END && ch != DESC && ch != KEY_GENERIC_ESCAPE)
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
switch (ch) switch (ch)
{ {
case STRT: case STRT:
@ -795,7 +796,7 @@ day_edit_item (conf_t *conf)
case DESC: case DESC:
update_desc (&a->mesg); update_desc (&a->mesg);
break; break;
case ESCAPE: case KEY_GENERIC_ESCAPE:
return; return;
} }
break; break;
@ -832,7 +833,7 @@ day_erase_item (long date, int item_number, erase_flag_e flag)
while (ans != 'i' && ans != 'n') while (ans != 'i' && ans != 'n')
{ {
status_mesg (note_warning, note_choice); status_mesg (note_warning, note_choice);
ans = wgetch (win[STA].p); ans = keys_getch (win[STA].p);
} }
if (ans == 'i') if (ans == 'i')
flag = ERASE_FORCE; flag = ERASE_FORCE;
@ -851,10 +852,10 @@ 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 != ESCAPE)) while ((ch != 'a') && (ch != 'o') && (ch != KEY_GENERIC_ESCAPE))
{ {
status_mesg (erase_warning, erase_choice); status_mesg (erase_warning, erase_choice);
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
} }
if (ch == 'a') if (ch == 'a')
{ {

View File

@ -1,4 +1,4 @@
/* $calcurse: help.c,v 1.29 2008/09/21 08:06:43 culot Exp $ */ /* $calcurse: help.c,v 1.30 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -30,10 +30,11 @@
#include <sys/types.h> #include <sys/types.h>
#include "i18n.h" #include "i18n.h"
#include "help.h"
#include "custom.h" #include "custom.h"
#include "utils.h" #include "utils.h"
#include "keys.h"
#include "notify.h" #include "notify.h"
#include "help.h"
typedef enum typedef enum
{ {
@ -161,100 +162,96 @@ wanted_page (int ch)
switch (ch) switch (ch)
{ {
case '?': case KEY_GENERIC_HELP:
page = HELP_MAIN; page = HELP_MAIN;
break; break;
case '!': case KEY_FLAG_ITEM:
page = HELP_FLAG; page = HELP_FLAG;
break; break;
case CTRL ('r'): case KEY_GENERIC_REDRAW:
case CTRL ('a'): case KEY_GENERIC_ADD_APPT:
case CTRL ('t'): case KEY_GENERIC_ADD_TODO:
case CTRL ('h'): case KEY_GENERIC_NEXT_DAY:
case CTRL ('j'): case KEY_GENERIC_PREV_DAY:
case CTRL ('k'): case KEY_GENERIC_NEXT_WEEK:
case CTRL ('l'): case KEY_GENERIC_PREV_WEEK:
case CTRL ('g'): case KEY_GENERIC_GOTO_TODAY:
page = HELP_GENERAL; page = HELP_GENERAL;
break; break;
case 's': case KEY_GENERIC_SAVE:
page = HELP_SAVE; page = HELP_SAVE;
break; break;
case 'i': case KEY_GENERIC_IMPORT:
page = HELP_IMPORT; page = HELP_IMPORT;
break; break;
case 'x': case KEY_GENERIC_EXPORT:
page = HELP_EXPORT; page = HELP_EXPORT;
break; break;
case '0': case KEY_END_OF_WEEK:
case '$': case KEY_START_OF_WEEK:
case 'h': case KEY_MOVE_UP:
case 'l': case KEY_MOVE_DOWN:
case 'j': case KEY_MOVE_RIGHT:
case 'k': case KEY_MOVE_LEFT:
case KEY_UP:
case KEY_DOWN:
case KEY_RIGHT:
case KEY_LEFT:
page = HELP_DISPLACEMENT; page = HELP_DISPLACEMENT;
break; break;
case 'a': case KEY_ADD_ITEM:
page = HELP_ADD; page = HELP_ADD;
break; break;
case 'g': case KEY_GENERIC_GOTO:
page = HELP_GOTO; page = HELP_GOTO;
break; break;
case 'd': case KEY_DEL_ITEM:
page = HELP_DELETE; page = HELP_DELETE;
break; break;
case 'e': case KEY_EDIT_ITEM:
page = HELP_EDIT; page = HELP_EDIT;
break; break;
case 'n': case KEY_EDIT_NOTE:
page = HELP_ENOTE; page = HELP_ENOTE;
break; break;
case '>': case KEY_VIEW_NOTE:
page = HELP_VNOTE; page = HELP_VNOTE;
break; break;
case 'c': case KEY_GENERIC_CONFIG_MENU:
page = HELP_CONFIG; page = HELP_CONFIG;
break; break;
case 'o': case KEY_GENERIC_OTHER_CMD:
page = HELP_OTHER; page = HELP_OTHER;
break; break;
case 'r': case KEY_REPEAT_ITEM:
page = HELP_REPEAT; page = HELP_REPEAT;
break; break;
case 'v': case KEY_VIEW_ITEM:
page = HELP_VIEW; page = HELP_VIEW;
break; break;
case '+': case KEY_RAISE_PRIORITY:
case '-': case KEY_LOWER_PRIORITY:
page = HELP_PRIORITY; page = HELP_PRIORITY;
break; break;
case 9: case KEY_GENERIC_CHANGE_VIEW:
page = HELP_TAB; page = HELP_TAB;
break; break;
case '@': case KEY_GENERIC_CREDITS:
page = HELP_CREDITS; page = HELP_CREDITS;
break; break;
@ -272,7 +269,7 @@ help_screen (void)
{ {
scrollwin_t hwin; scrollwin_t hwin;
int need_resize; int need_resize;
int ch = '?'; int ch = KEY_GENERIC_HELP;
int page, oldpage; int page, oldpage;
help_page_t hscr[HELPSCREENS]; help_page_t hscr[HELPSCREENS];
@ -604,7 +601,7 @@ help_screen (void)
need_resize = 0; need_resize = 0;
/* Display the help screen related to user input. */ /* Display the help screen related to user input. */
while (ch != 'q') while (ch != KEY_GENERIC_QUIT)
{ {
erase_window_part (hwin.win.p, 1, hwin.pad.y, col - 2, erase_window_part (hwin.win.p, 1, hwin.pad.y, col - 2,
hwin.win.h - 2); hwin.win.h - 2);
@ -618,11 +615,11 @@ help_screen (void)
need_resize = 1; need_resize = 1;
break; break;
case CTRL ('n'): case KEY_GENERIC_SCROLL_DOWN:
wins_scrollwin_down (&hwin); wins_scrollwin_down (&hwin);
break; break;
case CTRL ('p'): case KEY_GENERIC_SCROLL_UP:
wins_scrollwin_up (&hwin); wins_scrollwin_up (&hwin);
break; break;
@ -637,8 +634,7 @@ help_screen (void)
break; break;
} }
wins_scrollwin_display (&hwin); wins_scrollwin_display (&hwin);
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
ch = tolower (ch);
} }
wins_scrollwin_delete (&hwin); wins_scrollwin_delete (&hwin);
if (need_resize) if (need_resize)

View File

@ -1,4 +1,4 @@
/* $calcurse: htable.h,v 1.2 2008/11/09 20:10:18 culot Exp $ */ /* $Id: htable.h,v 1.3 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Copyright (c) 2008 Frederic Culot <frederic@culot.org> * Copyright (c) 2008 Frederic Culot <frederic@culot.org>
@ -152,7 +152,7 @@ name##_HTABLE_INSERT(struct name *head, struct type *elm) \
while ((__bktp = *__bktpp)) \ while ((__bktp = *__bktpp)) \
{ \ { \
if (!(cmp)(elm, __bktp)) \ if (!(cmp)(elm, __bktp)) \
return __bktp; \ return NULL; \
else \ else \
{ \ { \
__pos++; \ __pos++; \

View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.41 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: io.c,v 1.42 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -47,8 +47,6 @@
#define ICALDATEFMT "%Y%m%d" #define ICALDATEFMT "%Y%m%d"
#define ICALDATETIMEFMT "%Y%m%dT%H%M%S" #define ICALDATETIMEFMT "%Y%m%dT%H%M%S"
#define STRING_BUILD(str) {str, sizeof (str) - 1}
typedef enum typedef enum
{ {
PROGRESS_BAR_SAVE, PROGRESS_BAR_SAVE,
@ -56,11 +54,6 @@ typedef enum
PROGRESS_BAR_EXPORT PROGRESS_BAR_EXPORT
} progress_bar_t; } progress_bar_t;
typedef struct {
const char *str;
const int len;
} string_t;
typedef enum { typedef enum {
ICAL_VEVENT, ICAL_VEVENT,
ICAL_VTODO, ICAL_VTODO,
@ -216,7 +209,7 @@ get_export_stream (export_type_t type)
if (stream == NULL) if (stream == NULL)
{ {
status_mesg (wrong_name, press_enter); status_mesg (wrong_name, press_enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
} }
free (stream_name); free (stream_name);
@ -913,7 +906,7 @@ io_save_cal (io_mode_t mode, conf_t *conf)
if (mode == IO_MODE_INTERACTIVE && !conf->skip_system_dialogs) if (mode == IO_MODE_INTERACTIVE && !conf->skip_system_dialogs)
{ {
status_mesg (save_success, enter); status_mesg (save_success, enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
} }
@ -1127,7 +1120,7 @@ io_load_todo (void)
if (data_file == NULL) if (data_file == NULL)
{ {
status_mesg (mesg_line1, mesg_line2); status_mesg (mesg_line1, mesg_line2);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
for (;;) for (;;)
{ {
@ -1190,22 +1183,6 @@ load_keys_ht_compare (struct ht_keybindings_s *data1,
return 1; return 1;
} }
static int
key_to_ascii (char *key)
{
const string_t CONTROL_KEY = STRING_BUILD ("CTRL-");
if (strlen (key) == 1)
return (int)key[0];
else
{
if (!strncmp (key, CONTROL_KEY.str, CONTROL_KEY.len))
return CTRL ((int)key[CONTROL_KEY.len]);
else
return 0;
}
}
/* /*
* Load user-definable keys from file. * Load user-definable keys from file.
* A hash table is used to speed up loading process in avoiding string * A hash table is used to speed up loading process in avoiding string
@ -1214,7 +1191,7 @@ key_to_ascii (char *key)
void void
io_load_keys (void) io_load_keys (void)
{ {
struct ht_keybindings_s keys[NOKEYS]; struct ht_keybindings_s keys[NBKEYS];
FILE *keyfp; FILE *keyfp;
char buf[BUFSIZ]; char buf[BUFSIZ];
int i; int i;
@ -1226,7 +1203,7 @@ io_load_keys (void)
HTABLE_GENERATE (ht_keybindings, ht_keybindings_s, load_keys_ht_getkey, HTABLE_GENERATE (ht_keybindings, ht_keybindings_s, load_keys_ht_getkey,
load_keys_ht_compare); load_keys_ht_compare);
for (i = 0; i < NOKEYS; i++) for (i = 0; i < NBKEYS; i++)
{ {
keys[i].key = (keys_e)i; keys[i].key = (keys_e)i;
keys[i].label = keys_get_label ((keys_e)i); keys[i].label = keys_get_label ((keys_e)i);
@ -1261,15 +1238,20 @@ io_load_keys (void)
strncpy (tmpbuf, p, BUFSIZ); strncpy (tmpbuf, p, BUFSIZ);
if (sscanf (tmpbuf, "%s", key_ch) == AWAITED) if (sscanf (tmpbuf, "%s", key_ch) == AWAITED)
{ {
int ch; int ch, used;
char *unknown_key = _("Error reading key: %s"); char *unknown_key = _("Error reading key: \"%s\"");
char *already_used =
_("\"%s\" assigned multiple times in keys file!");
ch = key_to_ascii (key_ch); if ((ch = keys_str2int (key_ch)) < 0)
p += strlen (key_ch) + 1; ERROR_MSG (unknown_key, key_ch);
if (ch == 0)
ERROR_MSG (unknown_key);
else else
keys_assign_binding (ch, ht_elm->key); {
p += strlen (key_ch) + 1;
used = keys_assign_binding (ch, ht_elm->key);
if (used)
ERROR_MSG (already_used, key_ch);
}
} }
else else
break; break;
@ -1323,23 +1305,29 @@ check_file (char *file, int *missing)
* | * |
* +--- notes/ * +--- notes/
* |___ conf * |___ conf
* |___ keys
* |___ apts * |___ apts
* |___ todo * |___ todo
*/ */
int int
io_check_data_files (void) io_check_data_files (void)
{ {
int missing; int missing, missing_keys;
missing = 0; missing = missing_keys = 0;
errno = 0; errno = 0;
check_directory (path_dir, &missing); check_directory (path_dir, &missing);
check_directory (path_notes, &missing); check_directory (path_notes, &missing);
check_file (path_todo, &missing); check_file (path_todo, &missing);
check_file (path_apts, &missing); check_file (path_apts, &missing);
check_file (path_conf, &missing); check_file (path_conf, &missing);
check_file (path_keys, &missing); check_file (path_keys, &missing_keys);
if (missing_keys)
{
missing++;
keys_dump_defaults (path_keys);
}
return missing; return missing;
} }
@ -1355,12 +1343,12 @@ io_startup_screen (bool skip_dialogs, int no_data_file)
if (no_data_file != 0) if (no_data_file != 0)
{ {
status_mesg (welcome_mesg, enter); status_mesg (welcome_mesg, enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
else if (!skip_dialogs) else if (!skip_dialogs)
{ {
status_mesg (data_mesg, enter); status_mesg (data_mesg, enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
} }
@ -1420,7 +1408,7 @@ io_export_data (io_mode_t mode, export_type_t type, conf_t *conf)
if (!conf->skip_system_dialogs && mode == IO_MODE_INTERACTIVE) if (!conf->skip_system_dialogs && mode == IO_MODE_INTERACTIVE)
{ {
status_mesg (success, enter); status_mesg (success, enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
} }
@ -1612,7 +1600,7 @@ 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_TAB = 9; const int CHAR_SPACE = 32;
char *content; char *content;
int c; int c;
@ -1623,7 +1611,7 @@ ical_unfold_content (FILE *fd, char *line, unsigned *lineno)
for (;;) for (;;)
{ {
c = getc (fd); c = getc (fd);
if (c == CHAR_SPACE || c == CHAR_TAB) if (c == CHAR_SPACE || c == TAB)
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -2460,7 +2448,7 @@ get_import_stream (export_type_t type)
if (stream == NULL) if (stream == NULL)
{ {
status_mesg (wrong_file, press_enter); status_mesg (wrong_file, press_enter);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
} }
mem_free (stream_name); mem_free (stream_name);
@ -2556,7 +2544,7 @@ io_import_data (io_mode_t mode, import_type_t type, conf_t *conf,
snprintf (stat, BUFSIZ, lines_stats_interactive, stats.apoints, snprintf (stat, BUFSIZ, lines_stats_interactive, stats.apoints,
stats.events, stats.todos, stats.skipped); stats.events, stats.todos, stats.skipped);
status_mesg (read, stat); status_mesg (read, stat);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
else if (mode == IO_MODE_NONINTERACTIVE) else if (mode == IO_MODE_NONINTERACTIVE)
{ {
@ -2596,7 +2584,7 @@ io_import_data (io_mode_t mode, import_type_t type, conf_t *conf,
status_mesg (view_log, choices); status_mesg (view_log, choices);
do do
{ {
ans = wgetch (win[STA].p); ans = keys_getch (win[STA].p);
if (ans == 'y') if (ans == 'y')
{ {
wins_launch_external (flogname, conf->pager); wins_launch_external (flogname, conf->pager);

View File

@ -1,4 +1,4 @@
/* $calcurse: keys.c,v 1.2 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: keys.c,v 1.3 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -24,138 +24,277 @@
* *
*/ */
#include <string.h>
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "htable.h"
#include "keys.h" #include "keys.h"
#define HTKEYSIZE 512 #define MAXKEYVAL 256
struct keys_s { struct keydef_s {
int key; char *label;
keys_e action; char *binding;
HTABLE_ENTRY (keys_s);
}; };
static HTABLE_HEAD (ht_keys, HTKEYSIZE, keys_s) ht_keys_action = struct key_str_s {
HTABLE_INITIALIZER (&ht_keys_action); char *str;
struct key_str_s *next;
};
static char *keylabel[NOKEYS] = { static struct key_str_s *keys[NBKEYS];
"generic-help",
"generic-quit",
"generic-save",
"generic-change-view",
"generic-import",
"generic-export",
"generic-goto", static keys_e actions[MAXKEYVAL];
"generic-other-cmd",
"generic-config-menu",
"generic-redraw",
"generic-add-appt", static struct keydef_s keydef[NBKEYS] = {
"generic-add-todo", {"generic-escape", "ESC"},
"generic-next-ady", {"generic-credits", "@"},
"generic-prev-day", {"generic-help", "?"},
"generic-next-week", {"generic-quit", "q Q"},
"generic-prev-week", {"generic-save", "s S C-s"},
"generic-goto-today", {"generic-change-view", "TAB"},
{"generic-import", "i I"},
{"generic-export", "x X"},
{"generic-goto", "g G"},
{"generic-other-cmd", "o O"},
{"generic-config-menu", "c C"},
{"generic-redraw", "C-r"},
{"generic-add-appt", "C-a"},
{"generic-add-todo", "C-t"},
{"generic-next-day", "C-l"},
{"generic-prev-day", "C-h"},
{"generic-next-week", "C-j"},
{"generic-prev-week", "C-k"},
{"generic-scroll-down", "C-n"},
{"generic-scroll-up", "C-p"},
{"generic-goto-today", "C-g"},
"cal-next-day", {"move-right", "l L"},
"cal-prev-day", {"move-left", "h H"},
"cal-next-week", {"move-down", "j J"},
"cal-prev-week", {"move-up", "k K"},
"cal-start-of-week", {"start-of-week", "0"},
"cal-end-of-week", {"end-of-week", "$"},
{"add-item", "a A"},
"apt-add-item", {"del-item", "d D"},
"apt-del-item", {"edit-item", "e E"},
"apt-edit-item", {"view-item", "v V"},
"apt-view-item", {"flag-item", "!"},
"apt-flag-item", {"repeat", "r R"},
"apt-repeat", {"edit-note", "n N"},
"apt-move-up", {"view-note", ">"},
"apt-move-down", {"raise-priority", "+"},
"apt-edit-note", {"lower-priority", "-"},
"apt-view-note",
"todo-add-item",
"todo-del-item",
"todo-edit-item",
"todo-view-item",
"todo-raise-priority",
"todo-lower-priority",
"todo-move-up",
"todo-move-down",
"todo-edit-note",
"todo-view-bote",
"config-quit",
"config-general-menu",
"config-layout-menu",
"config-color-menu",
"config-notify-menu"
}; };
static void static void
ht_getkey (struct keys_s *data, char **key, int *len) dump_intro (FILE *fd)
{ {
*key = (char *)&data->key; char *intro =
*len = sizeof (int); _("#\n"
"# Calcurse keys configuration file\n#\n"
"# This file sets the keybindings used by Calcurse.\n"
"# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n"
"# To assign a keybinding to an action, this file must contain a line\n"
"# with the following syntax:\n#\n"
"# ACTION KEY1 KEY2 ... KEYn\n#\n"
"# Where ACTION is what will be performed when KEY1, KEY2, ..., or KEYn\n"
"# will be pressed.\n"
"#\n"
"# To define bindings which use the CONTROL key, prefix the key with "
"'C-'.\n"
"# The escape and horizontal Tab key can be specified using the 'ESC'\n"
"# and 'TAB' keyword, respectively.\n");
fprintf (fd, "%s\n", intro);
} }
static int void
ht_compare (struct keys_s *data1, struct keys_s *data2) keys_init (void)
{ {
if (data1->key == data2->key) int i;
return 0;
else for (i = 0; i < MAXKEYVAL; i++)
return 1; actions[i] = KEY_UNDEF;
bzero (keys, NBKEYS);
} }
HTABLE_GENERATE (ht_keys, keys_s, ht_getkey, ht_compare); void
keys_dump_defaults (char *file)
{
FILE *fd;
int i;
fd = fopen (file, "w");
EXIT_IF (fd == NULL, _("FATAL ERROR in keys_dump_defaults: "
"could not create default keys file."));
dump_intro (fd);
for (i = 0; i < NBKEYS; i++)
fprintf (fd, "%s %s\n", keydef[i].label, keydef[i].binding);
fclose (fd);
}
char * char *
keys_get_label (keys_e key) keys_get_label (keys_e key)
{ {
EXIT_IF (key < 0 || key > NOKEYS, EXIT_IF (key < 0 || key > NBKEYS,
_("FATAL ERROR in keys_get_label: key value out of bounds")); _("FATAL ERROR in keys_get_label: key value out of bounds"));
return keylabel[key]; return keydef[key].label;
}
static int
keys_get_action (int pressed)
{
if (pressed < 0 || pressed > MAXKEYVAL)
return -1;
else
return actions[pressed];
}
keys_e
keys_getch (WINDOW *win)
{
int ch;
ch = wgetch (win);
return keys_get_action (ch);
}
static void
add_key_str (keys_e action, int key)
{
struct key_str_s *new, **i;
if (action < 0 || action > NBKEYS)
return;
new = malloc (sizeof (struct key_str_s));
new->str = strdup (keys_int2str (key));
new->next = NULL;
i = &keys[action];
for (;;)
{
if (*i == NULL)
{
*i = new;
break;
}
else if ((*i)->next == NULL)
{
(*i)->next = new;
break;
}
i = &(*i)->next;
}
} }
int int
keys_get_key (int pressed)
{
struct keys_s *key, find;
find.key = pressed;
key = HTABLE_LOOKUP (ht_keys, &ht_keys_action, &find);
if (key)
return (int)key->action;
else
return -1;
}
void
keys_assign_binding (int key, keys_e action) keys_assign_binding (int key, keys_e action)
{ {
struct keys_s *binding; if (key < 0 || key > MAXKEYVAL || actions[key] != KEY_UNDEF)
return 1;
else
{
actions[key] = action;
add_key_str (action, key);
}
return 0;
}
binding = malloc (sizeof (struct keys_s)); static void
binding->key = key; del_key_str (keys_e action, int key)
binding->action = action; {
HTABLE_INSERT (ht_keys, &ht_keys_action, binding); struct key_str_s *old, **i;
char oldstr[BUFSIZ];
int oldstrlen;
if (action < 0 || action > NBKEYS)
return;
strncpy (oldstr, keys_int2str (key), BUFSIZ);
oldstrlen = strlen (oldstr);
for (i = &keys[action]; *i; i = &(*i)->next)
{
if (strlen ((*i)->str) == oldstrlen
&& !(strncmp ((*i)->str, oldstr, oldstrlen)))
{
old = (*i);
(*i) = old->next;
mem_free (old->str);
mem_free (old);
break;
}
}
} }
void void
key_remove_binding (int key, keys_e action) keys_remove_binding (int key, keys_e action)
{ {
struct keys_s find, *removed; if (key < 0 || key > MAXKEYVAL)
return;
find.key = key; else
find.action = action; {
removed = HTABLE_REMOVE (ht_keys, &ht_keys_action, &find); actions[key] = KEY_UNDEF;
mem_free (removed); del_key_str (action, key);
}
}
int
keys_str2int (char *key)
{
const string_t CONTROL_KEY = STRING_BUILD ("C-");
const string_t TAB_KEY = STRING_BUILD ("TAB");
const string_t ESCAPE_KEY = STRING_BUILD ("ESC");
if (!key)
return -1;
if (strlen (key) == 1)
return (int)key[0];
else
{
if (!strncmp (key, CONTROL_KEY.str, CONTROL_KEY.len))
return CTRL ((int)key[CONTROL_KEY.len]);
else if (!strncmp (key, TAB_KEY.str, TAB_KEY.len))
return TAB;
else if (!strncmp (key, ESCAPE_KEY.str, ESCAPE_KEY.len))
return ESCAPE;
else
return -1;
}
}
char *
keys_int2str (int key)
{
return keyname (key);
}
char *
keys_action_firstkey (keys_e action)
{
return (keys[action] != NULL) ? keys[action]->str : NULL;
}
char *
keys_action_allkeys (keys_e action)
{
static char keystr[BUFSIZ];
struct key_str_s *i;
const char *SPACE = " ";
if (keys[action] == NULL)
return NULL;
keystr[0] = '\0';
for (i = keys[action]; i; i = i->next)
{
const int MAXLEN = sizeof (keystr) - 1 - strlen (keystr);
strncat (keystr, i->str, MAXLEN - 1);
strncat (keystr, SPACE, 1);
}
return keystr;
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: keys.h,v 1.2 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: keys.h,v 1.3 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -27,8 +27,16 @@
#ifndef CALCURSE_KEYS_H #ifndef CALCURSE_KEYS_H
#define CALCURSE_KEYS_H #define CALCURSE_KEYS_H
#define CTRLVAL 0x1F
#define TAB 9
#define CTRL(x) ((x) & CTRLVAL)
#define ESCAPE 27
typedef enum typedef enum
{ {
KEY_GENERIC_ESCAPE,
KEY_GENERIC_CREDITS,
KEY_GENERIC_HELP, KEY_GENERIC_HELP,
KEY_GENERIC_QUIT, KEY_GENERIC_QUIT,
KEY_GENERIC_SAVE, KEY_GENERIC_SAVE,
@ -45,50 +53,41 @@ typedef enum
KEY_GENERIC_PREV_DAY, KEY_GENERIC_PREV_DAY,
KEY_GENERIC_NEXT_WEEK, KEY_GENERIC_NEXT_WEEK,
KEY_GENERIC_PREV_WEEK, KEY_GENERIC_PREV_WEEK,
KEY_GENERIC_SCROLL_DOWN,
KEY_GENERIC_SCROLL_UP,
KEY_GENERIC_GOTO_TODAY, KEY_GENERIC_GOTO_TODAY,
KEY_CAL_NEXT_DAY, KEY_MOVE_RIGHT,
KEY_CAL_PREV_DAY, KEY_MOVE_LEFT,
KEY_CAL_NEXT_WEEK, KEY_MOVE_DOWN,
KEY_CAL_PREV_WEEK, KEY_MOVE_UP,
KEY_CAL_START_OF_WEEK, KEY_START_OF_WEEK,
KEY_CAL_END_OF_WEEK, KEY_END_OF_WEEK,
KEY_ADD_ITEM,
KEY_DEL_ITEM,
KEY_EDIT_ITEM,
KEY_VIEW_ITEM,
KEY_FLAG_ITEM,
KEY_REPEAT_ITEM,
KEY_EDIT_NOTE,
KEY_VIEW_NOTE,
KEY_RAISE_PRIORITY,
KEY_LOWER_PRIORITY,
KEY_APT_ADD_ITEM, NBKEYS,
KEY_APT_DEL_ITEM, KEY_UNDEF
KEY_APT_EDIT_ITEM,
KEY_APT_VIEW_ITEM,
KEY_APT_FLAG_ITEM,
KEY_APT_REPEAT,
KEY_APT_MOVE_UP,
KEY_APT_MOVE_DOWN,
KEY_APT_EDIT_NOTE,
KEY_APT_VIEW_NOTE,
KEY_TODO_ADD_ITEM,
KEY_TODO_DEL_ITEM,
KEY_TODO_EDIT_ITEM,
KEY_TODO_VIEW_ITEM,
KEY_TODO_RAISE_PRIORITY,
KEY_TODO_LOWER_PRIORITY,
KEY_TODO_MOVE_UP,
KEY_TODO_MOVE_DOWN,
KEY_TODO_EDIT_NOTE,
KEY_TODO_VIEW_NOTE,
KEY_CONFIG_QUIT,
KEY_CONFIG_GENERAL_MENU,
KEY_CONFIG_LAYOUT_MENU,
KEY_CONFIG_COLOR_MENU,
KEY_CONFIG_NOTIFY_MENU,
NOKEYS
} }
keys_e; keys_e;
void keys_init (void);
void keys_dump_defaults (char *);
char *keys_get_label (keys_e); char *keys_get_label (keys_e);
int keys_get_key (int); keys_e keys_getch (WINDOW *win);
void keys_assign_binding (int, keys_e); int keys_assign_binding (int, keys_e);
void key_remove_binding (int, keys_e); void keys_remove_binding (int, keys_e);
int keys_str2int (char *);
char *keys_int2str (int);
char *keys_action_firstkey (keys_e);
char *keys_action_allkeys (keys_e);
#endif /* CALCURSE_KEYS_H */ #endif /* CALCURSE_KEYS_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: notify.c,v 1.27 2008/04/20 13:49:39 culot Exp $ */ /* $calcurse: notify.c,v 1.28 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -32,6 +32,7 @@
#include "i18n.h" #include "i18n.h"
#include "utils.h" #include "utils.h"
#include "custom.h" #include "custom.h"
#include "keys.h"
#include "notify.h" #include "notify.h"
static struct notify_vars_s *notify = NULL; static struct notify_vars_s *notify = NULL;
@ -538,7 +539,7 @@ notify_config_bar (void)
status_mesg (number_str, ""); status_mesg (number_str, "");
notify_print_options (conf_win.p, col); notify_print_options (conf_win.p, col);
*buf = '\0'; *buf = '\0';
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
switch (ch) switch (ch)
{ {

View File

@ -1,4 +1,4 @@
/* $calcurse: recur.c,v 1.38 2008/09/16 19:41:36 culot Exp $ */ /* $calcurse: recur.c,v 1.39 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -34,6 +34,7 @@
#include "utils.h" #include "utils.h"
#include "notify.h" #include "notify.h"
#include "day.h" #include "day.h"
#include "keys.h"
#include "recur.h" #include "recur.h"
recur_apoint_llist_t *recur_alist_p; recur_apoint_llist_t *recur_alist_p;
@ -688,18 +689,18 @@ recur_repeat_item (conf_t *conf)
if (p->type != APPT && p->type != EVNT) if (p->type != APPT && p->type != EVNT)
{ {
status_mesg (wrong_type_1, wrong_type_2); status_mesg (wrong_type_1, wrong_type_2);
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
return; return;
} }
while ((ch != 'D') && (ch != 'W') && (ch != 'M') while ((ch != 'D') && (ch != 'W') && (ch != 'M')
&& (ch != 'Y') && (ch != ESCAPE)) && (ch != 'Y') && (ch != KEY_GENERIC_ESCAPE))
{ {
status_mesg (mesg_type_1, mesg_type_2); status_mesg (mesg_type_1, mesg_type_2);
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
ch = toupper (ch); ch = toupper (ch);
} }
if (ch == ESCAPE) if (ch == KEY_GENERIC_ESCAPE)
{ {
return; return;
} }
@ -718,7 +719,7 @@ recur_repeat_item (conf_t *conf)
if (freq == 0) if (freq == 0)
{ {
status_mesg (mesg_wrong_freq, wrong_type_2); status_mesg (mesg_wrong_freq, wrong_type_2);
wgetch (win[STA].p); keys_getch (win[STA].p);
} }
user_input[0] = '\0'; user_input[0] = '\0';
} }
@ -752,7 +753,7 @@ recur_repeat_item (conf_t *conf)
if (until < p->start) if (until < p->start)
{ {
status_mesg (mesg_older, wrong_type_2); status_mesg (mesg_older, wrong_type_2);
wgetch (win[STA].p); keys_getch (win[STA].p);
date_entered = 0; date_entered = 0;
} }
else else
@ -765,7 +766,7 @@ recur_repeat_item (conf_t *conf)
snprintf (outstr, BUFSIZ, mesg_wrong_2, snprintf (outstr, BUFSIZ, mesg_wrong_2,
DATEFMT_DESC (conf->input_datefmt)); DATEFMT_DESC (conf->input_datefmt));
status_mesg (mesg_wrong_1, _(outstr)); status_mesg (mesg_wrong_1, _(outstr));
wgetch (win[STA].p); keys_getch (win[STA].p);
date_entered = 0; date_entered = 0;
} }
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: todo.c,v 1.23 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: todo.c,v 1.24 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -146,7 +146,7 @@ todo_new_item (void)
while ((ch < '1') || (ch > '9')) while ((ch < '1') || (ch > '9'))
{ {
status_mesg (mesg_id, ""); status_mesg (mesg_id, "");
ch = wgetch (win[STA].p); ch = keys_getch (win[STA].p);
} }
todo_add (todo_input, ch - '0', NULL); todo_add (todo_input, ch - '0', NULL);
todos++; todos++;
@ -249,7 +249,7 @@ todo_delete (conf_t *conf)
if (conf->confirm_delete) if (conf->confirm_delete)
{ {
status_mesg (del_todo_str, choices); status_mesg (del_todo_str, choices);
answer = wgetch (win[STA].p); answer = keys_getch (win[STA].p);
if ((answer == 'y') && (todos > 0)) if ((answer == 'y') && (todos > 0))
{ {
go_for_todo_del = true; go_for_todo_del = true;
@ -274,10 +274,10 @@ todo_delete (conf_t *conf)
if (has_note == 0) if (has_note == 0)
answer = 't'; answer = 't';
while (answer != 't' && answer != 'n' && answer != ESCAPE) while (answer != 't' && answer != 'n' && answer != KEY_GENERIC_ESCAPE)
{ {
status_mesg (erase_warning, erase_choice); status_mesg (erase_warning, erase_choice);
answer = wgetch (win[STA].p); answer = keys_getch (win[STA].p);
} }
switch (answer) switch (answer)
@ -348,11 +348,11 @@ todo_chg_priority (int action)
strncpy (backup_note, backup->note, NOTESIZ + 1); strncpy (backup_note, backup->note, NOTESIZ + 1);
else else
backup_note[0] = '\0'; backup_note[0] = '\0';
if (action == KEY_TODO_RAISE_PRIORITY) if (action == KEY_RAISE_PRIORITY)
{ {
(backup_id > 1) ? backup_id-- : do_chg--; (backup_id > 1) ? backup_id-- : do_chg--;
} }
else if (action == KEY_TODO_LOWER_PRIORITY) else if (action == KEY_LOWER_PRIORITY)
{ {
(backup_id < 9) ? backup_id++ : do_chg--; (backup_id < 9) ? backup_id++ : do_chg--;
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.c,v 1.52 2008/09/23 17:31:57 culot Exp $ */ /* $calcurse: utils.c,v 1.53 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -37,8 +37,21 @@
#include "i18n.h" #include "i18n.h"
#include "wins.h" #include "wins.h"
#include "custom.h" #include "custom.h"
#include "keys.h"
#include "utils.h" #include "utils.h"
#define NB_CAL_CMDS 26 /* number of commands while in cal view */
#define NB_APP_CMDS 30 /* same thing while in appointment view */
#define NB_TOD_CMDS 30 /* same thing while in todo view */
#define TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
#define CMDS_PER_LINE 6 /* max number of commands per line */
#define KEY_LENGTH 4 /* length of each keybinding + one space */
typedef struct {
char *label;
keys_e action;
} binding_t;
static unsigned status_page; static unsigned status_page;
/* General routine to exit calcurse properly. */ /* General routine to exit calcurse properly. */
@ -79,7 +92,7 @@ ierror (const char *errmsg, ierror_sev_e sev)
exitmsg); exitmsg);
custom_remove_attr (errwin, ATTR_HIGHEST); custom_remove_attr (errwin, ATTR_HIGHEST);
wrefresh (errwin); wrefresh (errwin);
wgetch (errwin); keys_getch (errwin);
if (sev == IERROR_FATAL) if (sev == IERROR_FATAL)
exit_calcurse (EXIT_FAILURE); exit_calcurse (EXIT_FAILURE);
} }
@ -114,7 +127,7 @@ warnbox (const char *msg)
mvwprintw (warnwin, 5, (WINCOL - strlen (displmsg)) / 2, "%s", displmsg); mvwprintw (warnwin, 5, (WINCOL - strlen (displmsg)) / 2, "%s", displmsg);
custom_remove_attr (warnwin, ATTR_HIGHEST); custom_remove_attr (warnwin, ATTR_HIGHEST);
wrefresh (warnwin); wrefresh (warnwin);
wgetch (warnwin); keys_getch (warnwin);
delwin (warnwin); delwin (warnwin);
doupdate (); doupdate ();
} }
@ -216,7 +229,9 @@ 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);
(pos >= l) ? waddch (win, SPC | A_REVERSE) : waddch (win, *nc | A_REVERSE); #define SPACE 32
(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. */
@ -356,7 +371,7 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
newpos++; newpos++;
break; break;
case ESCAPE: /* cancel editing */ case KEY_GENERIC_ESCAPE: /* cancel editing */
return (GETSTRING_ESC); return (GETSTRING_ESC);
break; break;
@ -427,64 +442,98 @@ is_all_digit (char *string)
return (all_digit); return (all_digit);
} }
/* Need this to display keys properly inside status bar. */
static char *
format_key (char *key)
{
static char fmtkey[KEY_LENGTH];
switch (strlen (key))
{
case 0:
snprintf (fmtkey, KEY_LENGTH, " ?");
case 1:
snprintf (fmtkey, KEY_LENGTH, " %s", key);
break;
case 2:
snprintf (fmtkey, KEY_LENGTH, " %s", key);
break;
case 3:
snprintf (fmtkey, KEY_LENGTH, "%s", key);
break;
default:
snprintf (fmtkey, KEY_LENGTH, "%c%c.", key[0], key[1]);
/* NOTREACHED */
}
return fmtkey;
}
/* /*
* Draws the status bar. * Draws the status bar.
* To add a keybinding, insert a new binding_t item, add it in the *binding * To add a keybinding, insert a new binding_t item, add it in the *binding
* table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines in * table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines,
* utils.h, depending on which panel the added keybind is assigned to. * depending on which panel the added keybind is assigned to.
*/ */
void void
status_bar (void) status_bar (void)
{ {
#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
window_e which_pan; window_e which_pan;
int cmd_length, space_between_cmds, start, end, i, j = 0; int cmd_length, space_between_cmds, start, end, i, j;
const int pos[NB_PANELS + 1] = const int pos[NB_PANELS + 1] =
{ 0, NB_CAL_CMDS, NB_CAL_CMDS + NB_APP_CMDS, TOTAL_CMDS }; { 0, NB_CAL_CMDS, NB_CAL_CMDS + NB_APP_CMDS, TOTAL_CMDS };
binding_t help = { " ?", _("Help") }; binding_t crdts = {_("Credits"), KEY_GENERIC_CREDITS};
binding_t quit = { " Q", _("Quit") }; binding_t help = {_("Help"), KEY_GENERIC_HELP};
binding_t save = { " S", _("Save") }; binding_t quit = {_("Quit"), KEY_GENERIC_QUIT};
binding_t export = { " X", _("Export") }; binding_t save = {_("Save"), KEY_GENERIC_SAVE};
binding_t import = { " I", _("Import") }; binding_t chgvu = {_("Chg View"), KEY_GENERIC_CHANGE_VIEW};
binding_t add = { " A", _("Add Item") }; binding_t import = {_("Import"), KEY_GENERIC_IMPORT};
binding_t del = { " D", _("Del Item") }; binding_t export = {_("Export"), KEY_GENERIC_EXPORT};
binding_t edit = { " E", _("Edit Itm") }; binding_t togo = {_("Go to"), KEY_GENERIC_GOTO};
binding_t flag = { " !", _("Flag Itm") }; binding_t othr = {_("OtherCmd"), KEY_GENERIC_OTHER_CMD};
binding_t day = { "H/L", _("-+1 Day") }; binding_t conf = {_("Config"), KEY_GENERIC_CONFIG_MENU};
binding_t week = { "K/J", _("-+1 Week") }; binding_t draw = {_("Redraw"), KEY_GENERIC_REDRAW};
binding_t updn = { "K/J", _("Up/Down") }; binding_t appt = {_("Add Appt"), KEY_GENERIC_ADD_APPT};
binding_t rept = { " R", _("Repeat") }; binding_t todo = {_("Add Todo"), KEY_GENERIC_ADD_TODO};
binding_t prio = { "+/-", _("Priority") }; binding_t gnday = {_("+1 Day"), KEY_GENERIC_NEXT_DAY};
binding_t tab = { "Tab", _("Chg View") }; binding_t gpday = {_("-1 Day"), KEY_GENERIC_PREV_DAY};
binding_t togo = { " G", _("Go to") }; binding_t gnweek = {_("+1 Week"), KEY_GENERIC_NEXT_WEEK};
binding_t conf = { " C", _("Config") }; binding_t gpweek = {_("-1 Week"), KEY_GENERIC_PREV_WEEK};
binding_t view = { " V", _("View") }; binding_t today = {_("Today"), KEY_GENERIC_GOTO_TODAY};
binding_t draw = { " ^R", _("Redraw") }; binding_t up = {_("Up"), KEY_MOVE_UP};
binding_t appt = { " ^A", _("Add Appt") }; binding_t down = {_("Down"), KEY_MOVE_DOWN};
binding_t todo = { " ^T", _("Add Todo") }; binding_t left = {_("Left"), KEY_MOVE_LEFT};
binding_t enote = { " N", _("EditNote") }; binding_t right = {_("Right"), KEY_MOVE_RIGHT};
binding_t vnote = { " >", _("ViewNote") }; binding_t weekb = {_("beg Week"), KEY_START_OF_WEEK};
binding_t eday = { "^HL", _("-+1 Day") }; binding_t weeke = {_("end Week"), KEY_END_OF_WEEK};
binding_t ewek = { "^KJ", _("-+1 Week") }; binding_t add = {_("Add Item"), KEY_ADD_ITEM};
binding_t othr = { " O", _("OtherCmd") }; binding_t del = {_("Del Item"), KEY_DEL_ITEM};
binding_t today = {" ^G", _("Today") }; binding_t edit = {_("Edit Itm"), KEY_EDIT_ITEM};
binding_t weekb = {" 0", _("beg Week") }; binding_t view = {_("View"), KEY_VIEW_ITEM};
binding_t weeke = {" $", _("end Week") }; binding_t flag = {_("Flag Itm"), KEY_FLAG_ITEM};
binding_t rept = {_("Repeat"), KEY_REPEAT_ITEM};
binding_t enote = {_("EditNote"), KEY_EDIT_NOTE};
binding_t vnote = {_("ViewNote"), KEY_VIEW_NOTE};
binding_t rprio = {_("Prio.+"), KEY_RAISE_PRIORITY};
binding_t lprio = {_("Prio.-"), KEY_LOWER_PRIORITY};
binding_t *binding[TOTAL_CMDS] = { binding_t *binding[TOTAL_CMDS] = {
/* calendar keys */ /* calendar keys */
&help, &quit, &save, &tab, &import, &export, &day, &week, &weekb, &weeke, &help, &quit, &save, &chgvu, &import, &export, &up, &down, &left, &right,
&togo, &othr, &conf, &draw, &appt, &todo, &eday, &ewek, &today, &othr, &togo, &othr, &weekb, &weeke, &conf, &draw, &appt, &todo, &gnday, &gpday,
&gnweek, &gpweek, &today, &othr, &crdts, &othr,
/* appointment keys */ /* appointment keys */
&help, &quit, &save, &tab, &import, &export, &add, &del, &edit, &view, &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
&rept, &othr, &updn, &flag, &enote, &vnote, &appt, &todo, &eday, &ewek, &draw, &othr, &rept, &flag, &enote, &vnote, &up, &down, &gnday, &gpday,
&conf, &togo, &draw, &othr, &today, &othr, &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &crdts, &othr,
/* todo keys */ /* todo keys */
&help, &quit, &save, &tab, &import, &export, &add, &del, &edit, &view, &help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
&prio, &othr, &updn, &conf, &enote, &vnote, &appt, &todo, &eday, &ewek, &draw, &othr, &rprio, &lprio, &enote, &vnote, &up, &down, &gnday, &gpday,
&togo, &draw, &today, &othr &gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &crdts, &othr
}; };
#define LABEL_LENGTH 8 /* length of command description */
/* Total length of a command. */ /* Total length of a command. */
cmd_length = KEY_LENGTH + LABEL_LENGTH; cmd_length = KEY_LENGTH + LABEL_LENGTH;
space_between_cmds = floor (col / CMDS_PER_LINE - cmd_length); space_between_cmds = floor (col / CMDS_PER_LINE - cmd_length);
@ -495,12 +544,22 @@ status_bar (void)
which_pan = wins_slctd (); which_pan = wins_slctd ();
start = pos[which_pan] + 2 * CMDS_PER_LINE * (status_page - 1); start = pos[which_pan] + 2 * CMDS_PER_LINE * (status_page - 1);
end = MIN (start + 2 * CMDS_PER_LINE, pos[which_pan + 1]); end = MIN (start + 2 * CMDS_PER_LINE, pos[which_pan + 1]);
j = 0;
for (i = start; i < end; i += 2) for (i = start; i < end; i += 2)
{ {
char key[KEY_LENGTH], *fmtkey;
strncpy (key, keys_action_firstkey (binding[i]->action), KEY_LENGTH);
fmtkey = format_key (key);
custom_apply_attr (win[STA].p, ATTR_HIGHEST); custom_apply_attr (win[STA].p, ATTR_HIGHEST);
mvwprintw (win[STA].p, 0, j * cmd_length, binding[i]->key); mvwprintw (win[STA].p, 0, j * cmd_length, fmtkey);
if (i + 1 != end) if (i + 1 != end)
mvwprintw (win[STA].p, 1, j * cmd_length, binding[i + 1]->key); {
strncpy (key, keys_action_firstkey (binding[i + 1]->action),
KEY_LENGTH);
fmtkey = format_key (key);
mvwprintw (win[STA].p, 1, j * cmd_length, fmtkey);
}
custom_remove_attr (win[STA].p, ATTR_HIGHEST); custom_remove_attr (win[STA].p, ATTR_HIGHEST);
mvwprintw (win[STA].p, 0, j * cmd_length + KEY_LENGTH, mvwprintw (win[STA].p, 0, j * cmd_length + KEY_LENGTH,
binding[i]->label); binding[i]->label);
@ -510,6 +569,8 @@ status_bar (void)
j++; j++;
} }
wnoutrefresh (win[STA].p); wnoutrefresh (win[STA].p);
#undef LABEL_LENGTH
#undef NB_PANELS
} }
long long
@ -759,7 +820,7 @@ item_in_popup (char *saved_a_start, char *saved_a_end, char *msg,
wmove (win[STA].p, 0, 0); wmove (win[STA].p, 0, 0);
pnoutrefresh (pad, 0, 0, margin_top + 2, margin_left, padl, winw); pnoutrefresh (pad, 0, 0, margin_top + 2, margin_left, padl, winw);
doupdate (); doupdate ();
wgetch (popup_win); keys_getch (popup_win);
delwin (pad); delwin (pad);
delwin (popup_win); delwin (popup_win);
} }
@ -1003,6 +1064,8 @@ str_toupper (char *s)
void void
mem_free (void *ptr) mem_free (void *ptr)
{ {
if (ptr) if (!ptr)
free (ptr); return;
free (ptr);
ptr = NULL;
} }

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.h,v 1.37 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: utils.h,v 1.38 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -35,6 +35,8 @@
#define MAX(x,y) ((x)>(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y))
#define STRING_BUILD(str) {str, sizeof (str) - 1}
#define ERROR_MSG(...) do { \ #define ERROR_MSG(...) do { \
char msg[BUFSIZ]; \ char msg[BUFSIZ]; \
\ \
@ -84,27 +86,14 @@
((e) ? (void)0 : aerror(__FILE__, __LINE__, #e)); \ ((e) ? (void)0 : aerror(__FILE__, __LINE__, #e)); \
} while (0) } while (0)
#define SPC 32 /* ASCII code for white space */
#define NB_CAL_CMDS 20 /* number of commands while in cal view */
#define NB_APP_CMDS 26 /* same thing while in appointment view */
#define NB_TOD_CMDS 24 /* same thing while in todo view */
#define TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
#define CMDS_PER_LINE 6 /* max number of commands per line */
#define KEY_LENGTH 4 /* length of each keybinding + one space */
#define LABEL_LENGTH 8 /* length of command description */
#define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */ #define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */
#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */ #define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
#define GETSTRING_RET 2 /* return was pressed without entering any text */ #define GETSTRING_RET 2 /* return was pressed without entering any text */
typedef struct typedef struct {
{ /* structure defining a keybinding */ const char *str;
char *key; const int len;
char *label; } string_t;
}
binding_t;
typedef enum typedef enum
{ {

View File

@ -1,4 +1,4 @@
/* $calcurse: vars.c,v 1.10 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: vars.c,v 1.11 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -31,6 +31,7 @@
#include "calendar.h" #include "calendar.h"
#include "custom.h" #include "custom.h"
#include "wins.h" #include "wins.h"
#include "keys.h"
#include "vars.h" #include "vars.h"
/* /*

View File

@ -1,4 +1,4 @@
/* $calcurse: vars.h,v 1.25 2008/11/09 20:10:18 culot Exp $ */ /* $calcurse: vars.h,v 1.26 2008/11/16 17:42:53 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -43,8 +43,6 @@
#define KEYS_PATH DIR_NAME KEYS_PATH_NAME #define KEYS_PATH DIR_NAME KEYS_PATH_NAME
#define NOTES_DIR DIR_NAME NOTES_DIR_NAME #define NOTES_DIR DIR_NAME NOTES_DIR_NAME
#define CTRL(x) ((x) & 0x1f)
#define ESCAPE 27
#define ATTR_FALSE 0 #define ATTR_FALSE 0
#define ATTR_TRUE 1 #define ATTR_TRUE 1
#define ATTR_LOWEST 2 #define ATTR_LOWEST 2