Hi list,

Firstly, thanks for OpenBSD and especially 7.8.  Now all my systems are
on neovim 0.11.

I've been having issues with less -F not working in xterm.  The command
just returns without displaying anything.  This can be worked around by
adding -X to not initialise the terminal.  This works fine, without -X,
in the console.

After some investigating it seems the OpenBSD less fork is missing some
post-fork patches to deal with terminals with alternate screen
capabilities.  I assume the console does not have the alt screen
capability which is why it is unaffected.

After looking at CVS, Garrett's (now archived) repo, and the upstream
repo I've got it working again for me with the inlined and attached
patch which is a mash up of pieces from a mix of upstream commits
listed below.
The function rename from the source commits just made more sense to me.

Anyway, I hope this is useful.

Best Regards,
Jon

Reference commits:

With -F, do not output ti/te if file fits on one screen.
https://github.com/gwsw/less/commit/7656c13770d75b99f3da4b0035a1ba9bb0295bfd

Code cleanup.
https://github.com/gwsw/less/commit/fed277e50e13fff72b94dead40fbcca49dd5be99

Don't count lines of initial screen if using -X with -F.
https://github.com/gwsw/less/commit/bc231ee311f6e473620c29b27c901bcb3048d908

Don't output keyboard init or mouse init if -F and file fits on one
screen.
https://github.com/gwsw/less/commit/03e656bee412d19ce60e4733b33eba4baddbcedc

--

Index: usr.bin/less/forwback.c
===================================================================
RCS file: /cvs/src/usr.bin/less/forwback.c,v
diff -u -p -r1.13 forwback.c
--- usr.bin/less/forwback.c     18 May 2024 00:08:06 -0000      1.13
+++ usr.bin/less/forwback.c     7 Nov 2025 19:19:45 -0000
@@ -357,3 +357,20 @@ get_back_scroll(void)
                return (sc_height - 2);
        return (10000); /* infinity */
 }
+
+/*
+ * Does the entire file fit on one screen?
+ */
+int
+fits_one_screen(void)
+{
+       int nlines;
+       off_t pos = ch_zero();
+
+       for (nlines = 0; nlines < sc_height; nlines++) {
+               pos = forw_line(pos);
+               if (pos == -1)
+                       return TRUE;
+       }
+       return FALSE;
+}
Index: usr.bin/less/funcs.h
===================================================================
RCS file: /cvs/src/usr.bin/less/funcs.h,v
diff -u -p -r1.26 funcs.h
--- usr.bin/less/funcs.h        14 Apr 2024 18:11:54 -0000      1.26
+++ usr.bin/less/funcs.h        7 Nov 2025 19:19:45 -0000
@@ -276,3 +276,4 @@ void open_getchr(void);
 int getchr(void);
 void *lsignal(int, void (*)(int));
 char *helpfile(void);
+int fits_one_screen(void);
Index: usr.bin/less/main.c
===================================================================
RCS file: /cvs/src/usr.bin/less/main.c,v
diff -u -p -r1.40 main.c
--- usr.bin/less/main.c 14 Apr 2024 18:11:54 -0000      1.40
+++ usr.bin/less/main.c 7 Nov 2025 19:19:45 -0000
@@ -42,6 +42,7 @@ int force_logfile = FALSE;
 char *namelogfile = NULL;
 char *editor;
 char *editproto;
+int one_screen;

 extern char    *tags;
 extern char    *tagoption;
@@ -260,9 +261,18 @@ main(int argc, char *argv[])
        } else if (nifile() == 0) {
                if (edit_stdin())  /* Edit standard input */
                        quit(QUIT_ERROR);
+               if (quit_if_one_screen && !no_init)
+                       one_screen = fits_one_screen();
        } else {
                if (edit_first())  /* Edit first valid file in cmd line */
                        quit(QUIT_ERROR);
+               if (quit_if_one_screen) {
+                       /* If more than one file, -F cannot be used */
+                       if (nifile() > 1)
+                               quit_if_one_screen = FALSE;
+                       else if (!no_init)
+                               one_screen = fits_one_screen();
+               }
        }

        init();
Index: usr.bin/less/screen.c
===================================================================
RCS file: /cvs/src/usr.bin/less/screen.c,v
diff -u -p -r1.25 screen.c
--- usr.bin/less/screen.c       3 Sep 2019 23:08:42 -0000       1.25
+++ usr.bin/less/screen.c       7 Nov 2025 19:19:45 -0000
@@ -87,6 +87,8 @@ extern int tty;
 extern int top_scroll;
 extern int oldbot;
 extern int hilite_search;
+extern int quit_if_one_screen;
+extern int one_screen;

 /*
  * Change terminal to "raw mode", or restore to "normal" mode.
@@ -527,10 +529,12 @@ tmodes(char *incap, char *outcap, char *
 void
 init(void)
 {
-       if (!no_init)
-               (void) tputs(sc_init, sc_height, putchr);
-       if (!no_keypad)
-               (void) tputs(sc_s_keypad, sc_height, putchr);
+       if (!(quit_if_one_screen && one_screen)) {
+               if (!no_init)
+                       (void) tputs(sc_init, sc_height, putchr);
+               if (!no_keypad)
+                       (void) tputs(sc_s_keypad, sc_height, putchr);
+       }
        if (top_scroll) {
                int i;

@@ -555,10 +559,12 @@ deinit(void)
 {
        if (!init_done)
                return;
-       if (!no_keypad)
-               (void) tputs(sc_e_keypad, sc_height, putchr);
-       if (!no_init)
-               (void) tputs(sc_deinit, sc_height, putchr);
+       if (!(quit_if_one_screen && one_screen)) {
+               if (!no_keypad)
+                       (void) tputs(sc_e_keypad, sc_height, putchr);
+               if (!no_init)
+                       (void) tputs(sc_deinit, sc_height, putchr);
+       }
        init_done = 0;
 }
Index: usr.bin/less/forwback.c
===================================================================
RCS file: /cvs/src/usr.bin/less/forwback.c,v
diff -u -p -r1.13 forwback.c
--- usr.bin/less/forwback.c	18 May 2024 00:08:06 -0000	1.13
+++ usr.bin/less/forwback.c	7 Nov 2025 19:19:45 -0000
@@ -357,3 +357,20 @@ get_back_scroll(void)
 		return (sc_height - 2);
 	return (10000); /* infinity */
 }
+
+/*
+ * Does the entire file fit on one screen?
+ */
+int
+fits_one_screen(void)
+{
+	int nlines;
+	off_t pos = ch_zero();
+
+	for (nlines = 0; nlines < sc_height; nlines++) {
+		pos = forw_line(pos);
+		if (pos == -1)
+			return TRUE;
+	}
+	return FALSE;
+}
Index: usr.bin/less/funcs.h
===================================================================
RCS file: /cvs/src/usr.bin/less/funcs.h,v
diff -u -p -r1.26 funcs.h
--- usr.bin/less/funcs.h	14 Apr 2024 18:11:54 -0000	1.26
+++ usr.bin/less/funcs.h	7 Nov 2025 19:19:45 -0000
@@ -276,3 +276,4 @@ void open_getchr(void);
 int getchr(void);
 void *lsignal(int, void (*)(int));
 char *helpfile(void);
+int fits_one_screen(void);
Index: usr.bin/less/main.c
===================================================================
RCS file: /cvs/src/usr.bin/less/main.c,v
diff -u -p -r1.40 main.c
--- usr.bin/less/main.c	14 Apr 2024 18:11:54 -0000	1.40
+++ usr.bin/less/main.c	7 Nov 2025 19:19:45 -0000
@@ -42,6 +42,7 @@ int force_logfile = FALSE;
 char *namelogfile = NULL;
 char *editor;
 char *editproto;
+int one_screen;
 
 extern char	*tags;
 extern char	*tagoption;
@@ -260,9 +261,18 @@ main(int argc, char *argv[])
 	} else if (nifile() == 0) {
 		if (edit_stdin())  /* Edit standard input */
 			quit(QUIT_ERROR);
+		if (quit_if_one_screen && !no_init)
+			one_screen = fits_one_screen();
 	} else {
 		if (edit_first())  /* Edit first valid file in cmd line */
 			quit(QUIT_ERROR);
+		if (quit_if_one_screen) {
+			/* If more than one file, -F cannot be used */
+			if (nifile() > 1) 
+				quit_if_one_screen = FALSE;
+			else if (!no_init)
+				one_screen = fits_one_screen();
+		}
 	}
 
 	init();
Index: usr.bin/less/screen.c
===================================================================
RCS file: /cvs/src/usr.bin/less/screen.c,v
diff -u -p -r1.25 screen.c
--- usr.bin/less/screen.c	3 Sep 2019 23:08:42 -0000	1.25
+++ usr.bin/less/screen.c	7 Nov 2025 19:19:45 -0000
@@ -87,6 +87,8 @@ extern int tty;
 extern int top_scroll;
 extern int oldbot;
 extern int hilite_search;
+extern int quit_if_one_screen;
+extern int one_screen;
 
 /*
  * Change terminal to "raw mode", or restore to "normal" mode.
@@ -527,10 +529,12 @@ tmodes(char *incap, char *outcap, char *
 void
 init(void)
 {
-	if (!no_init)
-		(void) tputs(sc_init, sc_height, putchr);
-	if (!no_keypad)
-		(void) tputs(sc_s_keypad, sc_height, putchr);
+	if (!(quit_if_one_screen && one_screen)) {
+		if (!no_init)
+			(void) tputs(sc_init, sc_height, putchr);
+		if (!no_keypad)
+			(void) tputs(sc_s_keypad, sc_height, putchr);
+	}
 	if (top_scroll) {
 		int i;
 
@@ -555,10 +559,12 @@ deinit(void)
 {
 	if (!init_done)
 		return;
-	if (!no_keypad)
-		(void) tputs(sc_e_keypad, sc_height, putchr);
-	if (!no_init)
-		(void) tputs(sc_deinit, sc_height, putchr);
+	if (!(quit_if_one_screen && one_screen)) {
+        	if (!no_keypad)
+			(void) tputs(sc_e_keypad, sc_height, putchr);
+		if (!no_init)
+			(void) tputs(sc_deinit, sc_height, putchr);
+	}
 	init_done = 0;
 }
 

Reply via email to