Skip to content

Commit 84403bc

Browse files
authored
Rewrite the TUI framework (#13)
* Rewrite MintTea to custom TUI implementation * Implement proper setup and shutdown * Add logger, switch to async reader * Fix quit from the model * Install libcurl on CI
1 parent 51de590 commit 84403bc

File tree

27 files changed

+295
-64
lines changed

27 files changed

+295
-64
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ jobs:
1515
os:
1616
- ubuntu-latest
1717
ocaml-compiler:
18-
- 5.1.1
18+
- 5.2.1
1919

2020
steps:
2121
- name: Checkout code
2222
uses: actions/checkout@v3
2323

24+
- name: Install libcurl development package
25+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
26+
2427
- name: Use OCaml ${{ matrix.ocaml-compiler }}
2528
uses: ocaml/setup-ocaml@v2
2629
with:
@@ -38,10 +41,13 @@ jobs:
3841
- name: Checkout code
3942
uses: actions/checkout@v3
4043

41-
- name: Use OCaml 5.1.1
44+
- name: Install libcurl development package
45+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
46+
47+
- name: Setup OCaml
4248
uses: ocaml/setup-ocaml@v2
4349
with:
44-
ocaml-compiler: 5.1.1
50+
ocaml-compiler: 5.2.1
4551
dune-cache: true
4652

4753
- name: Lint doc
@@ -53,10 +59,13 @@ jobs:
5359
- name: Checkout code
5460
uses: actions/checkout@v3
5561

56-
- name: Use OCaml 5.1.1
62+
- name: Install libcurl development package
63+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
64+
65+
- name: Setup OCaml
5766
uses: ocaml/setup-ocaml@v2
5867
with:
59-
ocaml-compiler: 5.1.1
68+
ocaml-compiler: 5.2.1
6069
dune-cache: true
6170

6271
- name: Lint fmt

.ocamlformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 0.26.2
1+
version = 0.27.0
22
profile = default
33
break-cases = fit-or-vertical
44
break-infix = wrap-or-vertical

dune-project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
(minttea (>= "0.0.2"))
2626
shape-the-term
2727
(terminal_size (>= "0.2.0"))
28+
(tty (>= "0.0.2"))
29+
(uutf (>= "1.0.3"))
2830
)
2931
(tags
3032
(tui cli git github)))

github_tui.opam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ depends: [
1717
"minttea" {>= "0.0.2"}
1818
"shape-the-term"
1919
"terminal_size" {>= "0.2.0"}
20+
"tty" {>= "0.0.2"}
21+
"uutf" {>= "1.0.3"}
2022
"odoc" {with-doc}
2123
]
2224
build: [
@@ -35,6 +37,5 @@ build: [
3537
]
3638
dev-repo: "git+https://github.com/chshersh/github-tui.git"
3739
pin-depends: [
38-
["minttea.dev" "git+https://github.com/chshersh/minttea"]
3940
["shape-the-term.dev" "git+https://github.com/jmcavanillas/shape-the-term"]
4041
]

github_tui.opam.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pin-depends: [
2-
["minttea.dev" "git+https://github.com/chshersh/minttea"]
32
["shape-the-term.dev" "git+https://github.com/jmcavanillas/shape-the-term"]
43
]

lib/cli.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ let path_arg =
1111
& opt (some string) None
1212
& info [ "d"; "directory" ] ~docv:"DIRECTORY_PATH" ~doc)
1313

14-
let run repo local_path = Tui.start ~repo ~local_path
15-
let gh_tui_term = Term.(const run $ repo_arg $ path_arg)
14+
let log_arg =
15+
let doc = "Log debug information to the given file" in
16+
Arg.(
17+
value
18+
& opt (some string) None
19+
& info [ "l"; "log-to" ] ~docv:"LOG_PATH" ~doc)
20+
21+
let run repo local_path log_file = Tui.start ~repo ~local_path ~log_file
22+
let gh_tui_term = Term.(const run $ repo_arg $ path_arg $ log_arg)
1623

1724
let cmd =
1825
let doc = "TUI of a GitHub repository" in

lib/fs/fs.mli

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(** File contents as an array of lines, where each line is wrapped into a document (for rendering efficiency) *)
1+
(** File contents as an array of lines, where each line is wrapped into a
2+
document (for rendering efficiency) *)
23
type file_contents = {
34
lines : Pretty.doc array;
45
offset : int;
@@ -46,7 +47,8 @@ val go_down : zipper -> zipper
4647
(** Move to the previous file within the same directory. Cycles. *)
4748
val go_up : zipper -> zipper
4849

49-
(** Move to the directory under the current cursor. Doesn't move inside files or empty directories. *)
50+
(** Move to the directory under the current cursor. Doesn't move inside files or
51+
empty directories. *)
5052
val go_next : zipper -> zipper
5153

5254
(** Move to the parent directory. *)

lib/log/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(library
2+
(name log)
3+
(libraries unix))

lib/log/log.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let log ~path ~tag ~msg =
2+
match path with
3+
| None -> ()
4+
| Some path ->
5+
let now = Unix.gettimeofday () in
6+
let str = Printf.sprintf "timestamp=%f tag=%s msg=%s\n" now tag msg in
7+
Out_channel.(
8+
with_open_gen [ Open_creat; Open_append; Open_binary ] 0o644 path
9+
(fun channel -> output_string channel str))

lib/log/log.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(** Log a single line in the following format to the given file if passed.
2+
3+
{v
4+
timestamp=1447865947.56802297 tag=event msg=Retry
5+
v} *)
6+
val log : path:string option -> tag:string -> msg:string -> unit

0 commit comments

Comments
 (0)