Remove automatic pager functionality

This commit is contained in:
Jeremy Baxter 2023-12-14 10:19:33 +13:00
parent 35a880ae26
commit 1c9bb056e8
4 changed files with 2 additions and 63 deletions

View file

@ -20,11 +20,6 @@ A Psalm of David.
He makes me lie down in green pastures.... He makes me lie down in green pastures....
``` ```
If the requested passage is over 32 lines long, `esv` will pipe it through
a pager (default less). The pager being used can be changed through the
`ESV_PAGER` environment variable or just disabled altogether by passing the
-P option.
The names of Bible books are not case sensitive, so John, john, and JOHN The names of Bible books are not case sensitive, so John, john, and JOHN
are all accepted. are all accepted.
@ -63,11 +58,6 @@ $ make
# make install # make install
``` ```
<!--
By default the configure script looks for ldc and dmd in your PATH
and optimises the command-line arguments based on the compiler.
-->
## Documentation ## Documentation
All documentation is contained in the manual pages. To access them, you can run All documentation is contained in the manual pages. To access them, you can run

View file

@ -7,10 +7,8 @@ public:
enum DEFAULT_APIKEY = "abfb7456fa52ec4292c79e435890cfa3df14dc2b"; enum DEFAULT_APIKEY = "abfb7456fa52ec4292c79e435890cfa3df14dc2b";
enum DEFAULT_CONFIGPATH = "~/.config/esv.conf"; enum DEFAULT_CONFIGPATH = "~/.config/esv.conf";
enum DEFAULT_MPEGPLAYER = "mpg123"; enum DEFAULT_MPEGPLAYER = "mpg123";
enum DEFAULT_PAGER = "less";
enum ENV_CONFIG = "ESV_CONFIG"; enum ENV_CONFIG = "ESV_CONFIG";
enum ENV_PAGER = "ESV_PAGER";
enum ENV_PLAYER = "ESV_PLAYER"; enum ENV_PLAYER = "ESV_PLAYER";
enum BUGREPORTURL = "https://codeberg.org/jtbx/esv/issues"; enum BUGREPORTURL = "https://codeberg.org/jtbx/esv/issues";

16
esv.1
View file

@ -24,14 +24,6 @@ to fast-forward, etc. Read about the
.Fl C .Fl C
option in mpg123's manual for more information. option in mpg123's manual for more information.
.Pp .Pp
If a text passage is too long for standard display on a terminal,
.Nm
will put it through a text pager (default less) in order for you to be able to
scroll through the text. This behaviour can be disabled by passing
the
.Fl P
flag.
.Pp
The options are as follows: The options are as follows:
.Bl -tag -width keyword .Bl -tag -width keyword
.It Fl a .It Fl a
@ -59,9 +51,6 @@ as the maximum line length.
Exclude verse numbers. Exclude verse numbers.
.It Fl n .It Fl n
Include verse numbers (the default). Include verse numbers (the default).
.It Fl P
If the passage is over 32 lines long, don't
pipe it into a pager.
.It Fl R .It Fl R
Exclude passage references. Exclude passage references.
.It Fl r .It Fl r
@ -73,11 +62,6 @@ Print the version number and exit.
.It Ev ESV_CONFIG .It Ev ESV_CONFIG
Where to read the configuration file, rather than using the default location (see section Where to read the configuration file, rather than using the default location (see section
.Sx FILES ) . .Sx FILES ) .
.It Ev ESV_PAGER
What pager to use when the passage is over 32 lines long, rather than using
the
.Ic less
utility.
.It Ev ESV_PLAYER .It Ev ESV_PLAYER
What MP3 player to use for playing audio, rather than using mpg123. What MP3 player to use for playing audio, rather than using mpg123.
Using mpg123 is recommended over other players such as mpv, because Using mpg123 is recommended over other players such as mpv, because

37
esv.d
View file

@ -44,7 +44,6 @@ bool fFlag, FFlag; /* footnotes */
bool hFlag, HFlag; /* headings */ bool hFlag, HFlag; /* headings */
int lFlag; /* line length */ int lFlag; /* line length */
bool nFlag, NFlag; /* verse numbers */ bool nFlag, NFlag; /* verse numbers */
bool PFlag; /* disable pager */
bool rFlag, RFlag; /* passage references */ bool rFlag, RFlag; /* passage references */
string sFlag; /* search passages */ string sFlag; /* search passages */
bool VFlag; /* show version */ bool VFlag; /* show version */
@ -79,11 +78,8 @@ main(string[] args)
bool bool
run(string[] args) run(string[] args)
{ {
ushort lines;
string apiKey; string apiKey;
string configPath; string configPath;
string pager;
string verses;
Ini iniData; Ini iniData;
ESVApi esv; ESVApi esv;
@ -98,7 +94,6 @@ run(string[] args)
"H", &HFlag, "h", &hFlag, "H", &HFlag, "h", &hFlag,
"l", &lFlag, "l", &lFlag,
"N", &NFlag, "n", &nFlag, "N", &NFlag, "n", &nFlag,
"P", &PFlag,
"R", &RFlag, "r", &rFlag, "R", &RFlag, "r", &rFlag,
"s", &sFlag, "s", &sFlag,
"V", &VFlag, "V", &VFlag,
@ -126,7 +121,7 @@ run(string[] args)
} }
if (args.length < 3) { if (args.length < 3) {
stderr.writefln("usage: %s [-aFfHhNnPRrV] [-C config] [-l length] [-s query] book verses", args[0].baseName()); stderr.writefln("usage: %s [-aFfHhNnRrV] [-C config] [-l length] [-s query] book verses", args[0].baseName());
return false; return false;
} }
@ -259,35 +254,7 @@ key = %s
if (RFlag) esv.opts.b["include-passage-references"] = false; if (RFlag) esv.opts.b["include-passage-references"] = false;
if (lFlag != 0) esv.opts.i["line-length"] = lFlag; if (lFlag != 0) esv.opts.i["line-length"] = lFlag;
verses = esv.getPassage(args[1].parseBook(), args[2]); writeln(esv.getPassage(args[1].parseBook(), args[2]));
foreach (string line; verses.splitLines())
++lines;
/* If the passage is very long, pipe it into a pager */
if (lines > 32 && !PFlag) {
import std.process : pipeProcess, Redirect, wait, ProcessException;
pager = environment.get(ENV_PAGER, DEFAULT_PAGER);
try {
auto pipe = pipeProcess(pager, Redirect.stdin);
pipe.stdin.writeln(verses);
pipe.stdin.flush();
pipe.stdin.close();
pipe.pid.wait();
} catch (ProcessException e) {
enforce(e.msg.matchFirst(regex("^Executable file not found")).empty,
format!"%s: command not found"(e.msg
.matchFirst(": (.+)$")[0]
.replaceFirst(regex("^: "), "")
));
throw new Exception(e.msg); /* catch-all */
}
return true;
}
writeln(verses);
return true; return true;
} }