diff --git a/bin/dune b/bin/dune index fd7f225..eb17a65 100644 --- a/bin/dune +++ b/bin/dune @@ -1,4 +1,4 @@ (executable (public_name diffcessible) (name main) - (libraries diffcessible cmdliner patch)) + (libraries diffcessible cmdliner patch extunix)) diff --git a/bin/main.ml b/bin/main.ml index 13d2ba8..030f002 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -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) + diff --git a/diffcessible.opam b/diffcessible.opam index 05ee17b..548139b 100644 --- a/diffcessible.opam +++ b/diffcessible.opam @@ -13,6 +13,7 @@ depends: [ "dune" {>= "3.11"} "cmdliner" "seq" + "extunix" "notty" {>= "0.2"} "odoc" {with-doc} ] diff --git a/dune-project b/dune-project index f228c76..4c8f34e 100644 --- a/dune-project +++ b/dune-project @@ -23,6 +23,7 @@ dune cmdliner seq + extunix (notty (>= 0.2))) (tags