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>
* 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
@ -32,12 +32,13 @@
#include "i18n.h"
#include "vars.h"
#include "event.h"
#include "apoint.h"
#include "day.h"
#include "custom.h"
#include "notify.h"
#include "recur.h"
#include "keys.h"
#include "calendar.h"
#include "apoint.h"
apoint_llist_t *alist_p;
static int hilt = 0;
@ -150,7 +151,7 @@ apoint_add (void)
else if (check_time (item_time) != 1)
{
status_mesg (format_message_1, enter_str);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
else
sscanf (item_time, "%u:%u", &heures, &minutes);
@ -174,7 +175,7 @@ apoint_add (void)
else if (check_time (item_time) == 0)
{
status_mesg (format_message_2, enter_str);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
else
{
@ -241,7 +242,7 @@ apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
if (conf->confirm_delete)
{
status_mesg (del_app_str, choices);
answer = wgetch (win[STA].p);
answer = keys_getch (win[STA].p);
if ((answer == 'y') && (nb_items != 0))
go_for_deletion = true;
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
@ -133,6 +133,7 @@ main (int argc, char **argv)
}
vars_init (&conf);
keys_init ();
wins_init ();
wins_slctd_init ();
notify_init_bar ();
@ -162,14 +163,10 @@ main (int argc, char **argv)
/* User input */
for (;;)
{
int ch, key;
int key;
do_update = true;
ch = wgetch (win[STA].p);
key = keys_get_key (ch);
if (key == -1)
key = ch;
key = keys_getch (win[STA].p);
switch (key)
{
case ERR:
@ -229,7 +226,7 @@ main (int argc, char **argv)
case KEY_GENERIC_GOTO_TODAY:
erase_status_bar ();
calendar_set_current_date ();
if (ch == KEY_GENERIC_GOTO_TODAY)
if (key == KEY_GENERIC_GOTO_TODAY)
calendar_goto_today ();
else
calendar_change_day (conf.input_datefmt);
@ -237,8 +234,7 @@ main (int argc, char **argv)
day_changed = true;
break;
case KEY_APT_VIEW_ITEM:
case KEY_TODO_VIEW_ITEM:
case KEY_VIEW_ITEM:
if ((wins_slctd () == APP) && (apoint_hilt () != 0))
day_popup_item ();
else if ((wins_slctd () == TOD) && (todo_hilt () != 0))
@ -248,9 +244,9 @@ main (int argc, char **argv)
case KEY_GENERIC_CONFIG_MENU:
erase_status_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':
@ -297,8 +293,7 @@ main (int argc, char **argv)
todo_hilt_increase ();
break;
case KEY_APT_ADD_ITEM:
case KEY_TODO_ADD_ITEM:
case KEY_ADD_ITEM:
switch (wins_slctd ())
{
case APP:
@ -315,8 +310,7 @@ main (int argc, char **argv)
}
break;
case KEY_APT_EDIT_ITEM:
case KEY_TODO_EDIT_ITEM:
case KEY_EDIT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_item (&conf);
else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -324,8 +318,7 @@ main (int argc, char **argv)
do_storage = true;
break;
case KEY_APT_DEL_ITEM:
case KEY_TODO_DEL_ITEM:
case KEY_DEL_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -333,20 +326,20 @@ main (int argc, char **argv)
do_storage = true;
break;
case KEY_APT_REPEAT:
case KEY_REPEAT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
recur_repeat_item (&conf);
do_storage = true;
break;
case KEY_APT_FLAG_ITEM:
case KEY_FLAG_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_switch_notify ();
do_storage = true;
break;
case KEY_TODO_RAISE_PRIORITY:
case KEY_TODO_LOWER_PRIORITY:
case KEY_RAISE_PRIORITY:
case KEY_LOWER_PRIORITY:
if (wins_slctd () == TOD && todo_hilt () != 0)
{
todo_chg_priority (key);
@ -357,8 +350,7 @@ main (int argc, char **argv)
}
break;
case KEY_APT_EDIT_NOTE:
case KEY_TODO_EDIT_NOTE:
case KEY_EDIT_NOTE:
if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_note (conf.editor);
else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -366,8 +358,7 @@ main (int argc, char **argv)
do_storage = true;
break;
case KEY_APT_VIEW_NOTE:
case KEY_TODO_VIEW_NOTE:
case KEY_VIEW_NOTE:
if (wins_slctd () == APP && apoint_hilt () != 0)
day_view_note (conf.pager);
else if (wins_slctd () == TOD && todo_hilt () != 0)
@ -392,9 +383,9 @@ main (int argc, char **argv)
case KEY_GENERIC_EXPORT:
erase_status_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':
@ -415,7 +406,7 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_NEXT_DAY:
case KEY_CAL_NEXT_DAY:
case KEY_MOVE_RIGHT:
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY)
{
do_storage = true;
@ -425,7 +416,7 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_PREV_DAY:
case KEY_CAL_PREV_DAY:
case KEY_MOVE_LEFT:
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY)
{
do_storage = true;
@ -435,61 +426,49 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_PREV_WEEK:
case KEY_CAL_PREV_WEEK:
case KEY_MOVE_UP:
if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK)
{
do_storage = true;
day_changed = true;
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;
case KEY_GENERIC_NEXT_WEEK:
case KEY_CAL_NEXT_WEEK:
case KEY_MOVE_DOWN:
if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK)
{
do_storage = true;
day_changed = true;
calendar_move (DOWN);
}
break;
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) &&
else if ((wins_slctd () == APP) &&
(apoint_hilt () < inday.nb_events + inday.nb_apoints))
{
apoint_hilt_increase ();
apoint_scroll_pad_down (inday.nb_events, win[APP].h);
}
break;
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 ()))
else if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
{
todo_hilt_increase ();
if (todo_hilt_pos () == win[TOD].h - 4)
todo_first_increase ();
}
break;
break;
case KEY_CAL_START_OF_WEEK:
case KEY_START_OF_WEEK:
if (wins_slctd () == CAL)
{
do_storage = true;
@ -498,7 +477,7 @@ main (int argc, char **argv)
}
break;
case KEY_CAL_END_OF_WEEK:
case KEY_END_OF_WEEK:
if (wins_slctd () == CAL)
{
do_storage = true;
@ -514,8 +493,8 @@ main (int argc, char **argv)
if (conf.confirm_quit)
{
status_mesg (_(quit_message), choices);
ch = wgetch (win[STA].p);
if (ch == 'y')
key = wgetch (win[STA].p);
if (key == 'y')
exit_calcurse (EXIT_SUCCESS);
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
@ -35,10 +35,11 @@
#include "day.h"
#include "apoint.h"
#include "event.h"
#include "calendar.h"
#include "custom.h"
#include "vars.h"
#include "keys.h"
#include "utils.h"
#include "calendar.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
@ -387,7 +388,7 @@ calendar_change_day (int datefmt)
if (wrong_day)
{
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
@ -31,6 +31,7 @@
#include "i18n.h"
#include "io.h"
#include "utils.h"
#include "keys.h"
#include "apoint.h"
static struct attribute_s attr;
@ -225,7 +226,7 @@ custom_load_conf (conf_t *conf, int background)
status_mesg (mesg_line1, mesg_line2);
wnoutrefresh (win[STA].p);
doupdate ();
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
var = CUSTOM_CONF_NOVARIABLE;
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");
status_mesg (layout_mesg, choice_mesg);
wgetch (win[STA].p);
keys_getch (win[STA].p);
status_mesg (layout_up_mesg, layout_down_mesg);
wnoutrefresh (win[STA].p);
doupdate ();
while ((ch = wgetch (win[STA].p)) != 'q')
while ((ch = keys_getch (win[STA].p)) != 'q')
{
if (ch <= '8' && ch >= '1')
{
@ -581,7 +582,7 @@ custom_color_config (void)
display_color_config (&conf_win, &mark_fore, &mark_back, cursor,
need_reset, theme_changed);
while ((ch = wgetch (win[STA].p)) != 'q')
while ((ch = keys_getch (win[STA].p)) != 'q')
{
need_reset = 0;
theme_changed = 0;
@ -809,7 +810,7 @@ custom_general_config (conf_t *conf)
cwin.total_lines = print_general_options (cwin.pad.p, conf);
wins_scrollwin_display (&cwin);
while ((ch = wgetch (win[STA].p)) != 'q')
while ((ch = keys_getch (win[STA].p)) != 'q')
{
switch (ch)
{
@ -831,10 +832,10 @@ custom_general_config (conf_t *conf)
notify_update_bar ();
}
break;
case CTRL ('n'):
case KEY_MOVE_DOWN:
wins_scrollwin_down (&cwin);
break;
case CTRL ('p'):
case KEY_MOVE_UP:
wins_scrollwin_up (&cwin);
break;
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
@ -34,6 +34,7 @@
#include "apoint.h"
#include "event.h"
#include "custom.h"
#include "keys.h"
#include "day.h"
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)
{
status_mesg (fmt_msg, enter_str);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
else
return (timestr);
@ -558,7 +559,7 @@ update_start_time (long *start, long *dur)
else
{
status_mesg (msg_wrong_time, msg_enter);
wgetch (win[STA].p);
keys_getch (win[STA].p);
valid_date = 0;
}
}
@ -641,7 +642,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
if (newfreq == 0)
{
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)
{
status_mesg (msg_wrong_time, msg_enter);
wgetch (win[STA].p);
keys_getch (win[STA].p);
date_entered = 0;
}
else
@ -695,7 +696,7 @@ update_rept (struct rpt_s **rpt, const long start, conf_t *conf)
snprintf (outstr, BUFSIZ, msg_fmts,
DATEFMT_DESC (conf->input_datefmt));
status_mesg (msg_wrong_date, _(outstr));
wgetch (win[STA].p);
keys_getch (win[STA].p);
date_entered = 0;
}
}
@ -735,8 +736,8 @@ day_edit_item (conf_t *conf)
case 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] ");
while (ch != '1' && ch != '2' && ch != ESCAPE)
ch = wgetch (win[STA].p);
while (ch != '1' && ch != '2' && ch != KEY_GENERIC_ESCAPE)
ch = keys_getch (win[STA].p);
switch (ch)
{
case '1':
@ -758,8 +759,8 @@ day_edit_item (conf_t *conf)
status_mesg (_("Edit: (1)Start time, (2)End time, "
"(3)Description or (4)Repetition?"), "[1/2/3/4] ");
while (ch != STRT && ch != END && ch != DESC &&
ch != REPT && ch != ESCAPE)
ch = wgetch (win[STA].p);
ch != REPT && ch != KEY_GENERIC_ESCAPE)
ch = keys_getch (win[STA].p);
switch (ch)
{
case STRT:
@ -774,7 +775,7 @@ day_edit_item (conf_t *conf)
case REPT:
update_rept (&ra->rpt, ra->start, conf);
break;
case ESCAPE:
case KEY_GENERIC_ESCAPE:
return;
}
break;
@ -782,8 +783,8 @@ day_edit_item (conf_t *conf)
a = apoint_get (date, day_item_nb (date, item_num, APPT));
status_mesg (_("Edit: (1)Start time, (2)End time "
"or (3)Description?"), "[1/2/3] ");
while (ch != STRT && ch != END && ch != DESC && ch != ESCAPE)
ch = wgetch (win[STA].p);
while (ch != STRT && ch != END && ch != DESC && ch != KEY_GENERIC_ESCAPE)
ch = keys_getch (win[STA].p);
switch (ch)
{
case STRT:
@ -795,7 +796,7 @@ day_edit_item (conf_t *conf)
case DESC:
update_desc (&a->mesg);
break;
case ESCAPE:
case KEY_GENERIC_ESCAPE:
return;
}
break;
@ -832,7 +833,7 @@ day_erase_item (long date, int item_number, erase_flag_e flag)
while (ans != 'i' && ans != 'n')
{
status_mesg (note_warning, note_choice);
ans = wgetch (win[STA].p);
ans = keys_getch (win[STA].p);
}
if (ans == 'i')
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)
ch = 'a';
while ((ch != 'a') && (ch != 'o') && (ch != ESCAPE))
while ((ch != 'a') && (ch != 'o') && (ch != KEY_GENERIC_ESCAPE))
{
status_mesg (erase_warning, erase_choice);
ch = wgetch (win[STA].p);
ch = keys_getch (win[STA].p);
}
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
@ -30,10 +30,11 @@
#include <sys/types.h>
#include "i18n.h"
#include "help.h"
#include "custom.h"
#include "utils.h"
#include "keys.h"
#include "notify.h"
#include "help.h"
typedef enum
{
@ -161,100 +162,96 @@ wanted_page (int ch)
switch (ch)
{
case '?':
case KEY_GENERIC_HELP:
page = HELP_MAIN;
break;
case '!':
case KEY_FLAG_ITEM:
page = HELP_FLAG;
break;
case CTRL ('r'):
case CTRL ('a'):
case CTRL ('t'):
case CTRL ('h'):
case CTRL ('j'):
case CTRL ('k'):
case CTRL ('l'):
case CTRL ('g'):
case KEY_GENERIC_REDRAW:
case KEY_GENERIC_ADD_APPT:
case KEY_GENERIC_ADD_TODO:
case KEY_GENERIC_NEXT_DAY:
case KEY_GENERIC_PREV_DAY:
case KEY_GENERIC_NEXT_WEEK:
case KEY_GENERIC_PREV_WEEK:
case KEY_GENERIC_GOTO_TODAY:
page = HELP_GENERAL;
break;
case 's':
case KEY_GENERIC_SAVE:
page = HELP_SAVE;
break;
case 'i':
case KEY_GENERIC_IMPORT:
page = HELP_IMPORT;
break;
case 'x':
case KEY_GENERIC_EXPORT:
page = HELP_EXPORT;
break;
case '0':
case '$':
case 'h':
case 'l':
case 'j':
case 'k':
case KEY_UP:
case KEY_DOWN:
case KEY_RIGHT:
case KEY_LEFT:
case KEY_END_OF_WEEK:
case KEY_START_OF_WEEK:
case KEY_MOVE_UP:
case KEY_MOVE_DOWN:
case KEY_MOVE_RIGHT:
case KEY_MOVE_LEFT:
page = HELP_DISPLACEMENT;
break;
case 'a':
case KEY_ADD_ITEM:
page = HELP_ADD;
break;
case 'g':
case KEY_GENERIC_GOTO:
page = HELP_GOTO;
break;
case 'd':
case KEY_DEL_ITEM:
page = HELP_DELETE;
break;
case 'e':
case KEY_EDIT_ITEM:
page = HELP_EDIT;
break;
case 'n':
case KEY_EDIT_NOTE:
page = HELP_ENOTE;
break;
case '>':
case KEY_VIEW_NOTE:
page = HELP_VNOTE;
break;
case 'c':
case KEY_GENERIC_CONFIG_MENU:
page = HELP_CONFIG;
break;
case 'o':
case KEY_GENERIC_OTHER_CMD:
page = HELP_OTHER;
break;
case 'r':
case KEY_REPEAT_ITEM:
page = HELP_REPEAT;
break;
case 'v':
case KEY_VIEW_ITEM:
page = HELP_VIEW;
break;
case '+':
case '-':
case KEY_RAISE_PRIORITY:
case KEY_LOWER_PRIORITY:
page = HELP_PRIORITY;
break;
case 9:
case KEY_GENERIC_CHANGE_VIEW:
page = HELP_TAB;
break;
case '@':
case KEY_GENERIC_CREDITS:
page = HELP_CREDITS;
break;
@ -272,7 +269,7 @@ help_screen (void)
{
scrollwin_t hwin;
int need_resize;
int ch = '?';
int ch = KEY_GENERIC_HELP;
int page, oldpage;
help_page_t hscr[HELPSCREENS];
@ -604,7 +601,7 @@ help_screen (void)
need_resize = 0;
/* 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,
hwin.win.h - 2);
@ -618,11 +615,11 @@ help_screen (void)
need_resize = 1;
break;
case CTRL ('n'):
case KEY_GENERIC_SCROLL_DOWN:
wins_scrollwin_down (&hwin);
break;
case CTRL ('p'):
case KEY_GENERIC_SCROLL_UP:
wins_scrollwin_up (&hwin);
break;
@ -637,8 +634,7 @@ help_screen (void)
break;
}
wins_scrollwin_display (&hwin);
ch = wgetch (win[STA].p);
ch = tolower (ch);
ch = keys_getch (win[STA].p);
}
wins_scrollwin_delete (&hwin);
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>
@ -152,7 +152,7 @@ name##_HTABLE_INSERT(struct name *head, struct type *elm) \
while ((__bktp = *__bktpp)) \
{ \
if (!(cmp)(elm, __bktp)) \
return __bktp; \
return NULL; \
else \
{ \
__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
@ -47,8 +47,6 @@
#define ICALDATEFMT "%Y%m%d"
#define ICALDATETIMEFMT "%Y%m%dT%H%M%S"
#define STRING_BUILD(str) {str, sizeof (str) - 1}
typedef enum
{
PROGRESS_BAR_SAVE,
@ -56,11 +54,6 @@ typedef enum
PROGRESS_BAR_EXPORT
} progress_bar_t;
typedef struct {
const char *str;
const int len;
} string_t;
typedef enum {
ICAL_VEVENT,
ICAL_VTODO,
@ -216,7 +209,7 @@ get_export_stream (export_type_t type)
if (stream == NULL)
{
status_mesg (wrong_name, press_enter);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
}
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)
{
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)
{
status_mesg (mesg_line1, mesg_line2);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
for (;;)
{
@ -1190,22 +1183,6 @@ load_keys_ht_compare (struct ht_keybindings_s *data1,
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.
* A hash table is used to speed up loading process in avoiding string
@ -1214,7 +1191,7 @@ key_to_ascii (char *key)
void
io_load_keys (void)
{
struct ht_keybindings_s keys[NOKEYS];
struct ht_keybindings_s keys[NBKEYS];
FILE *keyfp;
char buf[BUFSIZ];
int i;
@ -1226,7 +1203,7 @@ io_load_keys (void)
HTABLE_GENERATE (ht_keybindings, ht_keybindings_s, load_keys_ht_getkey,
load_keys_ht_compare);
for (i = 0; i < NOKEYS; i++)
for (i = 0; i < NBKEYS; i++)
{
keys[i].key = (keys_e)i;
keys[i].label = keys_get_label ((keys_e)i);
@ -1261,15 +1238,20 @@ io_load_keys (void)
strncpy (tmpbuf, p, BUFSIZ);
if (sscanf (tmpbuf, "%s", key_ch) == AWAITED)
{
int ch;
char *unknown_key = _("Error reading key: %s");
int ch, used;
char *unknown_key = _("Error reading key: \"%s\"");
char *already_used =
_("\"%s\" assigned multiple times in keys file!");
ch = key_to_ascii (key_ch);
p += strlen (key_ch) + 1;
if (ch == 0)
ERROR_MSG (unknown_key);
if ((ch = keys_str2int (key_ch)) < 0)
ERROR_MSG (unknown_key, key_ch);
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
break;
@ -1323,23 +1305,29 @@ check_file (char *file, int *missing)
* |
* +--- notes/
* |___ conf
* |___ keys
* |___ apts
* |___ todo
*/
int
io_check_data_files (void)
{
int missing;
int missing, missing_keys;
missing = 0;
missing = missing_keys = 0;
errno = 0;
check_directory (path_dir, &missing);
check_directory (path_notes, &missing);
check_file (path_todo, &missing);
check_file (path_apts, &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;
}
@ -1355,12 +1343,12 @@ io_startup_screen (bool skip_dialogs, int no_data_file)
if (no_data_file != 0)
{
status_mesg (welcome_mesg, enter);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
else if (!skip_dialogs)
{
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)
{
status_mesg (success, enter);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
}
@ -1612,7 +1600,7 @@ ical_unformat_line (char *line)
static char *
ical_unfold_content (FILE *fd, char *line, unsigned *lineno)
{
const int CHAR_SPACE = 32, CHAR_TAB = 9;
const int CHAR_SPACE = 32;
char *content;
int c;
@ -1623,7 +1611,7 @@ ical_unfold_content (FILE *fd, char *line, unsigned *lineno)
for (;;)
{
c = getc (fd);
if (c == CHAR_SPACE || c == CHAR_TAB)
if (c == CHAR_SPACE || c == TAB)
{
char buf[BUFSIZ];
@ -2460,7 +2448,7 @@ get_import_stream (export_type_t type)
if (stream == NULL)
{
status_mesg (wrong_file, press_enter);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
}
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,
stats.events, stats.todos, stats.skipped);
status_mesg (read, stat);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
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);
do
{
ans = wgetch (win[STA].p);
ans = keys_getch (win[STA].p);
if (ans == 'y')
{
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
@ -24,138 +24,277 @@
*
*/
#include <string.h>
#include "i18n.h"
#include "utils.h"
#include "htable.h"
#include "keys.h"
#define HTKEYSIZE 512
#define MAXKEYVAL 256
struct keys_s {
int key;
keys_e action;
HTABLE_ENTRY (keys_s);
struct keydef_s {
char *label;
char *binding;
};
static HTABLE_HEAD (ht_keys, HTKEYSIZE, keys_s) ht_keys_action =
HTABLE_INITIALIZER (&ht_keys_action);
struct key_str_s {
char *str;
struct key_str_s *next;
};
static char *keylabel[NOKEYS] = {
"generic-help",
"generic-quit",
"generic-save",
"generic-change-view",
"generic-import",
"generic-export",
static struct key_str_s *keys[NBKEYS];
"generic-goto",
"generic-other-cmd",
"generic-config-menu",
"generic-redraw",
static keys_e actions[MAXKEYVAL];
"generic-add-appt",
"generic-add-todo",
"generic-next-ady",
"generic-prev-day",
"generic-next-week",
"generic-prev-week",
"generic-goto-today",
static struct keydef_s keydef[NBKEYS] = {
{"generic-escape", "ESC"},
{"generic-credits", "@"},
{"generic-help", "?"},
{"generic-quit", "q Q"},
{"generic-save", "s S C-s"},
{"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",
"cal-prev-day",
"cal-next-week",
"cal-prev-week",
"cal-start-of-week",
"cal-end-of-week",
"apt-add-item",
"apt-del-item",
"apt-edit-item",
"apt-view-item",
"apt-flag-item",
"apt-repeat",
"apt-move-up",
"apt-move-down",
"apt-edit-note",
"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"
{"move-right", "l L"},
{"move-left", "h H"},
{"move-down", "j J"},
{"move-up", "k K"},
{"start-of-week", "0"},
{"end-of-week", "$"},
{"add-item", "a A"},
{"del-item", "d D"},
{"edit-item", "e E"},
{"view-item", "v V"},
{"flag-item", "!"},
{"repeat", "r R"},
{"edit-note", "n N"},
{"view-note", ">"},
{"raise-priority", "+"},
{"lower-priority", "-"},
};
static void
ht_getkey (struct keys_s *data, char **key, int *len)
dump_intro (FILE *fd)
{
*key = (char *)&data->key;
*len = sizeof (int);
char *intro =
_("#\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
ht_compare (struct keys_s *data1, struct keys_s *data2)
void
keys_init (void)
{
if (data1->key == data2->key)
return 0;
else
return 1;
int i;
for (i = 0; i < MAXKEYVAL; i++)
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 *
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"));
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
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)
{
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));
binding->key = key;
binding->action = action;
HTABLE_INSERT (ht_keys, &ht_keys_action, binding);
static void
del_key_str (keys_e action, int key)
{
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
key_remove_binding (int key, keys_e action)
keys_remove_binding (int key, keys_e action)
{
struct keys_s find, *removed;
find.key = key;
find.action = action;
removed = HTABLE_REMOVE (ht_keys, &ht_keys_action, &find);
mem_free (removed);
if (key < 0 || key > MAXKEYVAL)
return;
else
{
actions[key] = KEY_UNDEF;
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
@ -27,8 +27,16 @@
#ifndef CALCURSE_KEYS_H
#define CALCURSE_KEYS_H
#define CTRLVAL 0x1F
#define TAB 9
#define CTRL(x) ((x) & CTRLVAL)
#define ESCAPE 27
typedef enum
{
KEY_GENERIC_ESCAPE,
KEY_GENERIC_CREDITS,
KEY_GENERIC_HELP,
KEY_GENERIC_QUIT,
KEY_GENERIC_SAVE,
@ -45,50 +53,41 @@ typedef enum
KEY_GENERIC_PREV_DAY,
KEY_GENERIC_NEXT_WEEK,
KEY_GENERIC_PREV_WEEK,
KEY_GENERIC_SCROLL_DOWN,
KEY_GENERIC_SCROLL_UP,
KEY_GENERIC_GOTO_TODAY,
KEY_CAL_NEXT_DAY,
KEY_CAL_PREV_DAY,
KEY_CAL_NEXT_WEEK,
KEY_CAL_PREV_WEEK,
KEY_CAL_START_OF_WEEK,
KEY_CAL_END_OF_WEEK,
KEY_MOVE_RIGHT,
KEY_MOVE_LEFT,
KEY_MOVE_DOWN,
KEY_MOVE_UP,
KEY_START_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,
KEY_APT_DEL_ITEM,
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
NBKEYS,
KEY_UNDEF
}
keys_e;
void keys_init (void);
void keys_dump_defaults (char *);
char *keys_get_label (keys_e);
int keys_get_key (int);
void keys_assign_binding (int, keys_e);
void key_remove_binding (int, keys_e);
keys_e keys_getch (WINDOW *win);
int keys_assign_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 */

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
@ -32,6 +32,7 @@
#include "i18n.h"
#include "utils.h"
#include "custom.h"
#include "keys.h"
#include "notify.h"
static struct notify_vars_s *notify = NULL;
@ -538,7 +539,7 @@ notify_config_bar (void)
status_mesg (number_str, "");
notify_print_options (conf_win.p, col);
*buf = '\0';
ch = wgetch (win[STA].p);
ch = keys_getch (win[STA].p);
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
@ -34,6 +34,7 @@
#include "utils.h"
#include "notify.h"
#include "day.h"
#include "keys.h"
#include "recur.h"
recur_apoint_llist_t *recur_alist_p;
@ -688,18 +689,18 @@ recur_repeat_item (conf_t *conf)
if (p->type != APPT && p->type != EVNT)
{
status_mesg (wrong_type_1, wrong_type_2);
ch = wgetch (win[STA].p);
ch = keys_getch (win[STA].p);
return;
}
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);
ch = wgetch (win[STA].p);
ch = keys_getch (win[STA].p);
ch = toupper (ch);
}
if (ch == ESCAPE)
if (ch == KEY_GENERIC_ESCAPE)
{
return;
}
@ -718,7 +719,7 @@ recur_repeat_item (conf_t *conf)
if (freq == 0)
{
status_mesg (mesg_wrong_freq, wrong_type_2);
wgetch (win[STA].p);
keys_getch (win[STA].p);
}
user_input[0] = '\0';
}
@ -752,7 +753,7 @@ recur_repeat_item (conf_t *conf)
if (until < p->start)
{
status_mesg (mesg_older, wrong_type_2);
wgetch (win[STA].p);
keys_getch (win[STA].p);
date_entered = 0;
}
else
@ -765,7 +766,7 @@ recur_repeat_item (conf_t *conf)
snprintf (outstr, BUFSIZ, mesg_wrong_2,
DATEFMT_DESC (conf->input_datefmt));
status_mesg (mesg_wrong_1, _(outstr));
wgetch (win[STA].p);
keys_getch (win[STA].p);
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
@ -146,7 +146,7 @@ todo_new_item (void)
while ((ch < '1') || (ch > '9'))
{
status_mesg (mesg_id, "");
ch = wgetch (win[STA].p);
ch = keys_getch (win[STA].p);
}
todo_add (todo_input, ch - '0', NULL);
todos++;
@ -249,7 +249,7 @@ todo_delete (conf_t *conf)
if (conf->confirm_delete)
{
status_mesg (del_todo_str, choices);
answer = wgetch (win[STA].p);
answer = keys_getch (win[STA].p);
if ((answer == 'y') && (todos > 0))
{
go_for_todo_del = true;
@ -274,10 +274,10 @@ todo_delete (conf_t *conf)
if (has_note == 0)
answer = 't';
while (answer != 't' && answer != 'n' && answer != ESCAPE)
while (answer != 't' && answer != 'n' && answer != KEY_GENERIC_ESCAPE)
{
status_mesg (erase_warning, erase_choice);
answer = wgetch (win[STA].p);
answer = keys_getch (win[STA].p);
}
switch (answer)
@ -348,11 +348,11 @@ todo_chg_priority (int action)
strncpy (backup_note, backup->note, NOTESIZ + 1);
else
backup_note[0] = '\0';
if (action == KEY_TODO_RAISE_PRIORITY)
if (action == KEY_RAISE_PRIORITY)
{
(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--;
}

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
@ -37,8 +37,21 @@
#include "i18n.h"
#include "wins.h"
#include "custom.h"
#include "keys.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;
/* General routine to exit calcurse properly. */
@ -79,7 +92,7 @@ ierror (const char *errmsg, ierror_sev_e sev)
exitmsg);
custom_remove_attr (errwin, ATTR_HIGHEST);
wrefresh (errwin);
wgetch (errwin);
keys_getch (errwin);
if (sev == IERROR_FATAL)
exit_calcurse (EXIT_FAILURE);
}
@ -114,7 +127,7 @@ warnbox (const char *msg)
mvwprintw (warnwin, 5, (WINCOL - strlen (displmsg)) / 2, "%s", displmsg);
custom_remove_attr (warnwin, ATTR_HIGHEST);
wrefresh (warnwin);
wgetch (warnwin);
keys_getch (warnwin);
delwin (warnwin);
doupdate ();
}
@ -216,7 +229,9 @@ showcursor (WINDOW *win, int y, int pos, char *str, int l, int offset)
nc = str + pos;
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. */
@ -356,7 +371,7 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
newpos++;
break;
case ESCAPE: /* cancel editing */
case KEY_GENERIC_ESCAPE: /* cancel editing */
return (GETSTRING_ESC);
break;
@ -427,64 +442,98 @@ is_all_digit (char *string)
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.
* 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
* utils.h, depending on which panel the added keybind is assigned to.
* table, and update the NB_CAL_CMDS, NB_APP_CMDS or NB_TOD_CMDS defines,
* depending on which panel the added keybind is assigned to.
*/
void
status_bar (void)
{
#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
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] =
{ 0, NB_CAL_CMDS, NB_CAL_CMDS + NB_APP_CMDS, TOTAL_CMDS };
binding_t help = { " ?", _("Help") };
binding_t quit = { " Q", _("Quit") };
binding_t save = { " S", _("Save") };
binding_t export = { " X", _("Export") };
binding_t import = { " I", _("Import") };
binding_t add = { " A", _("Add Item") };
binding_t del = { " D", _("Del Item") };
binding_t edit = { " E", _("Edit Itm") };
binding_t flag = { " !", _("Flag Itm") };
binding_t day = { "H/L", _("-+1 Day") };
binding_t week = { "K/J", _("-+1 Week") };
binding_t updn = { "K/J", _("Up/Down") };
binding_t rept = { " R", _("Repeat") };
binding_t prio = { "+/-", _("Priority") };
binding_t tab = { "Tab", _("Chg View") };
binding_t togo = { " G", _("Go to") };
binding_t conf = { " C", _("Config") };
binding_t view = { " V", _("View") };
binding_t draw = { " ^R", _("Redraw") };
binding_t appt = { " ^A", _("Add Appt") };
binding_t todo = { " ^T", _("Add Todo") };
binding_t enote = { " N", _("EditNote") };
binding_t vnote = { " >", _("ViewNote") };
binding_t eday = { "^HL", _("-+1 Day") };
binding_t ewek = { "^KJ", _("-+1 Week") };
binding_t othr = { " O", _("OtherCmd") };
binding_t today = {" ^G", _("Today") };
binding_t weekb = {" 0", _("beg Week") };
binding_t weeke = {" $", _("end Week") };
binding_t crdts = {_("Credits"), KEY_GENERIC_CREDITS};
binding_t help = {_("Help"), KEY_GENERIC_HELP};
binding_t quit = {_("Quit"), KEY_GENERIC_QUIT};
binding_t save = {_("Save"), KEY_GENERIC_SAVE};
binding_t chgvu = {_("Chg View"), KEY_GENERIC_CHANGE_VIEW};
binding_t import = {_("Import"), KEY_GENERIC_IMPORT};
binding_t export = {_("Export"), KEY_GENERIC_EXPORT};
binding_t togo = {_("Go to"), KEY_GENERIC_GOTO};
binding_t othr = {_("OtherCmd"), KEY_GENERIC_OTHER_CMD};
binding_t conf = {_("Config"), KEY_GENERIC_CONFIG_MENU};
binding_t draw = {_("Redraw"), KEY_GENERIC_REDRAW};
binding_t appt = {_("Add Appt"), KEY_GENERIC_ADD_APPT};
binding_t todo = {_("Add Todo"), KEY_GENERIC_ADD_TODO};
binding_t gnday = {_("+1 Day"), KEY_GENERIC_NEXT_DAY};
binding_t gpday = {_("-1 Day"), KEY_GENERIC_PREV_DAY};
binding_t gnweek = {_("+1 Week"), KEY_GENERIC_NEXT_WEEK};
binding_t gpweek = {_("-1 Week"), KEY_GENERIC_PREV_WEEK};
binding_t today = {_("Today"), KEY_GENERIC_GOTO_TODAY};
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 weekb = {_("beg Week"), KEY_START_OF_WEEK};
binding_t weeke = {_("end Week"), KEY_END_OF_WEEK};
binding_t add = {_("Add Item"), KEY_ADD_ITEM};
binding_t del = {_("Del Item"), KEY_DEL_ITEM};
binding_t edit = {_("Edit Itm"), KEY_EDIT_ITEM};
binding_t view = {_("View"), KEY_VIEW_ITEM};
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] = {
/* calendar keys */
&help, &quit, &save, &tab, &import, &export, &day, &week, &weekb, &weeke,
&togo, &othr, &conf, &draw, &appt, &todo, &eday, &ewek, &today, &othr,
&help, &quit, &save, &chgvu, &import, &export, &up, &down, &left, &right,
&togo, &othr, &weekb, &weeke, &conf, &draw, &appt, &todo, &gnday, &gpday,
&gnweek, &gpweek, &today, &othr, &crdts, &othr,
/* appointment keys */
&help, &quit, &save, &tab, &import, &export, &add, &del, &edit, &view,
&rept, &othr, &updn, &flag, &enote, &vnote, &appt, &todo, &eday, &ewek,
&conf, &togo, &draw, &othr, &today, &othr,
&help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
&draw, &othr, &rept, &flag, &enote, &vnote, &up, &down, &gnday, &gpday,
&gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &crdts, &othr,
/* todo keys */
&help, &quit, &save, &tab, &import, &export, &add, &del, &edit, &view,
&prio, &othr, &updn, &conf, &enote, &vnote, &appt, &todo, &eday, &ewek,
&togo, &draw, &today, &othr
&help, &quit, &save, &chgvu, &import, &export, &add, &del, &edit, &view,
&draw, &othr, &rprio, &lprio, &enote, &vnote, &up, &down, &gnday, &gpday,
&gnweek, &gpweek, &togo, &othr, &today, &conf, &appt, &todo, &crdts, &othr
};
#define LABEL_LENGTH 8 /* length of command description */
/* Total length of a command. */
cmd_length = KEY_LENGTH + LABEL_LENGTH;
space_between_cmds = floor (col / CMDS_PER_LINE - cmd_length);
@ -495,12 +544,22 @@ status_bar (void)
which_pan = wins_slctd ();
start = pos[which_pan] + 2 * CMDS_PER_LINE * (status_page - 1);
end = MIN (start + 2 * CMDS_PER_LINE, pos[which_pan + 1]);
j = 0;
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);
mvwprintw (win[STA].p, 0, j * cmd_length, binding[i]->key);
mvwprintw (win[STA].p, 0, j * cmd_length, fmtkey);
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);
mvwprintw (win[STA].p, 0, j * cmd_length + KEY_LENGTH,
binding[i]->label);
@ -510,6 +569,8 @@ status_bar (void)
j++;
}
wnoutrefresh (win[STA].p);
#undef LABEL_LENGTH
#undef NB_PANELS
}
long
@ -759,7 +820,7 @@ item_in_popup (char *saved_a_start, char *saved_a_end, char *msg,
wmove (win[STA].p, 0, 0);
pnoutrefresh (pad, 0, 0, margin_top + 2, margin_left, padl, winw);
doupdate ();
wgetch (popup_win);
keys_getch (popup_win);
delwin (pad);
delwin (popup_win);
}
@ -1003,6 +1064,8 @@ str_toupper (char *s)
void
mem_free (void *ptr)
{
if (ptr)
free (ptr);
if (!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
@ -35,6 +35,8 @@
#define MAX(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 { \
char msg[BUFSIZ]; \
\
@ -84,27 +86,14 @@
((e) ? (void)0 : aerror(__FILE__, __LINE__, #e)); \
} 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_ESC 1 /* user pressed escape to cancel editing */
#define GETSTRING_RET 2 /* return was pressed without entering any text */
typedef struct
{ /* structure defining a keybinding */
char *key;
char *label;
}
binding_t;
typedef struct {
const char *str;
const int len;
} string_t;
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
@ -31,6 +31,7 @@
#include "calendar.h"
#include "custom.h"
#include "wins.h"
#include "keys.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
@ -43,8 +43,6 @@
#define KEYS_PATH DIR_NAME KEYS_PATH_NAME
#define NOTES_DIR DIR_NAME NOTES_DIR_NAME
#define CTRL(x) ((x) & 0x1f)
#define ESCAPE 27
#define ATTR_FALSE 0
#define ATTR_TRUE 1
#define ATTR_LOWEST 2