From 8060459dc777d69a22fdf0a7694b1d9c03265787 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Mon, 3 Apr 2023 21:37:12 +0300 Subject: [PATCH] Improved gmi2map logic --- tools/README-tools.md | 18 +++++++++--------- tools/gmi2map.sh | 5 ++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/README-tools.md b/tools/README-tools.md index ec8b999..18bd981 100644 --- a/tools/README-tools.md +++ b/tools/README-tools.md @@ -73,7 +73,7 @@ Note that by default, reflow logic in `gmi2map.sh` is optional and you have to s cat [file] | gmi2map.sh [page_width] [leading_spaces] [trailing_spaces] [placeholder_char] ``` -I.e. it looks like the `phlow.sh` and `gopherinfo.sh` options combined, but the spaces part only applies to the reflow, which is also off by default. +I.e. it looks like the `phlow.sh` and `gopherinfo.sh` options combined, but the spaces part only applies to the reflow, which is also off by default. Also, it doesn't align the whitespaces after the infolines unless there is non-zero amount of trailing spaces. Example - imagine we have this rudimentary Gemtext document in the `example.gmi` file: ``` @@ -87,19 +87,19 @@ I write a bit longer Gemtext here to showcase reflow capabilities of Bopher Tool See ya! ``` -When running `cat example.gmi | bash gmi2map.sh 67`, this file translates to the following Gophermap: +When running `cat example.gmi | bash gmi2map.sh 67 0 1`, this file translates to the following Gophermap: ``` $ cat example.gmi | bash gmi2map.sh 67 -iI write short Gemtext here. ; ; 0 -i ; ; 0 -iI write a bit longer Gemtext here to showcase reflow capabilities ; ; 0 -iof Bopher Tools' gmi2map.sh script, because it really is cool. ; ; 0 -i ; ; 0 +iI write short Gemtext here. ; ; 0 +i ; ; 0 +iI write a bit longer Gemtext here to showcase reflow capabilities ; ; 0 +iof Bopher Tools' gmi2map.sh script, because it really is cool. ; ; 0 +i ; ; 0 1Anyway, why not publish it on Gopher? luxferre happynetbox.com 79 hOr read my blog on Web... URL:https://chronovir.us ; 0 -i ; ; 0 -iSee ya! ; ; 0 +i ; ; 0 +iSee ya! ; ; 0 . ``` diff --git a/tools/gmi2map.sh b/tools/gmi2map.sh index 2a0baf8..634fff5 100644 --- a/tools/gmi2map.sh +++ b/tools/gmi2map.sh @@ -22,8 +22,11 @@ CRLF=$'\r\n' [[ -z "$TSPACES" ]] && TSPACES=0 [[ -z "$DELIM" ]] && DELIM=';' +FORMAT_WIDTH=0 # make formatting width distinct from the target reflow width +(( TSPACES > 0 )) && FORMAT_WIDTH="$TARGET_WIDTH" # and only use it if there are trailing spaces + # format strings to use in different situations: -reflowfmt="%-$(( LSPACES ))s%-${TARGET_WIDTH}s%-$(( TSPACES ))s\n" # params: smth, line, smth +reflowfmt="%-$(( LSPACES ))s%-${FORMAT_WIDTH}s%-$(( TSPACES ))s\n" # params: smth, line, smth infofmt="i%s${TAB}%s${TAB}%s${TAB}0${CRLF}" # params: line, DELIM, DELIM gopherlinkfmt="%s%s${TAB}%s${TAB}%s${TAB}%d${CRLF}" # params: type, name, selector, host, port extlinkfmt="h%s${TAB}URL:%s${TAB}%s${TAB}0${CRLF}" # params: name, URL, DELIM -- 2.45.2