diff --git a/README.md b/README.md index d1cc41f..6ab0ba6 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,7 @@ Build: sudo apt build-dep bsdmainutils make ``` + +## Known issues + +Cursor can be moved out of the visible calendar. diff --git a/ncal.c b/ncal.c index cda6ccd..02cc185 100644 --- a/ncal.c +++ b/ncal.c @@ -170,6 +170,10 @@ static void printmonthr(int line, int col, int y, int m, int jd_flag, static void printmonthb(int line, int col, int y, int m, int jd_flag, int highlightdate); static void mkweekdays(struct weekdays * wds); +static void processkeyr(int key, int year, int m, int jd_flag, + int before, int after, int *highlightdate); +static void processkeyb(int key, int year, int m, int jd_flag, + int before, int after, int *highlightdate); static void monthranger(int year, int m, int jd_flag, int before, int after, int highlightdate); static void monthrangeb(int year, int m, int jd_flag, @@ -562,13 +566,20 @@ main(int argc, char *argv[]) int key; initscr(); noecho(); + curs_set(0); + keypad(stdscr, 1); do { clear(); - if (flag_backward) + if (flag_backward) { monthrangeb(y, m, flag_julian_day, before, after, highlightdate); - else + key = getch(); + processkeyb(key, y, m, flag_julian_day, before, after, &highlightdate); + } else { monthranger(y, m, flag_julian_day, before, after, highlightdate); - key = getch(); + key = getch(); + mvprintw(30, 60, "%d %d", key, highlightdate); + processkeyr(key, y, m, flag_julian_day, before, after, &highlightdate); + } } while (key != 'q'); endwin(); } @@ -1068,6 +1079,97 @@ printmonthb(int line, int col, int y, int m, int jd_flag, int highlightdate) weekstart++; } +static void +processkeyb(int key, int y, int m, int jd_flag, int before, int after, int *highlightdate) +{ + struct weekdays wds; + char s[MAX_WIDTH], t[MAX_WIDTH]; + wchar_t ws[MAX_WIDTH], ws1[MAX_WIDTH]; + const char *wdss; + int i, j; + int mpl; + int mw; + int m1, m2; + int printyearheader; + int prevyear = -1; + + mpl = jd_flag ? 2 : 3; + mw = jd_flag ? MONTH_WIDTH_B_J : (flag_weeks ? MONTH_WIDTH_B_WW : MONTH_WIDTH_B_NW ); + wdss = (mpl == 2) ? " " : ""; + + while (before > 0) { + DECREASEMONTH(m, y); + before--; + after++; + } + while (before < 0) { + INCREASEMONTH(m, y); + before++; + after--; + } + m1 = y * 12 + m - 1; + m2 = m1 + after; + + switch (key) { + case KEY_UP: + *highlightdate -= 7; + break; + case KEY_DOWN: + *highlightdate += 7; + break; + case KEY_LEFT: + (*highlightdate)--; + break; + case KEY_RIGHT: + (*highlightdate)++; + break; + } +} + +static void +processkeyr(int key, int y, int m, int jd_flag, int before, int after, int *highlightdate) +{ + struct weekdays wds; + char s[MAX_WIDTH], t[MAX_WIDTH]; + int i, j; + int mpl; + int mw; + int m1, m2; + int prevyear = -1; + int printyearheader; + + mpl = jd_flag ? 3 : 4; + mw = jd_flag ? MONTH_WIDTH_R_J : MONTH_WIDTH_R; + + while (before > 0) { + DECREASEMONTH(m, y); + before--; + after++; + } + while (before < 0) { + INCREASEMONTH(m, y); + before++; + after--; + } + m1 = y * 12 + m - 1; + m2 = m1 + after; + + switch (key) { + case KEY_UP: + (*highlightdate)--; + break; + case KEY_DOWN: + (*highlightdate)++; + break; + case KEY_LEFT: + *highlightdate -= 7; + break; + case KEY_RIGHT: + *highlightdate += 7; + break; + } +} + /* Put the local names of weekdays into the wds. */ static void mkweekdays(struct weekdays *wds)