commit 72b1826897c1396d069eb29216fbcb0414439255 from: Omar Polo date: Sat Jun 19 16:52:40 2021 UTC added olivetti-mode! commit - 51dc2fa43014052f22b32332d00829ada9c52b3f commit + 72b1826897c1396d069eb29216fbcb0414439255 blob - 3ba4d3e4d8e9345a1655de012dc96fc5d3e8e706 blob + c25d777832e3a2caecad4b8b79c6f5a9e2423251 --- ChangeLog +++ ChangeLog @@ -1,5 +1,7 @@ 2021-06-19 Omar Polo + * defaults.c (config_setvari): added olivetti-mode! + * fs.c (load_last_session): load about:help during the first startup * pages.c: added about:about, about:blank and about:help pages blob - 545355ce305ae31951d0f567dfa7458c9e3c1300 blob + 50d7b4cc73d328e088739e38f6ae9357a2279ed6 --- defaults.c +++ defaults.c @@ -23,6 +23,7 @@ char *new_tab_url = NULL; int fill_column = INT_MAX; +int olivetti_mode = 0; struct lineprefix line_prefixes[] = { [LINE_TEXT] = { "", "" }, @@ -112,6 +113,8 @@ config_setvari(const char *var, int val) if (!strcmp(var, "fill-column")) { if (val > 0) fill_column = val; + } else if (!strcmp(var, "olivetti-mode")) { + olivetti_mode = !!val; } else return 0; return 1; blob - 205c9652b75da5595fa21d5826b53e1fde9c3363 blob + d56d1135ac820f016d1e15baa26b4149dfc2dd73 --- telescope.h +++ telescope.h @@ -60,6 +60,7 @@ enum imsg_type { extern char *new_tab_url; extern int fill_column; +extern int olivetti_mode; struct lineprefix { const char *prfx1; blob - ca480f95f4709c7ea8e9873866bd689ffc199b00 blob + 7570f977147d4f3f4b165b68af02858df87ecea6 --- ui.c +++ ui.c @@ -106,6 +106,8 @@ static struct tab *new_tab(const char*); static void session_new_tab_cb(const char*); static void usage(void); +static int x_offset; + static struct { short meta; int key; uint32_t cp; } thiskey; static struct event resizeev; @@ -162,6 +164,15 @@ static struct { struct hist *hist_cur; size_t hist_off; } ministate; + +static inline void +update_x_offset() +{ + if (olivetti_mode && fill_column < body_cols) + x_offset = (body_cols - fill_column)/2; + else + x_offset = 0; +} static inline void global_set_key(const char *key, void (*fn)(struct buffer*)) @@ -314,6 +325,8 @@ restore_cursor(struct buffer *buffer) else buffer->curs_x = utf8_snwidth(vl->line, buffer->cpoff); + buffer->curs_x += x_offset; + if (vl != NULL) { prfx = line_prefixes[vl->parent->type].prfx1; buffer->curs_x += utf8_swidth(prfx); @@ -1311,6 +1324,7 @@ handle_resize_nodelay(int s, short ev, void *d) } else mvwin(body, 1, 0); + update_x_offset(); wresize(body, body_lines, body_cols); wresize(tabline, 1, COLS); @@ -1327,6 +1341,7 @@ wrap_page(struct buffer *buffer, int width) struct line *l; const struct line *orig; struct vline *vl; + int pre_width; const char *prfx; orig = buffer->current_line == NULL @@ -1354,7 +1369,11 @@ wrap_page(struct buffer *buffer, int width) wrap_text(buffer, prfx, l, MIN(fill_column, width)); break; case LINE_PRE_CONTENT: - hardwrap_text(buffer, l, width); + if (olivetti_mode) + pre_width = MIN(fill_column, width); + else + pre_width = width; + hardwrap_text(buffer, l, pre_width); break; } @@ -1506,7 +1525,7 @@ redraw_window(WINDOW *win, int height, struct buffer * l = 0; vl = nth_line(buffer, buffer->line_off); for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) { - wmove(win, l, 0); + wmove(win, l, x_offset); print_vline(win, vl); l++; if (l == height) @@ -1643,6 +1662,8 @@ redraw_tab(struct tab *tab) redraw_help(); wnoutrefresh(help); } + + restore_cursor(&tab->buffer); redraw_tabline(); redraw_body(tab); @@ -1992,6 +2013,8 @@ ui_init(int argc, char * const *argv) body_lines = LINES-3; body_cols = COLS; + + update_x_offset(); keypad(body, TRUE); scrollok(body, TRUE);