Compare commits

..

4 Commits

Author SHA1 Message Date
e60ffeeb20
Improve PAGER defaults
We basically need less(1), nothing else will work correctly.

I'm not sure where I took pager(1) from, might be a Debian thing.
2020-09-28 21:34:09 +02:00
9a2f6ab5cf
README.adoc: talk about view and edit helpers 2020-09-28 21:26:33 +02:00
0a66ae4d26
Expand a comment about overstriked underlining 2020-09-28 20:11:38 +02:00
121d7850fe
Show error output from failed helpers
Usually, when the pager or the editor fail and return a non-zero
exit status, they display a message on the standard error output.

We might also try to redirect this output to show_mesage() but
it might not fit as a whole, so, given the relative rareness
of this situation, this slight inconsistency shouldn't be much
of an issue.

It'd also be possible to redirect the output to run_pager() but
in doing so, we might make the problem recursive.
2020-09-28 20:05:29 +02:00
2 changed files with 30 additions and 7 deletions

View File

@ -89,10 +89,10 @@ bind -x '"\201": sdn-restore'
bind '"\eo":"\200\C-m\201"' bind '"\eo":"\200\C-m\201"'
.... ....
Colors Colours
------ -------
Here is an example of a '~/.config/sdn/look' file; the format is similar to Here is an example of a '~/.config/sdn/look' file; the format is similar to
that of git, only named colors aren't supported: that of git, only named colours aren't supported:
.... ....
cursor 231 202 cursor 231 202
@ -101,7 +101,7 @@ cwd bold
input input
.... ....
Filename colors are taken from the `LS_COLORS` environment variable. Filename colours are taken from the `LS_COLORS` environment variable.
Run `dircolors` to get some defaults. Run `dircolors` to get some defaults.
Bindings Bindings
@ -115,6 +115,20 @@ normal l choose
normal ? help normal ? help
.... ....
Helper programs
---------------
The F3 and F4 keys are normally bound to actions 'view' and 'edit', similarly to
Norton Commander and other orthodox file managers. The helper programs used
here may be changed by setting the PAGER and VISUAL (or EDITOR) environment
variables.
While it is mostly possible to get 'mcview' working using an invocation like
`PAGER='mcview -u' sdn`, beware that this helper cannot read files from its
standard input, nor does it enable overstrike processing by default (F9, could
be hacked around in 'mc.ext' by turning on the `nroff` switch for a custom file
extension, just without actually invoking 'nroff'), and thus it can't show the
program help. 'sdn' is currently optimised for 'less' as the pager.
Similar software Similar software
---------------- ----------------
* https://elvish.io/ is an entire shell with an integrated ranger-like file * https://elvish.io/ is an entire shell with an integrated ranger-like file

15
sdn.cpp
View File

@ -243,7 +243,8 @@ fun capitalize (const string &s) -> string {
return result; return result;
} }
/// Underlining for teletypes, also imitated in more(1) and less(1) /// Underlining for teletypes (also called overstriking),
/// also imitated in more(1) and less(1)
fun underline (const string& s) -> string { fun underline (const string& s) -> string {
string result; string result;
for (auto c : s) for (auto c : s)
@ -865,6 +866,12 @@ fun run_program (initializer_list<const char*> list, const string &filename) {
if (WSTOPSIG (status) == SIGTSTP) if (WSTOPSIG (status) == SIGTSTP)
kill (child, SIGCONT); kill (child, SIGCONT);
tcsetpgrp (STDOUT_FILENO, getpgid (0)); tcsetpgrp (STDOUT_FILENO, getpgid (0));
if (WIFEXITED (status) && WEXITSTATUS (status)) {
printf ("Helper returned non-zero exit status %d. "
"Press Enter to continue.\n", WEXITSTATUS (status));
string dummy; getline (cin, dummy);
}
} }
refresh (); refresh ();
@ -872,7 +879,9 @@ fun run_program (initializer_list<const char*> list, const string &filename) {
} }
fun view (const string &filename) { fun view (const string &filename) {
run_program ({(const char *) getenv ("PAGER"), "pager", "cat"}, filename); // XXX: we cannot realistically detect that the pager hasn't made a pause
// at the end of the file, so we can't ensure all contents have been seen
run_program ({(const char *) getenv ("PAGER"), "less", "cat"}, filename);
} }
fun edit (const string &filename) { fun edit (const string &filename) {
@ -896,7 +905,7 @@ fun run_pager (FILE *contents) {
dup2 (fileno (contents), STDIN_FILENO); dup2 (fileno (contents), STDIN_FILENO);
// Behaviour copies man-db's man(1), similar to POSIX man(1) // Behaviour copies man-db's man(1), similar to POSIX man(1)
for (auto pager : {(const char *) getenv ("PAGER"), "pager", "cat"}) for (auto pager : {(const char *) getenv ("PAGER"), "less", "cat"})
if (pager) execl ("/bin/sh", "/bin/sh", "-c", pager, NULL); if (pager) execl ("/bin/sh", "/bin/sh", "-c", pager, NULL);
_exit (EXIT_FAILURE); _exit (EXIT_FAILURE);
default: default: