Skip to content

Commit ed67db2

Browse files
authored
Merge pull request #1 from mbarbin/add-styles
Add styles
2 parents f6fa969 + a1fb7df commit ed67db2

16 files changed

+181
-45
lines changed

.github/workflows/deploy-odoc.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: deploy-odoc
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
# Review gh actions docs if you want to further define triggers, paths, etc
8+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9+
10+
jobs:
11+
build:
12+
name: Build OCaml Doc
13+
runs-on: ubuntu-latest
14+
defaults:
15+
run:
16+
shell: bash
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Setup OCaml
24+
uses: ocaml/setup-ocaml@v3
25+
with:
26+
ocaml-compiler: "5.3.x"
27+
opam-repositories: |
28+
default: https://github.com/ocaml/opam-repository.git
29+
mbarbin: https://github.com/mbarbin/opam-repository.git
30+
# janestreet-bleeding: https://github.com/janestreet/opam-repository.git
31+
# janestreet-bleeding-external: https://github.com/janestreet/opam-repository.git#external-packages
32+
33+
- name: Install OCaml Dependencies
34+
run: opam install . --deps-only --with-doc
35+
36+
- name: Build Odoc Pages
37+
run: opam exec -- dune build @doc
38+
39+
- name: Upload Build Artifact
40+
uses: actions/upload-pages-artifact@v3
41+
with:
42+
path: _build/default/_doc/_html
43+
44+
deploy:
45+
name: Deploy to GitHub Pages
46+
needs: build
47+
48+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
49+
permissions:
50+
pages: write # to deploy to Pages
51+
id-token: write # to verify the deployment originates from an appropriate source
52+
53+
# Deploy to the github-pages environment
54+
environment:
55+
name: github-pages
56+
url: ${{ steps.deployment.outputs.page_url }}
57+
58+
runs-on: ubuntu-latest
59+
defaults:
60+
run:
61+
shell: bash
62+
# working-directory: ./doc
63+
steps:
64+
- name: Deploy to GitHub Pages
65+
id: deployment
66+
uses: actions/deploy-pages@v4

.headache.dirs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# Add new directories below. Lines starting with '#' are ignored.
33
lib/print_table/src
44
lib/print_table/test
5+
lib/print_table/test/bin

.vscode/settings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"cSpell.words": [
33
"janestreet",
44
"odoc",
5-
"opam"
5+
"opam",
6+
"printbox",
7+
"Uchar",
8+
"Uutf"
69
]
7-
}
10+
}

lib/print_table/src/box.ml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,22 @@ let of_print_table (Print_table_ast.T { columns; rows }) =
3636
{ columns }
3737
;;
3838

39-
let pad s ~len ~align =
40-
let slen = String.length s in
39+
let pad ?ansi_code text ~len ~align =
40+
let slen = String.length text in
41+
let text =
42+
match ansi_code with
43+
| None -> text
44+
| Some ansi_code -> Printf.sprintf "\027[%dm%s\027[0m" ansi_code text
45+
in
4146
if slen >= len
42-
then s
47+
then text
4348
else (
4449
let pad = String.make (len - slen) ' ' in
4550
match (align : Print_table_ast.Align.t) with
46-
| Left -> s ^ pad
47-
| Right -> pad ^ s
51+
| Left -> text ^ pad
52+
| Right -> pad ^ text
4853
| Center ->
4954
let left = (len - slen) / 2 in
5055
let right = len - slen - left in
51-
String.make left ' ' ^ s ^ String.make right ' ')
56+
String.make left ' ' ^ text ^ String.make right ' ')
5257
;;

lib/print_table/src/box.mli

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ val of_print_table : Print_table_ast.t -> t
2929

3030
(** [pad input ~len ~align] returns a new string with spaces either to the left,
3131
right or both so that it contains the original string at the specified
32-
alignment. For example [pad "hello" 10 ~align:Right] is equivalent to
33-
[String.make 5 ' ' ^ "hello"]. *)
34-
val pad : string -> len:int -> align:Print_table_ast.Align.t -> string
32+
alignment. For example [pad "hello" ~len:10 ~align:Right] is equivalent to
33+
[String.make 5 ' ' ^ "hello"]. [ansi_code] may be supplied to surround the
34+
input text by ansi codes. *)
35+
val pad : ?ansi_code:int -> string -> len:int -> align:Print_table_ast.Align.t -> string

lib/print_table/src/print_table.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module Style = struct
1616
let fg_green = Fg_green
1717
let fg_red = Fg_red
1818
let fg_yellow = Fg_yellow
19+
let dim = Dim
20+
let underscore = Underscore
1921
end
2022

2123
module Cell = struct

lib/print_table/src/print_table.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ module Style : sig
6969
val fg_green : t
7070
val fg_red : t
7171
val fg_yellow : t
72+
val dim : t
73+
val underscore : t
7274
end
7375

7476
module Cell : sig
@@ -100,7 +102,7 @@ module Column : sig
100102
['row] value represents an individual row in the table. *)
101103
type 'row t
102104

103-
(** [make ~header ?aligh f] declares a new column with [header]. The alignment
105+
(** [make ~header ?align f] declares a new column with [header]. The alignment
104106
defaults to [Left]. [f] is the function that should take care and
105107
encapsulate the knowledge of how the contents for this [column] is
106108
extracted and created for a given [row]. It is not immediately called but

lib/print_table/src/print_table_ast.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module Style = struct
1010
| Fg_green
1111
| Fg_red
1212
| Fg_yellow
13+
| Dim
14+
| Underscore
1315
end
1416

1517
module Cell = struct

lib/print_table/src/print_table_ast.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module Style : sig
1515
| Fg_green
1616
| Fg_red
1717
| Fg_yellow
18+
| Dim
19+
| Underscore
1820
end
1921

2022
module Cell : sig

lib/print_table/src/print_table_markdown.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let to_string_non_empty t =
4646
let { Print_table_ast.Cell.text; style } = cells.(i) in
4747
let () =
4848
match style with
49-
| Default | Fg_green | Fg_red | Fg_yellow ->
49+
| Default | Fg_green | Fg_red | Fg_yellow | Dim | Underscore ->
5050
(* There is no support for controlling colors in the GitHub Markdown
5151
syntax. We simply do not render them. *)
5252
()

0 commit comments

Comments
 (0)