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

How to clear screen content after quitting opam --help #191

Open
muzimuzhi opened this issue Sep 8, 2024 · 2 comments
Open

How to clear screen content after quitting opam --help #191

muzimuzhi opened this issue Sep 8, 2024 · 2 comments
Labels

Comments

@muzimuzhi
Copy link

As a macOS user new to OCaml, I find after I quit opam --help or dune --help, the help content is kept in the terminal. This default behavior is different from (most?) other CLI programs like git or man.

$ opam --help
OPAM(1)                           Opam Manual                          OPAM(1)

NAME
       opam - source-based package management

SYNOPSIS
       opam [COMMAND] …
...
$ git --paginate --help
$ man less
$

Is there a way to overwrite this behavior?

I have environment variables

$ echo $PAGER
less
$ echo $LESS
-R

It seems this is caused by the use of less option -X/--no-init, added in 1de3611 and f239981 for #167.

match pager with
| None -> print `Plain ppf v
| Some (pager, opts) ->
let pager = match Sys.win32 with
| false -> "LESS=FRX " ^ pager ^ opts
| true -> "set LESS=FRX && " ^ pager ^ opts
in

-X or --no-init
       Disables sending the termcap initialization and deinitialization strings to the
       terminal.  This is sometimes desirable if the deinitialization string does something
       unnecessary, like clearing the screen.
@dbuenzli
Copy link
Owner

dbuenzli commented Sep 8, 2024

Here are a few points.

  1. This behaviour is more ergonomic than the alternative you suggest: you can get to the documentation of an option of interest, quit the pager and then try to use it while still having the documentation in sight.
  2. git log works this way by default so I'm not sure about your comment about git (see man git-config).

We could perhaps carry on the value of the LESS variable if the user defined it (like git does). That would allow you to use the LESS value you'd want. But I'm a bit vary and not very enthusiastic of changing things in this area. The whole groff and paging business is extremely fragile and I can already see more people coming here complaining that their help is garbled because they have a LESS variable set without the R.

@muzimuzhi
Copy link
Author

muzimuzhi commented Sep 8, 2024

I just realized PAGER=less LESS=-R is set by oh-my-zsh by default, which I haven't thought about why and already taken as granted.

The whole groff and paging business is extremely fragile and I can already see more people coming here complaining that their help is garbled because they have a LESS variable set without the R.

Understandable. Maintaining backwards compatibility is hard.

BTW what's inconvenient for me is that, in the file opened by less, it's possible to scroll lines using mouse wheel, but not if it's opened by less -X, in both macOS terminal.app and iTerm2. Maybe this is configurable in these terminal emulators.

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

No branches or pull requests

2 participants