diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 03aea76dcb16567e8c026c7842b50942c645476d
parent 43934a84fa58d0706d47adfafa3767d24c4df5d7
Author: in0rdr <andreas.gruhler@uzh.ch>
Date:   Wed, 23 Nov 2016 15:50:40 +0800

Wrap text on terminal resize

Diffstat:
Mdiary.c | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/diary.c b/diary.c @@ -207,17 +207,19 @@ int main(int argc, char** argv) { int ch; struct tm new_date; + int prev_width = COLS - ASIDE_WIDTH - CAL_WIDTH; + int prev_height = LINES - 1; + // init the current pad possition at the very end, // such that the cursor is displayed top of screen int pad_pos = 9999999; - int width = COLS - ASIDE_WIDTH - CAL_WIDTH; wmove(cal, 0, 0); getyx(cal, cy, cx); bool ret = go_to(cal, aside, raw_time, &pad_pos); - WINDOW* prev = newwin(LINES - 1, width, 1, ASIDE_WIDTH + CAL_WIDTH); - prev = read_diary(diary_dir, prev, width); + WINDOW* prev = newwin(prev_height, prev_width, 1, ASIDE_WIDTH + CAL_WIDTH); + prev = read_diary(diary_dir, prev, prev_width); do { ch = wgetch(cal); @@ -287,7 +289,12 @@ int main(int argc, char** argv) { if (ret) { update_date(date_header); - prev = read_diary(diary_dir, prev, width); + + // adjust prev width if terminal was resized in the mean time + prev_width = COLS - ASIDE_WIDTH - CAL_WIDTH; + wresize(prev, prev_height, prev_width); + + prev = read_diary(diary_dir, prev, prev_width); } } while (ch != 'q');