Change interface to accept arrow string with '-a' instead of arrow length

This commit is contained in:
Kaustubh Maske Patil 2024-07-20 15:26:55 +05:30
parent 1dfbace040
commit 1fa8a0fa8b
6 changed files with 32 additions and 25 deletions

View File

@ -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

View File

@ -2,7 +2,7 @@ open Boks
let usage_msg = "boks -p <padding size> -a <arrow size> <text1> [<text2>] ..."
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

View File

@ -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"

View File

@ -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")))

View File

@ -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

View File

@ -1 +1 @@
val boks : ?padlen:int -> ?arrowlen:int -> string list -> unit
val boks : padlen:int -> arrow:string -> string list -> unit