Skip to content

Commit

Permalink
Fix manpage paging on Windows (dbuenzli#166).
Browse files Browse the repository at this point in the history
  • Loading branch information
dbuenzli authored and emillon committed Sep 25, 2023
1 parent 795391a commit e5e45c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Thanks to Michael Richards and Reynir Björnsson for the report (#176).
- Fix install to directory with spaces (#172). Thanks to
@ZSFactory for reporting and suggesting the fix.
- Fix manpage paging on Windows (#166). Thanks to Nicolás Ojeda Bär
for the report and the solution.

v1.1.1 2022-03-23 La Forclaz (VS)
---------------------------------
Expand Down
20 changes: 19 additions & 1 deletion src/cmdliner_manpage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ let pp_to_temp_file pp_v v =
Some file
with Sys_error _ -> None

let tmp_file_for_pager () =
try
let exec = Filename.basename Sys.argv.(0) in
let file = Filename.temp_file exec "tty" in
at_exit (fun () -> try Sys.remove file with Sys_error e -> ());
Some file
with Sys_error _ -> None

let find_cmd cmds =
let test, null = match Sys.os_type with
| "Win32" -> "where", " NUL"
Expand Down Expand Up @@ -476,7 +484,17 @@ let pp_to_pager print ppf v =
let groffer = groffer ^ opts in
begin match pp_to_temp_file (print `Groff) v with
| None -> None
| Some f -> Some (strf "%s < %s | %s" groffer f pager)
| Some f when Sys.win32 ->
(* For some obscure reason the pipe below does not
work. We need to use a temporary file.
https://github.com/dbuenzli/cmdliner/issues/166 *)
begin match tmp_file_for_pager () with
| None -> None
| Some tmp ->
Some (strf "%s <%s >%s %s <%s" groffer f tmp pager tmp)
end
| Some f ->
Some (strf "%s < %s | %s" groffer f pager)
end
in
match cmd with
Expand Down

0 comments on commit e5e45c3

Please sign in to comment.