diff --git a/README.md b/README.md index 27f2ad9..28840bb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,16 @@ $ boks apps dbms data +----------+ +----------+ +----------+ ``` -Use `-a` to customize length of arrows, `-p` to customize padding. +Use `-a` to customize arrow style, `-p` to customize padding length. + +e.g. + +```shell +$ boks -a '--->' 'declarative query' 'optimized plan' ++-----------------------+ +--------------------+ +| declarative query |--->| optimized plan | ++-----------------------+ +--------------------+ +``` ## Installation diff --git a/bin/main.ml b/bin/main.ml index 121676d..6411e9d 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -2,7 +2,7 @@ open Boks let usage_msg = "boks -p -a [] ..." let padlen = ref 3 -let arrowlen = ref 3 +let arrow = ref "<--->" let texts = ref [] let accept_text t = @@ -10,12 +10,14 @@ let accept_text t = let speclist = [ ("-p", Arg.Set_int padlen, "Padding size"); - ("-a", Arg.Set_int arrowlen, "Arrow size"); + ("-a", Arg.Set_string arrow, "Arrow"); ] let () = Arg.parse speclist accept_text usage_msg; let padlen = !padlen in - let arrowlen = !arrowlen in - let texts = !texts in - boks ~padlen ~arrowlen texts + let arrow = !arrow in + let texts = + if List.is_empty !texts then ["moo"] else !texts + in + boks ~padlen ~arrow texts diff --git a/boks.opam b/boks.opam index 3b957d2..2f372e6 100644 --- a/boks.opam +++ b/boks.opam @@ -1,14 +1,14 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -synopsis: "A short synopsis" -description: "A longer description" -maintainer: ["Maintainer Name"] -authors: ["Author Name"] -license: "LICENSE" -tags: ["topics" "to describe" "your" "project"] -homepage: "https://github.com/username/reponame" -doc: "https://url/to/documentation" -bug-reports: "https://github.com/username/reponame/issues" +synopsis: "Box maker in OCaml" +description: "CLI tool to make boxes with text in OCaml" +maintainer: ["Kaustubh M"] +authors: ["Kaustubh M"] +license: "MIT" +tags: ["cli"] +homepage: "https://github.com/nikochiko/boks" +doc: "https://git.kaustubh.page/kaustubh/boks" +bug-reports: "https://github.com/nikochiko/boks/issues" depends: [ "ocaml" "dune" {>= "3.13"} @@ -28,4 +28,4 @@ build: [ "@doc" {with-doc} ] ] -dev-repo: "git+https://github.com/username/reponame.git" +dev-repo: "git+https://github.com/nikochiko/boks.git" diff --git a/dune-project b/dune-project index d5b41fd..c8038b6 100644 --- a/dune-project +++ b/dune-project @@ -20,4 +20,4 @@ (synopsis "Box maker in OCaml") (description "CLI tool to make boxes with text in OCaml") (depends ocaml dune) - (tags "cli")) + (tags ("cli"))) diff --git a/lib/boks.ml b/lib/boks.ml index 9cd6935..60e8ed7 100644 --- a/lib/boks.ml +++ b/lib/boks.ml @@ -5,18 +5,14 @@ let bok_core padlen text = let padding = String.make padlen ' ' in Printf.sprintf "|%s%s%s|" padding text padding -let arrow len = - Printf.sprintf "<%s>" (String.make len '-') - -let boks ?(padlen=3) ?(arrowlen=3) texts = - let conn = arrow arrowlen in - let conn_space = String.make (String.length conn) ' ' in +let boks ~padlen ~arrow texts = + let conn_space = String.make (String.length arrow) ' ' in let boks_edge = String.concat conn_space (List.map (bok_edge padlen) texts) in let boks_core = String.concat - conn + arrow (List.map (bok_core padlen) texts) in Printf.printf "%s\n%s\n%s\n" boks_edge boks_core boks_edge diff --git a/lib/boks.mli b/lib/boks.mli index d6fa2da..0726e78 100644 --- a/lib/boks.mli +++ b/lib/boks.mli @@ -1 +1 @@ -val boks : ?padlen:int -> ?arrowlen:int -> string list -> unit +val boks : padlen:int -> arrow:string -> string list -> unit