Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mless: doesn't work on OpenBSD 7.6 due to lack of LESSOPEN #266

Open
leahneukirchen opened this issue Oct 9, 2024 · 5 comments
Open

mless: doesn't work on OpenBSD 7.6 due to lack of LESSOPEN #266

leahneukirchen opened this issue Oct 9, 2024 · 5 comments

Comments

@leahneukirchen
Copy link
Owner

LESSOPEN support was removed in OpenBSD in openbsd/src@c74702f

I'm not sure how we can have something like mless without this feature... one would need to pre-render the whole sequence perhaps?

@josephchoe
Copy link

That might result in performance problems for large sequences. I've just gotten around it by piping a message with the preamble into less, though that doesn't allow me to page through mail, but oh well.

@leahneukirchen
Copy link
Owner Author

One approach could be to drive less in a loop, and use exit codes to switch between files, only starting less with one mail rendered every time.

@josephchoe
Copy link

Hrm, I'm assuming that this would have different keybindings than lesskey(1)?

I looked at the source for less(1) on OpenBSD, and exit codes seem to be here: https://github.com/openbsd/src/blob/master/usr.bin/less/less.h#L157-L159

So, 0 for success, 1 for error, and 2 for interrupt. Not a whole lot of wiggle room to switch between specific files. Unless there's something I'm missing?

@leahneukirchen
Copy link
Owner Author

leahneukirchen commented Dec 22, 2024

e.g. add Z quit \42 to .lesskey, run lesskey, press Z in less, it exits with status 34 (=042).

Works on OpenBSD 7.6.

@josephchoe
Copy link

josephchoe commented Dec 22, 2024

Is something like this what you had in mind?

diff --git a/mless b/mless
index ddead98..51bd361 100755
--- a/mless
+++ b/mless
@@ -85,10 +85,26 @@ elif [ -f "$HOME/.mblaze/mless" ]; then
 elif [ -f "$HOME/.mless" ]; then
 	export LESSKEY="$HOME/.mless"
 fi
+scan=0
 while :; do
-	LESSOPEN="|$0 --filter %s" \
-		less -Ps"mless %f?m (message %i of %m).." -R \
-			"+:e $(mscan -n .)$nl" //scan $(mscan -n :)
+	local cur=$(mscan -n .)
+	local total=$(mscan -n : | tail -1)
+
+	if [ $scan -ne 0 ]
+	then
+		cur="//scan"
+		local status="mless.."
+	else
+		local status="mless $cur (message $cur of $total).."
+	fi
+
+	{
+		case $cur in
+			[0-9]*) $0 --filter $cur;;
+			*) $0 --filter //scan;;
+		esac
+	} | less -Ps"$status" -R
+
 	case "$?" in
 	0|1) exit $?;;
 	36) # $ goto end
@@ -111,6 +127,21 @@ while :; do
 	72) # H toggle HTML mode
 		MLESS_HTML=$((1-$MLESS_HTML))
 		;;
+	91) # [ prev file
+		case $cur in
+			1) scan=1;;
+			*) mseq -C '.-1' 2>/dev/null;;
+		esac
+		;;
+	93) # ] next file
+		if [ $scan -eq 0 ]
+		then
+			mseq -C '.+1' 2>/dev/null
+		else
+			scan=0
+			mseq -C 1 2>/dev/null
+		fi
+		;;
 	94) # ^ goto parent
 		mseq -C '.^' 2>/dev/null
 		;;
diff --git a/mlesskey.example b/mlesskey.example
index be82e1d..90d69af 100644
--- a/mlesskey.example
+++ b/mlesskey.example
@@ -4,8 +4,8 @@
 # When using less >=590: copy this file to ~/.mlesskey
 Q quit \1
 :cq quit \1
-[ prev-file
-] next-file
+[ quit [
+] quit ]
 { noaction E1\n
 } quit $
 $ quit $

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants