Hi Greg,
I can see that there has already been some discussion about how to
implement syntax highlighting for gmi files. You had suggested to create
a custom pager, that is based on less.
I have recently written a pager specifically for text/gemini and thought
you might find it interesting. It doesn't just do syntax highlighting,
but also word wrapping and, perhaps more interestingly, link selection.
I think that the link selection makes browsing a lot smoother. I have
attached a simple demo-patch (that assumes PAGER=gmir) below.
You can find the source at https://github.com/codesoap/gmir and a little
blog post about it at gemini://rulmer.xyz/gmir.gmi .
Greetings,
Richard Ulmer
---
gmi | 31 +++++++++++++------------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/gmi b/gmi
index 2262609..cddcb67 100755
--- a/gmi+++ b/gmi
@@ -126,28 +126,23 @@ success() (
case ${format-fixed} in
[Ff][Ll][Oo][Ww][Ee][Dd]) LESS=S$LESS ;;
esac
- printf %s "$response" |+ uri="$(printf %s "$response" | base64 -d |
sed '1d;s/\r$//' |
iconv -f "${charset-UTF-8}" |
- pager- {- printf '[%s] \033[4m\033[34m%s\033[m %s\n' \- B "$back" Back \- U ../ Up \- R "$path" Reload- printf %s "$response" |- base64 -d |- sed 1d |- iconv -f "${charset-UTF-8}" |- awk '/^```/ { pre = (pre + 1) % 2; next }- ! pre && sub("^=>", "") {- $1 = "[" ++i "] \033[4m\033[34m" $1 "\033[m"- print- }'- } | fzf --ansi | while IFS=' ' read -r _ uri _; do- main "$uri"+ pager)"+ if [ -z "$uri" ]; then+ {+ printf '[%s] \033[4m\033[34m%s\033[m %s\n' \+ B "$back" Back \+ U ../ Up \+ R "$path" Reload+ } | fzf --ansi | while IFS=' ' read -r _ uri _; do+ main "$uri" done
+ else+ main "$uri"+ fi ;;
*)
printf %s "$response" | base64 -d | sed 1d > "${path##*/}"
--
2.37.3
On 11/03/2023 09:38, codesoap wrote:
> Hi Greg,> I can see that there has already been some discussion about how to> implement syntax highlighting for gmi files. You had suggested to create> a custom pager, that is based on less.> > I have recently written a pager specifically for text/gemini and thought> you might find it interesting. It doesn't just do syntax highlighting,> but also word wrapping and, perhaps more interestingly, link selection.> > I think that the link selection makes browsing a lot smoother. I have> attached a simple demo-patch (that assumes PAGER=gmir) below.> > You can find the source at https://github.com/codesoap/gmir and a little> blog post about it at gemini://rulmer.xyz/gmir.gmi .> > Greetings,> Richard Ulmer
Hi Richard,
Thank you for this. I've only just got around to trying it. Sorry to
leave you without a reply for so long.
It seems to work really well and complements terminal-based clients
perfectly. This a valuable project because it takes away a lot of the
work of building a such a client. It handles document presentation and
link selection which are both non-trivial problems.
When I get some time to work on gmi again, I want to revise the way it
handles pagers to integrate smoothly with gmir if that's what PAGER is
set to, or fall back to the usual fzf behaviour otherwise.
Regards,
Greg