import sfeed_curses

Import sfeed_curses into sfeed.
The files are based of the commit 8e151ce48b503ad0ff0e24cb1be3bc93d6fbd895
This commit is contained in:
Hiltjo Posthuma 2021-11-26 12:10:05 +01:00
parent 618a6561cd
commit 3cb7df56e0
12 changed files with 3250 additions and 0 deletions

176
README.curses Normal file
View File

@ -0,0 +1,176 @@
sfeed_curses
------------
sfeed_curses is a curses UI front-end for sfeed.
It shows the TAB-separated feed items in a graphical command-line UI. The
interface has a look inspired by the mutt mail client. It has a sidebar panel
for the feeds, a panel with a listing of the items and a small statusbar for
the selected item/URL. Some functions like searching and scrolling are
integrated in the interface itself.
Build and install
-----------------
$ make
# make install
Usage
-----
Like the format programs included in sfeed you can run it like this:
sfeed_curses ~/.sfeed/feeds/*
... or by reading from stdin:
sfeed_curses < ~/.sfeed/feeds/xkcd
By default sfeed_curses marks the items of the last day as new/bold. To manage
read/unread items in a different way a plain-text file with a list of the read
URLs can be used. To enable this behaviour the path to this file can be
specified by setting the environment variable $SFEED_URL_FILE to the URL file:
export SFEED_URL_FILE="$HOME/.sfeed/urls"
[ -f "$SFEED_URL_FILE" ] || touch "$SFEED_URL_FILE"
sfeed_curses ~/.sfeed/feeds/*
There is a shellscript "sfeed_markread" to process the read and unread items.
See the man page for more detailed information.
Dependencies
------------
- C compiler (C99).
- libc (recommended: C99 and POSIX >= 200809).
- curses (typically ncurses), optional but recommended: but see minicurses.h.
Optional dependencies
---------------------
- POSIX make(1) for Makefile.
- mandoc for documentation: https://mdocml.bsd.lv/
Run-time dependencies
---------------------
- A (POSIX) shell.
- A terminal (emulator) supporting UTF-8 and the used capabilities.
Optional run-time dependencies
------------------------------
- xclip for yanking the URL or enclosure. See $SFEED_YANKER to change it.
- xdg-open, used as a plumber by default. See $SFEED_PLUMBER to change it.
- awk, used by the sfeed_content and sfeed_markread script.
See the ENVIRONMENT VARIABLES section in the man page to change it.
- lynx, used by the sfeed_content script to convert HTML content.
See the ENVIRONMENT VARIABLES section in the man page to change it.
OS tested
---------
- Linux (compilers: clang, gcc, tcc, libc: glibc, musl).
- OpenBSD (clang, gcc).
- NetBSD
- FreeBSD
- DragonFlyBSD
- Illumos (OpenIndiana).
- Windows (cygwin gcc + mintty).
- HaikuOS
Known terminal issues
---------------------
Below lists some bugs or missing features in terminals that are found while
testing. Some of them might be fixed already upstream:
- cygwin + mintty: the xterm mouse-encoding of the mouse position is broken for
scrolling.
- HaikuOS terminal: the xterm mouse-encoding of the mouse button number of the
middle-button, right-button is incorrect / reversed.
- putty: the full reset attribute (ESC c, typically `rs1`) does not reset the
window title.
Color themes
------------
To change the default theme you can set SFEED_THEME using make or in the
Makefile or include the a header file in sfeed_curses.c. See also the themes/
directory.
Running custom commands inside the program
------------------------------------------
Running commands inside the program can be useful for example to sync items or
mark all items across all feeds as read. It can be comfortable to have a
keybind for this inside the program to perform a scripted action and then
reload the feeds by sending the signal SIGHUP.
In the input handling code you can then add a case:
case 'M':
forkexec((char *[]) { "markallread.sh", NULL }, 0);
break;
or
case 'S':
forkexec((char *[]) { "syncnews.sh", NULL }, 1);
break;
The specified script should be in $PATH or an absolute path.
Example of a `markallread.sh` shellscript to mark all URLs as read:
#!/bin/sh
# mark all items/URLs as read.
tmp=$(mktemp)
(cat ~/.sfeed/urls; cut -f 3 ~/.sfeed/feeds/*) | \
awk '!x[$0]++' > "$tmp" &&
mv "$tmp" ~/.sfeed/urls &&
pkill -SIGHUP sfeed_curses # reload feeds.
Example of a `syncnews.sh` shellscript to update the feeds and reload them:
#!/bin/sh
sfeed_update && pkill -SIGHUP sfeed_curses
Open an URL directly in the same terminal
-----------------------------------------
To open an URL directly in the same terminal using the text-mode lynx browser:
SFEED_PLUMBER=lynx SFEED_PLUMBER_INTERACTIVE=1 sfeed_curses ~/.sfeed/feeds/*
Yank to tmux buffer
-------------------
This changes the yank command to set the tmux buffer, instead of X11 xclip:
SFEED_YANKER="tmux set-buffer \`cat\`"
License
-------
ISC, see LICENSE file.
Author
------
Hiltjo Posthuma <hiltjo@codemadness.org>

38
minicurses.h Normal file
View File

@ -0,0 +1,38 @@
#include <sys/ioctl.h>
#undef OK
#define OK (0)
const char *clr_eol = "\x1b[K";
const char *clear_screen = "\x1b[H\x1b[2J";
const char *cursor_address = "\x1b[%ld;%ldH";
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
setupterm(char *term, int fildes, int *errret)
{
return OK;
}
char *
tparm(const char *s, long p1, long p2, ...)
{
static char buf[32];
if (s == cursor_address) {
snprintf(buf, sizeof(buf), s, p1 + 1, p2 + 1);
return buf;
}
return (char *)s;
}

53
sfeed_content Executable file
View File

@ -0,0 +1,53 @@
#!/bin/sh
# Content viewer for sfeed(5) lines.
# The locale is set to "C" for performance. The input is always UTF-8.
LC_ALL=C awk -F '\t' '
function unescape(s) {
# use the character "\x01" as a temporary replacement for "\".
gsub("\\\\\\\\", "\x01", s);
gsub("\\\\n", "\n", s);
gsub("\\\\t", "\t", s);
gsub("\x01", "\\", s); # restore "\x01" to "\".
return s;
}
BEGIN {
htmlconv = "lynx -stdin -dump " \
"-underline_links -image_links " \
"-display_charset=\"utf-8\" -assume_charset=\"utf-8\" ";
}
{
if (previtem)
print "\f";
previtem = 1;
print "Title: " $2;
if (length($7))
print "Author: " $7;
if (length($9)) {
categories = $9;
gsub("\\|", ", ", categories);
print "Category: " categories;
}
if (length($3))
print "Link: " $3;
if (length($8))
print "Enclosure: " $8;
if (!length($4))
next;
print "";
if ($5 == "html") {
# use the link of the item as the base URL for relative URLs in
# HTML content.
base = $3;
if (length(base)) {
gsub("\"", "%22", base); # encode quotes.
base = "<base href=\"" base "\"/>\n";
}
print base unescape($4) | htmlconv;
close(htmlconv);
} else {
print unescape($4);
}
}' "$@" | \
${PAGER:-less -R}

57
sfeed_content.1 Normal file
View File

@ -0,0 +1,57 @@
.Dd July 25, 2021
.Dt SFEED_CONTENT 1
.Os
.Sh NAME
.Nm sfeed_content
.Nd view RSS/Atom content
.Sh SYNOPSIS
.Nm
.Op Ar
.Sh DESCRIPTION
.Nm
formats feed data (TSV) from
.Xr sfeed 1
from stdin or for each
.Ar file
to stdout as plain-text content.
For HTML content it uses
.Xr lynx 1
to convert it to plain-text.
At the end it uses the pager to view the output.
The
.Nm
script can be used by
.Xr sfeed_curses 1
to view content.
.Sh ENVIRONMENT VARIABLES
.Bl -tag -width Ds
.It Ev PAGER
The pager used to view the content.
If it is not set it will use "less -R" by default.
.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
.Bd -literal
curl -s 'https://codemadness.org/atom_content.xml' | sfeed | sfeed_content
.Ed
.Pp
The output format looks like this:
.Bd -literal
Title: The title.
Author: The line with the author if it is set.
Category: The line with the categories if it is set.
Link: The line with the link if it is set.
Enclosure: The line with the enclosure if it is set.
The content converted to plain-text.
<form feed character> if there are multiple items.
.Ed
.Sh SEE ALSO
.Xr awk 1 ,
.Xr less 1 ,
.Xr lynx 1 ,
.Xr sfeed_curses 1
.Sh AUTHORS
.An Hiltjo Posthuma Aq Mt hiltjo@codemadness.org

320
sfeed_curses.1 Normal file
View File

@ -0,0 +1,320 @@
.Dd August 10, 2021
.Dt SFEED_CURSES 1
.Os
.Sh NAME
.Nm sfeed_curses
.Nd curses UI for viewing feed data
.Sh SYNOPSIS
.Nm
.Op Ar
.Sh DESCRIPTION
.Nm
formats feed data (TSV) from
.Xr sfeed 1
from stdin or for each
.Ar file
into a curses UI.
If one or more
.Ar file
arguments are specified then the basename of the
.Ar file
is used as the feed name in the output such as the feeds sidebar.
The
.Ar file
arguments are processed and shown in the specified argument order in the feeds
sidebar.
If no
.Ar file
arguments are specified then the data is read from stdin and the feed name is
"stdin" and no sidebar is visible by default in this case.
.Pp
Items with a timestamp from the last day compared to the system time at the
time of loading the feed are marked as new and bold.
There is also an alternative mode available to mark items as read by matching
it against a list of URLs from a plain-text file.
.Pp
.Nm
aligns the output.
Make sure the environment variable
.Ev LC_CTYPE
is set to a UTF-8 locale, so it can determine the proper column-width
per rune, using
.Xr mbtowc 3
and
.Xr wcwidth 3 .
.Sh KEYBINDS
.Bl -tag -width Ds
.It k, ARROW UP
Go one row up.
.It j, ARROW DOWN
Go one row down.
.It K
Go one row up and open the item.
.It J
Go one row down and open the item.
.It h, ARROW LEFT
Focus feeds pane.
.It l, ARROW RIGHT
Focus items pane.
.It TAB
Cycle focused pane (between feeds and items).
.It g
Go to the first row.
.It G
Go to the last row.
.It PAGE UP, CTRL-B
Scroll one page up.
.It PAGE DOWN, CTRL-F, SPACE
Scroll one page down.
.It /
Prompt for a new search and search forward (case-insensitive).
.It ?
Prompt for a new search and search backward (case-insensitive).
.It n
Search forward with the previously set search term.
.It N
Search backward with the previously set search term.
.It \&[
Go to the previous feed in the feeds pane and open it.
.It ]
Go to the next feed in the feeds pane and open it.
.It CTRL-L
Redraw screen.
.It R
Reload all feed files which were specified as arguments on startup.
.It m
Toggle mouse-mode.
It supports xterm X10 and extended SGR encoding.
.It s
Toggle between monocle layout and the previous non-monocle layout.
.It <
Use a fixed sidebar size for the current layout and decrease the fixed width or
height by 1 column.
.It >
Use a fixed sidebar size for the current layout and increase the fixed width or
height by 1 column.
.It =
Reset the sidebar size to automaticly adjust for the current layout.
With the vertical layout the width is the longest feed name with the item
counts right-aligned.
With the horizontal layout the height is half of the window height (minus the
statusbar) or otherwise the total amount of visible feeds, whichever fits the
best.
.It t
Toggle showing only feeds with new items in the sidebar.
.It a, e, @
Plumb URL of the enclosure.
The URL is passed as a parameter to the program specified in
.Ev SFEED_PLUMBER .
.It o, ENTER, RETURN
Feeds pane: load feed and its items.
In the monocle layout it will also switch to the items pane after loading the
feed items.
Items pane: plumb current item URL, the URL is passed as a parameter to
the program specified in
.Ev SFEED_PLUMBER .
.It c, p, |
Pipe the whole TAB-Separated Value line to a program.
This program can be specified with
.Ev SFEED_PIPER .
.It y
Pipe the TAB-Separated Value field for yanking the URL to a program.
This program can be specified with
.Ev SFEED_YANKER .
.It E
Pipe the TAB-Separated Value field for yanking the enclosure to a program.
This program can be specified with
.Ev SFEED_YANKER .
.It r
Mark item as read.
This will only work when
.Ev SFEED_URL_FILE
is set.
.It u
Mark item as unread.
This will only work when
.Ev SFEED_URL_FILE
is set.
.It f
Mark all items of the current loaded feed as read.
This will only work when
.Ev SFEED_URL_FILE
is set.
.It F
Mark all items of the current loaded feed as unread.
This will only work when
.Ev SFEED_URL_FILE
is set.
.It 1
Set the current layout to a vertical mode.
Showing a feeds sidebar to the left and the feed items to the right.
.It 2
Set the current layout to a horizontal mode.
Showing a feeds sidebar on the top and the feed items on the bottom.
.It 3
Set the current layout to a monocle mode.
Showing either a feeds or a feed items pane.
.It q, EOF
Quit
.El
.Sh MOUSE ACTIONS
When mouse-mode is enabled the below actions are available.
.Bl -tag -width Ds
.It LEFT-CLICK
Feeds pane: select and load the feed and its items.
In the monocle layout it will also switch to the items pane after loading the
feed items.
Items pane: select item, when already selected then plumb it.
.It RIGHT-CLICK
Feeds pane: select feed, but do not load it.
Items pane: pipe the item.
.It SCROLL UP
Scroll one page up.
.It SCROLL DOWN
Scroll one page down.
.It FORWARD
Switch to the items pane.
.It BACKWARD
Switch to the feeds pane.
.El
.Sh SIGNALS
.Bl -tag -width Ds
.It SIGHUP
Reload all feed files which were specified as arguments on startup.
.It SIGINT, SIGTERM
Quit
.It SIGWINCH
Resize the pane dimensions relative to the terminal size.
.El
.Sh ENVIRONMENT VARIABLES
.Bl -tag -width Ds
.It Ev SFEED_AUTOCMD
Read and process a sequence of keys as input commands from this environment
variable first, afterwards read from stdin as usual.
This can be useful to automate certain actions at the start.
.It Ev SFEED_PIPER
A program where the whole TAB-Separated Value line is piped to.
By default this is "sfeed_content".
.It Ev SFEED_PIPER_INTERACTIVE
Handle the program interactively in the same terminal or not.
If set to "1" then before execution it restores the terminal attributes and
.Nm
will wait until the program is finished.
If set to "0" then it will suppress stdout and stderr output.
By default this is set to "1".
.It Ev SFEED_PLUMBER
A program that receives the link URL or enclosure URL as a parameter.
By default this is "xdg-open".
.It Ev SFEED_PLUMBER_INTERACTIVE
Handle the program interactively in the same terminal or not.
If set to "1" then before execution it restores the terminal attributes and
.Nm
will wait until the program is finished.
If set to "0" then it will suppress stdout and stderr output.
For example this option is useful to open a text-mode browser in the same
terminal.
By default this is set to "0".
.It Ev SFEED_YANKER
A program where the URL or enclosure field is piped to, to copy it to a
clipboard.
By default this is "xclip -r".
.It Ev SFEED_YANKER_INTERACTIVE
Handle the program interactively in the same terminal or not.
If set to "1" then before execution it restores the terminal attributes and
.Nm
will wait until the program is finished.
If set to "0" then it will suppress stdout and stderr output.
By default this is set to "0".
.It Ev SFEED_URL_FILE
If this variable is set then a different mode is used to mark items as read,
instead of checking the timestamp, which is the default.
The value specified is a plain-text file containing a list of read URLs, one
URL per line.
This URL is matched on the link field if it is set, otherwise it is matched on
the id field.
.It Ev SFEED_MARK_READ
A program to mark items as read if
.Ev SFEED_URL_FILE
is also set, if unset the default program used is "sfeed_markread read".
The marked items are piped to the program line by line.
If the feed item has a link then this line is the link field, otherwise it is
the id field.
The program is expected to merge items in a safe/transactional manner.
The program should return the exit status 0 on success or non-zero on failure.
.It Ev SFEED_MARK_UNREAD
A program to mark items as unread if
.Ev SFEED_URL_FILE
is also set, if unset the default program used is "sfeed_markread unread".
The unmarked items are piped to the program line by line.
If the feed item has a link then this line is the link field, otherwise it is
the id field.
The program is expected to merge items in a safe/transactional manner.
The program should return the exit status 0 on success or non-zero on failure.
.It Ev SFEED_LAZYLOAD
Lazyload items when reading the feed data from files.
This can reduce memory usage but increases latency when seeking items,
especially on slower disk drives.
It can also cause a race-condition issue if the feed data on disk is changed
while having the UI open and offsets for the lines are different.
A workaround for the race-condition issue is by sending the SIGHUP signal to
.Nm
directly after the data was updated.
This forces
.Nm
to reload the latest feed data and update the correct line offsets.
By default this is set to "0".
.It Ev SFEED_FEED_PATH
This variable is set by
.Nm
when a feed is loaded.
If the data was read from stdin this variable is unset.
It can be used by the plumb or pipe program for scripting purposes.
.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
.Bd -literal
sfeed_curses ~/.sfeed/feeds/*
.Ed
.Pp
Another example which shows some of the features
.Nm
has:
.Bd -literal
export SFEED_AUTOCMD="2tgo"
export SFEED_URL_FILE="$HOME/.sfeed/urls"
[ -f "$SFEED_URL_FILE" ] || touch "$SFEED_URL_FILE"
sfeed_curses ~/.sfeed/feeds/*
.Ed
.Pp
Which does the following:
.Bl -enum
.It
Set the current layout to a horizontal mode ('2' keybind').
Showing a feeds sidebar on the top and the feed items on the bottom.
.It
Toggle showing only feeds with new items in the sidebar ('t' keybind).
.It
Go to the first row in the current panel ('g' keybind).
.It
Load the current selected feed ('o' keybind').
.It
Set a file to use for managing read and unread items.
This file is a plain-text file containing a list of read URLs, one URL per
line.
.It
Check if this file for managing the read and unread items exists.
If it doesn't exist yet then create an empty file.
.It
Start
.Nm .
.El
.Sh SEE ALSO
.Xr sfeed 1 ,
.Xr sfeed_content 1 ,
.Xr sfeed_markread 1 ,
.Xr sfeed_plain 1 ,
.Xr xclip 1 ,
.Xr sfeed 5
.Sh AUTHORS
.An Hiltjo Posthuma Aq Mt hiltjo@codemadness.org

2459
sfeed_curses.c Normal file

File diff suppressed because it is too large Load Diff

35
sfeed_markread Executable file
View File

@ -0,0 +1,35 @@
#!/bin/sh
# Mark items as read/unread: the input is the read / unread URL per line.
usage() {
echo "usage: $0 <read|unread> [urlfile]" >&2
echo "" >&2
echo "An urlfile must be specified as an argument or with the environment variable \$SFEED_URL_FILE" >&2
exit 1
}
urlfile="${2:-${SFEED_URL_FILE}}"
if test -z "${urlfile}"; then
usage
fi
case "$1" in
read)
cat >> "${urlfile}"
;;
unread)
tmp=$(mktemp)
trap "rm -f ${tmp}" EXIT
test -f "${urlfile}" || touch "${urlfile}" 2>/dev/null
LC_CTYPE=C awk -F '\t' '
{ FILENR += (FNR == 1) }
FILENR == 1 { urls[$0] = 1 }
FILENR == 2 { if (!urls[$0]) { print $0 } }
END { exit(FILENR != 2) }' \
"-" "${urlfile}" > "${tmp}" && \
cp "${tmp}" "${urlfile}"
;;
*)
usage
;;
esac

47
sfeed_markread.1 Normal file
View File

@ -0,0 +1,47 @@
.Dd July 25, 2021
.Dt SFEED_MARKREAD 1
.Os
.Sh NAME
.Nm sfeed_markread
.Nd mark items as read/unread
.Sh SYNOPSIS
.Nm
.Ar read | Ar unread
.Op Ar urlfile
.Sh DESCRIPTION
.Nm
reads a plain-text list of URLs from stdin.
The file format for the list of URLs is one URL per line.
.Nm
will write to the file specified as
.Ar urlfile
or with the environment variable
.Ev SFEED_URL_FILE .
The
.Nm
script can be used by
.Xr sfeed_curses 1
to mark items as read and unread.
.Sh ENVIRONMENT VARIABLES
.Bl -tag -width Ds
.It Ev SFEED_URL_FILE
This variable can be set to use as the path to the file containing a
plain-text list of read URLs.
.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
.Bd -literal
export SFEED_URL_FILE="$HOME/.sfeed/urls"
echo 'https://codemadness.org/sfeed.html' | sfeed_markread read
.Ed
.Pp
or
.Bd -literal
echo 'https://codemadness.org/sfeed.html' | sfeed_markread read ~/.sfeed/urls
.Ed
.Sh SEE ALSO
.Xr awk 1 ,
.Xr sfeed_curses 1
.Sh AUTHORS
.An Hiltjo Posthuma Aq Mt hiltjo@codemadness.org

13
themes/mono.h Normal file
View File

@ -0,0 +1,13 @@
/* default mono theme */
#define THEME_ITEM_NORMAL() do { } while(0)
#define THEME_ITEM_FOCUS() do { } while(0)
#define THEME_ITEM_BOLD() do { attrmode(ATTR_BOLD_ON); } while(0)
#define THEME_ITEM_SELECTED() do { if (p->focused) attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_SCROLLBAR_FOCUS() do { } while(0)
#define THEME_SCROLLBAR_NORMAL() do { attrmode(ATTR_FAINT_ON); } while(0)
#define THEME_SCROLLBAR_TICK_FOCUS() do { attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_SCROLLBAR_TICK_NORMAL() do { attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_LINEBAR() do { attrmode(ATTR_FAINT_ON); } while(0)
#define THEME_STATUSBAR() do { attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_INPUT_LABEL() do { attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_INPUT_NORMAL() do { } while(0)

15
themes/mono_highlight.h Normal file
View File

@ -0,0 +1,15 @@
/* mono theme with highlighting of the active panel.
The faint attribute may not work on all terminals though.
The combination bold with faint generally does not work either. */
#define THEME_ITEM_NORMAL() do { } while(0)
#define THEME_ITEM_FOCUS() do { } while(0)
#define THEME_ITEM_BOLD() do { if (p->focused || !selected) attrmode(ATTR_BOLD_ON); } while(0)
#define THEME_ITEM_SELECTED() do { attrmode(ATTR_REVERSE_ON); if (!p->focused) attrmode(ATTR_FAINT_ON); } while(0)
#define THEME_SCROLLBAR_FOCUS() do { } while(0)
#define THEME_SCROLLBAR_NORMAL() do { attrmode(ATTR_FAINT_ON); } while(0)
#define THEME_SCROLLBAR_TICK_FOCUS() do { attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_SCROLLBAR_TICK_NORMAL() do { attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_LINEBAR() do { attrmode(ATTR_FAINT_ON); } while(0)
#define THEME_STATUSBAR() do { attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_INPUT_LABEL() do { attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_INPUT_NORMAL() do { } while(0)

13
themes/newsboat.h Normal file
View File

@ -0,0 +1,13 @@
/* newsboat-like (blue, yellow) */
#define THEME_ITEM_NORMAL() do { } while(0)
#define THEME_ITEM_FOCUS() do { } while(0)
#define THEME_ITEM_BOLD() do { attrmode(ATTR_BOLD_ON); } while(0)
#define THEME_ITEM_SELECTED() do { if (p->focused) ttywrite("\x1b[93;44m"); } while(0) /* bright yellow fg, blue bg */
#define THEME_SCROLLBAR_FOCUS() do { ttywrite("\x1b[34m"); } while(0) /* blue fg */
#define THEME_SCROLLBAR_NORMAL() do { ttywrite("\x1b[34m"); } while(0)
#define THEME_SCROLLBAR_TICK_FOCUS() do { ttywrite("\x1b[44m"); } while(0) /* blue bg */
#define THEME_SCROLLBAR_TICK_NORMAL() do { ttywrite("\x1b[44m"); } while(0)
#define THEME_LINEBAR() do { ttywrite("\x1b[34m"); } while(0)
#define THEME_STATUSBAR() do { attrmode(ATTR_BOLD_ON); ttywrite("\x1b[93;44m"); } while(0)
#define THEME_INPUT_LABEL() do { } while(0)
#define THEME_INPUT_NORMAL() do { } while(0)

24
themes/templeos.h Normal file
View File

@ -0,0 +1,24 @@
/* TempleOS-like (for fun and god) */
/* set true-color foreground / background, Terry would've preferred ANSI */
#define SETFGCOLOR(r,g,b) ttywritef("\x1b[38;2;%d;%d;%dm", r, g, b)
#define SETBGCOLOR(r,g,b) ttywritef("\x1b[48;2;%d;%d;%dm", r, g, b)
#define THEME_ITEM_NORMAL() do { SETFGCOLOR(0x00, 0x00, 0xaa); SETBGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_ITEM_FOCUS() do { SETFGCOLOR(0x00, 0x00, 0xaa); SETBGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_ITEM_BOLD() do { attrmode(ATTR_BOLD_ON); SETFGCOLOR(0xaa, 0x00, 0x00); SETBGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_ITEM_SELECTED() do { if (p->focused) attrmode(ATTR_REVERSE_ON); } while(0)
#define THEME_SCROLLBAR_FOCUS() do { SETFGCOLOR(0x00, 0x00, 0xaa); SETBGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_SCROLLBAR_NORMAL() do { SETFGCOLOR(0x00, 0x00, 0xaa); SETBGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_SCROLLBAR_TICK_FOCUS() do { SETBGCOLOR(0x00, 0x00, 0xaa); SETFGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_SCROLLBAR_TICK_NORMAL() do { SETBGCOLOR(0x00, 0x00, 0xaa); SETFGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_LINEBAR() do { SETFGCOLOR(0x00, 0x00, 0xaa); SETBGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_STATUSBAR() do { ttywrite("\x1b[6m"); SETBGCOLOR(0x00, 0x00, 0xaa); SETFGCOLOR(0xff, 0xff, 0xff); } while(0) /* blink statusbar */
#define THEME_INPUT_LABEL() do { SETFGCOLOR(0x00, 0x00, 0xaa); SETBGCOLOR(0xff, 0xff, 0xff); } while(0)
#define THEME_INPUT_NORMAL() do { SETFGCOLOR(0x00, 0x00, 0xaa); SETBGCOLOR(0xff, 0xff, 0xff); } while(0)
#undef SCROLLBAR_SYMBOL_BAR
#define SCROLLBAR_SYMBOL_BAR "\xe2\x95\x91" /* symbol: "double vertical" */
#undef LINEBAR_SYMBOL_BAR
#define LINEBAR_SYMBOL_BAR "\xe2\x95\x90" /* symbol: "double horizontal" */
#undef LINEBAR_SYMBOL_RIGHT
#define LINEBAR_SYMBOL_RIGHT "\xe2\x95\xa3" /* symbol: "double vertical and left" */