arrow keys move the highlighted date
This commit is contained in:
parent
ccbd5bf9e3
commit
52e009cf56
|
@ -6,3 +6,7 @@ Build:
|
||||||
sudo apt build-dep bsdmainutils
|
sudo apt build-dep bsdmainutils
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Known issues
|
||||||
|
|
||||||
|
Cursor can be moved out of the visible calendar.
|
||||||
|
|
108
ncal.c
108
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,
|
static void printmonthb(int line, int col, int y, int m, int jd_flag,
|
||||||
int highlightdate);
|
int highlightdate);
|
||||||
static void mkweekdays(struct weekdays * wds);
|
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,
|
static void monthranger(int year, int m, int jd_flag,
|
||||||
int before, int after, int highlightdate);
|
int before, int after, int highlightdate);
|
||||||
static void monthrangeb(int year, int m, int jd_flag,
|
static void monthrangeb(int year, int m, int jd_flag,
|
||||||
|
@ -562,13 +566,20 @@ main(int argc, char *argv[])
|
||||||
int key;
|
int key;
|
||||||
initscr();
|
initscr();
|
||||||
noecho();
|
noecho();
|
||||||
|
curs_set(0);
|
||||||
|
keypad(stdscr, 1);
|
||||||
do {
|
do {
|
||||||
clear();
|
clear();
|
||||||
if (flag_backward)
|
if (flag_backward) {
|
||||||
monthrangeb(y, m, flag_julian_day, before, after, highlightdate);
|
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);
|
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');
|
} while (key != 'q');
|
||||||
endwin();
|
endwin();
|
||||||
}
|
}
|
||||||
|
@ -1068,6 +1079,97 @@ printmonthb(int line, int col, int y, int m, int jd_flag, int highlightdate)
|
||||||
weekstart++;
|
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. */
|
/* Put the local names of weekdays into the wds. */
|
||||||
static void
|
static void
|
||||||
mkweekdays(struct weekdays *wds)
|
mkweekdays(struct weekdays *wds)
|
||||||
|
|
Loading…
Reference in New Issue