commit 0c6fd957dd9d90f28e3670d683d5d9c03b02e643 Author: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Sat Jul 20 03:37:17 2024 +0530 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e72c16 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +*.annot +*.cmo +*.cma +*.cmi +*.a +*.o +*.cmx +*.cmxs +*.cmxa + +# ocamlbuild working directory +_build/ + +# ocamlbuild targets +*.byte +*.native + +# oasis generated files +setup.data +setup.log + +# Merlin configuring file for Vim and Emacs +.merlin + +# Dune generated files +*.install + +# Local OPAM switch +_opam/ + +.DS_Store diff --git a/bin/dune b/bin/dune new file mode 100644 index 0000000..f9d7d88 --- /dev/null +++ b/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name boks) + (name main) + (libraries boks)) diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..121676d --- /dev/null +++ b/bin/main.ml @@ -0,0 +1,21 @@ +open Boks + +let usage_msg = "boks -p -a [] ..." +let padlen = ref 3 +let arrowlen = ref 3 +let texts = ref [] + +let accept_text t = + texts := !texts @ [t] + +let speclist = [ + ("-p", Arg.Set_int padlen, "Padding size"); + ("-a", Arg.Set_int arrowlen, "Arrow size"); +] + +let () = + Arg.parse speclist accept_text usage_msg; + let padlen = !padlen in + let arrowlen = !arrowlen in + let texts = !texts in + boks ~padlen ~arrowlen texts diff --git a/boks.opam b/boks.opam new file mode 100644 index 0000000..3b957d2 --- /dev/null +++ b/boks.opam @@ -0,0 +1,31 @@ +# 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" +depends: [ + "ocaml" + "dune" {>= "3.13"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..a923e21 --- /dev/null +++ b/dune-project @@ -0,0 +1,26 @@ +(lang dune 3.13) + +(name boks) + +(generate_opam_files true) + +(source + (github username/reponame)) + +(authors "Author Name") + +(maintainers "Maintainer Name") + +(license LICENSE) + +(documentation https://url/to/documentation) + +(package + (name boks) + (synopsis "A short synopsis") + (description "A longer description") + (depends ocaml dune) + (tags + (topics "to describe" your project))) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/lib/boks.ml b/lib/boks.ml new file mode 100644 index 0000000..9cd6935 --- /dev/null +++ b/lib/boks.ml @@ -0,0 +1,22 @@ +let bok_edge padlen text = + Printf.sprintf "+%s+" (String.make (String.length text + 2 * padlen) '-') + +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_edge = String.concat + conn_space + (List.map (bok_edge padlen) texts) + in + let boks_core = String.concat + conn + (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 new file mode 100644 index 0000000..d6fa2da --- /dev/null +++ b/lib/boks.mli @@ -0,0 +1 @@ +val boks : ?padlen:int -> ?arrowlen:int -> string list -> unit diff --git a/lib/dune b/lib/dune new file mode 100644 index 0000000..169fad3 --- /dev/null +++ b/lib/dune @@ -0,0 +1,3 @@ +(library + (name boks) + (modules boks)) diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..1d5d2e3 --- /dev/null +++ b/test/dune @@ -0,0 +1,2 @@ +(test + (name test_boks)) diff --git a/test/test_boks.ml b/test/test_boks.ml new file mode 100644 index 0000000..e69de29