sfeed_curses

[fork] sfeed (atom feed) reader
Log | Files | Refs | README | LICENSE

commit cab66e3975eaeaef2c8f675d5348fa5e2e6021e4
parent 1c33e9c30ac51469441b9810ef8a522948f2584e
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 23 Aug 2020 14:57:28 +0200

add minimal shim no_curses.h to allow an easy compile without curses/ncurses

This shim hardcodes the escape sequences typically used in xterm, st, etc.

Diffstat:
MMakefile | 3++-
MREADME | 2+-
Aminicurses.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Msfeed_curses.c | 21++++-----------------
4 files changed, 52 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile @@ -20,6 +20,7 @@ BIN = sfeed_curses SCRIPTS = sfeed_content sfeed_markread SRC = ${BIN:=.c} +HDR = minicurses.h MAN1 = ${BIN:=.1}\ ${SCRIPTS:=.1} @@ -44,7 +45,7 @@ ${OBJ}: dist: rm -rf "${NAME}-${VERSION}" mkdir -p "${NAME}-${VERSION}" - cp -f ${MAN1} ${DOC} ${SRC} ${SCRIPTS} Makefile \ + cp -f ${MAN1} ${DOC} ${HDR} ${SRC} ${SCRIPTS} Makefile \ "${NAME}-${VERSION}" # make tarball tar cf - "${NAME}-${VERSION}" | \ diff --git a/README b/README @@ -44,7 +44,7 @@ Dependencies - C compiler (C99). - libc (recommended: C99 and POSIX >= 200809). -- curses (typically ncurses). +- curses (typically ncurses), optional but recommended: but see minicurses.h. Optional dependencies diff --git a/minicurses.h b/minicurses.h @@ -0,0 +1,45 @@ +#include <sys/ioctl.h> + +const char *clr_eol = "\x1b[K"; +const char *clear_screen = "\x1b[H\x1b[2J"; +const char *cursor_address = "\x1b[%d;%dH"; +const char *cursor_normal = "\x1b[?25h"; /* DECTCEM (in)Visible cursor */ +const char *cursor_invisible = "\x1b[?25l"; /* DECTCEM (in)Visible cursor */ +const char *eat_newline_glitch = (void *)1; +const char *enter_ca_mode = "\x1b[?1049h"; /* smcup */ +const char *exit_ca_mode = "\x1b[?1049l"; /* rmcup */ +const char *save_cursor = "\x1b""7"; +const char *restore_cursor = "\x1b""8"; +const char *exit_attribute_mode = "\x1b[0m"; +const char *enter_bold_mode = "\x1b[1m"; +const char *enter_dim_mode = "\x1b[2m"; +const char *enter_reverse_mode = "\x1b[7m"; + +int lines = 79; +int columns = 24; + +int +setupterm(char *term, int fildes, int *errret) +{ + struct winsize winsz; + + if (ioctl(0, TIOCGWINSZ, &winsz) == -1) + return -1; /* ERR */ + columns = winsz.ws_col; + lines = winsz.ws_row; + + return 0; /* OK */ +} + +char * +tparm(const char *s, int p1, int p2, ...) +{ + static char buf[32]; + + if (s == cursor_address) { + snprintf(buf, sizeof(buf), s, p1 + 1, p2 + 1); + return buf; + } + + return (char *)s; +} diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -4,7 +4,6 @@ #include <sys/wait.h> #include <ctype.h> -#include <curses.h> #include <errno.h> #include <fcntl.h> #include <locale.h> @@ -13,12 +12,15 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <term.h> #include <termios.h> #include <time.h> #include <unistd.h> #include <wchar.h> +/* curses */ +#include <curses.h> +#include <term.h> + /* Allow to lazyload items when a file is specified? This saves memory but increases some latency when seeking items. It also causes issues if the feed is changed while having the UI open (and offsets are changed). */ @@ -397,7 +399,6 @@ updatetitle(void) void appmode(int on) { - /*ttywrite(on ? "\x1b[?1049h" : "\x1b[?1049l");*/ /* smcup, rmcup */ ttywrite(tparm(on ? enter_ca_mode : exit_ca_mode, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } @@ -410,22 +411,18 @@ mousemode(int on) void cursormode(int on) { - /*ttywrite(on ? "\x1b[?25h" : "\x1b[?25l");*/ /* DECTCEM (in)Visible cursor */ ttywrite(tparm(on ? cursor_normal : cursor_invisible, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } void cursormove(int x, int y) { - /*ttywritef("\x1b[%d;%dH", y + 1, x + 1);*/ ttywrite(tparm(cursor_address, y, x, 0, 0, 0, 0, 0, 0, 0)); } void cursorsave(void) { - /*ttywrite("\x1b""7");*/ /* save cursor */ - /* do not save the cursor if it won't be restored anyway */ if (cursor_invisible) ttywrite(tparm(save_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0)); @@ -434,8 +431,6 @@ cursorsave(void) void cursorrestore(void) { - /*ttywrite("\x1b""8");*/ /* restore cursor */ - /* if the cursor cannot be hidden then move to a consistent position */ if (cursor_invisible) ttywrite(tparm(restore_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0)); @@ -462,20 +457,17 @@ attrmode(int mode) default: return; } - ttywrite(tparm(p, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } void cleareol(void) { - /*ttywrite("\x1b[K");*/ ttywrite(tparm(clr_eol, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } void clearscreen(void) { - /*ttywrite("\x1b[H\x1b[2J");*/ ttywrite(tparm(clear_screen, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } @@ -520,11 +512,6 @@ win_update(struct win *w, int width, int height) void resizewin(void) { - /*struct winsize winsz; - if (ioctl(0, TIOCGWINSZ, &winsz) == -1) - die("ioctl"); - win_update(&win, winsz.ws_col, winsz.ws_row);*/ - setupterm(NULL, 1, NULL); /* termios globals are changed: `lines` and `columns` */ win_update(&win, columns, lines);