Skip to content

Commit

Permalink
added extunix specific ttyname
Browse files Browse the repository at this point in the history
  • Loading branch information
yokurang committed Jul 1, 2024
1 parent 3d8ea6b commit 03e1995
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(executable
(public_name diffcessible)
(name main)
(libraries diffcessible cmdliner patch))
(libraries diffcessible cmdliner patch extunix))
18 changes: 12 additions & 6 deletions bin/main.ml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
open Diffcessible
open Cmdliner
open ExtUnix.Specific

let main file_path =
let file = In_channel.open_bin file_path in
let s = In_channel.input_all file in
let patch = Patch.to_diffs s in
let file = match file_path with
| Some path -> In_channel.open_bin path
| None ->
let tty = ttyname Unix.stdin
in In_channel.open_bin tty
in let s = In_channel.input_all file
in let patch = Patch.to_diffs s in
Interactive_viewer.start patch

let file_arg =
let doc = "Path to the file containing the Git diff." in
Arg.(required & pos 0 (some string) None & info [] ~docv:"FILE" ~doc)
let doc = "Path to the file containing the Git diff. If not provided, reads from the terminal." in
Arg.(value & pos 0 (some string) None & info [] ~docv:"FILE" ~doc)

let cmd =
let doc = "Render Git diffs in an accessible way." in
let doc = "Render Git diffs in an accessible way. Acts as a pager if no file is provided." in
let info = Cmd.info "diffcessible" ~version:"VERSION" ~doc in
Cmd.v info Term.(const main $ file_arg)

let () = exit (Cmd.eval cmd)

1 change: 1 addition & 0 deletions diffcessible.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ depends: [
"dune" {>= "3.11"}
"cmdliner"
"seq"
"extunix"
"notty" {>= "0.2"}
"odoc" {with-doc}
]
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
dune
cmdliner
seq
extunix
(notty
(>= 0.2)))
(tags
Expand Down

0 comments on commit 03e1995

Please sign in to comment.