Change interface to accept arrow string with '-a' instead of arrow length
This commit is contained in:
parent
1dfbace040
commit
1fa8a0fa8b
11
README.md
11
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
|
## Installation
|
||||||
|
|
||||||
|
|||||||
12
bin/main.ml
12
bin/main.ml
@ -2,7 +2,7 @@ open Boks
|
|||||||
|
|
||||||
let usage_msg = "boks -p <padding size> -a <arrow size> <text1> [<text2>] ..."
|
let usage_msg = "boks -p <padding size> -a <arrow size> <text1> [<text2>] ..."
|
||||||
let padlen = ref 3
|
let padlen = ref 3
|
||||||
let arrowlen = ref 3
|
let arrow = ref "<--->"
|
||||||
let texts = ref []
|
let texts = ref []
|
||||||
|
|
||||||
let accept_text t =
|
let accept_text t =
|
||||||
@ -10,12 +10,14 @@ let accept_text t =
|
|||||||
|
|
||||||
let speclist = [
|
let speclist = [
|
||||||
("-p", Arg.Set_int padlen, "Padding size");
|
("-p", Arg.Set_int padlen, "Padding size");
|
||||||
("-a", Arg.Set_int arrowlen, "Arrow size");
|
("-a", Arg.Set_string arrow, "Arrow");
|
||||||
]
|
]
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Arg.parse speclist accept_text usage_msg;
|
Arg.parse speclist accept_text usage_msg;
|
||||||
let padlen = !padlen in
|
let padlen = !padlen in
|
||||||
let arrowlen = !arrowlen in
|
let arrow = !arrow in
|
||||||
let texts = !texts in
|
let texts =
|
||||||
boks ~padlen ~arrowlen texts
|
if List.is_empty !texts then ["moo"] else !texts
|
||||||
|
in
|
||||||
|
boks ~padlen ~arrow texts
|
||||||
|
|||||||
20
boks.opam
20
boks.opam
@ -1,14 +1,14 @@
|
|||||||
# This file is generated by dune, edit dune-project instead
|
# This file is generated by dune, edit dune-project instead
|
||||||
opam-version: "2.0"
|
opam-version: "2.0"
|
||||||
synopsis: "A short synopsis"
|
synopsis: "Box maker in OCaml"
|
||||||
description: "A longer description"
|
description: "CLI tool to make boxes with text in OCaml"
|
||||||
maintainer: ["Maintainer Name"]
|
maintainer: ["Kaustubh M"]
|
||||||
authors: ["Author Name"]
|
authors: ["Kaustubh M"]
|
||||||
license: "LICENSE"
|
license: "MIT"
|
||||||
tags: ["topics" "to describe" "your" "project"]
|
tags: ["cli"]
|
||||||
homepage: "https://github.com/username/reponame"
|
homepage: "https://github.com/nikochiko/boks"
|
||||||
doc: "https://url/to/documentation"
|
doc: "https://git.kaustubh.page/kaustubh/boks"
|
||||||
bug-reports: "https://github.com/username/reponame/issues"
|
bug-reports: "https://github.com/nikochiko/boks/issues"
|
||||||
depends: [
|
depends: [
|
||||||
"ocaml"
|
"ocaml"
|
||||||
"dune" {>= "3.13"}
|
"dune" {>= "3.13"}
|
||||||
@ -28,4 +28,4 @@ build: [
|
|||||||
"@doc" {with-doc}
|
"@doc" {with-doc}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
dev-repo: "git+https://github.com/username/reponame.git"
|
dev-repo: "git+https://github.com/nikochiko/boks.git"
|
||||||
|
|||||||
@ -20,4 +20,4 @@
|
|||||||
(synopsis "Box maker in OCaml")
|
(synopsis "Box maker in OCaml")
|
||||||
(description "CLI tool to make boxes with text in OCaml")
|
(description "CLI tool to make boxes with text in OCaml")
|
||||||
(depends ocaml dune)
|
(depends ocaml dune)
|
||||||
(tags "cli"))
|
(tags ("cli")))
|
||||||
|
|||||||
10
lib/boks.ml
10
lib/boks.ml
@ -5,18 +5,14 @@ let bok_core padlen text =
|
|||||||
let padding = String.make padlen ' ' in
|
let padding = String.make padlen ' ' in
|
||||||
Printf.sprintf "|%s%s%s|" padding text padding
|
Printf.sprintf "|%s%s%s|" padding text padding
|
||||||
|
|
||||||
let arrow len =
|
let boks ~padlen ~arrow texts =
|
||||||
Printf.sprintf "<%s>" (String.make len '-')
|
let conn_space = String.make (String.length arrow) ' ' in
|
||||||
|
|
||||||
let boks ?(padlen=3) ?(arrowlen=3) texts =
|
|
||||||
let conn = arrow arrowlen in
|
|
||||||
let conn_space = String.make (String.length conn) ' ' in
|
|
||||||
let boks_edge = String.concat
|
let boks_edge = String.concat
|
||||||
conn_space
|
conn_space
|
||||||
(List.map (bok_edge padlen) texts)
|
(List.map (bok_edge padlen) texts)
|
||||||
in
|
in
|
||||||
let boks_core = String.concat
|
let boks_core = String.concat
|
||||||
conn
|
arrow
|
||||||
(List.map (bok_core padlen) texts)
|
(List.map (bok_core padlen) texts)
|
||||||
in
|
in
|
||||||
Printf.printf "%s\n%s\n%s\n" boks_edge boks_core boks_edge
|
Printf.printf "%s\n%s\n%s\n" boks_edge boks_core boks_edge
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
val boks : ?padlen:int -> ?arrowlen:int -> string list -> unit
|
val boks : padlen:int -> arrow:string -> string list -> unit
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user