Skip to content

Commit c3f9cd3

Browse files
committed
Various fixes.
The Makefile in particular has been reworked (see README for details).
1 parent d76f45a commit c3f9cd3

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

Makefile

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
OCAMLC = ocamlc
22
OCAMLOPT = ocamlopt
33

4-
AR = ocamlmklib
4+
INTERFACES = pretty_types.cmi pretty.cmi
5+
OPT_IMPLS = pretty.cmx
6+
BYTE_IMPLS = pretty.cmo
57

6-
INTERFACES = pretty_types.mli pretty.mli
7-
IMPLEMENTATIONS = pretty.ml
8+
%.cmi: %.mli
9+
$(OCAMLC) -o $@ -c $<
810

9-
pretty: $(INTERFACES) $(IMPLEMENTATIONS)
10-
$(AR) -o $@ $^
11+
%.cmo: %.ml
12+
$(OCAMLC) -o $@ -c $<
13+
14+
%.cmx: %.ml
15+
$(OCAMLOPT) -o $@ -c $<
16+
17+
byte: $(INTERFACES) $(BYTE_IMPLS)
18+
$(OCAMLC) -a -o pretty.cma unix.cma $(BYTE_IMPLS)
19+
20+
opt: $(INTERFACES) $(OPT_IMPLS)
21+
$(OCAMLOPT) -a -o pretty.cmxa unix.cmxa $(OPT_IMPLS)
1122

1223
clean:
1324
rm -f *.{a,cm*,o,out}

README

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ Supports the following functionality:
66
- Clearing/erasing text;
77
- Text attributes/colours.
88

9+
Changes: 2012/07/19
10+
- Fixed Makefile;
11+
- Changed interface for Pretty.noecho_aux.
12+
13+
Changes: 2012/07/18
14+
- No-echo utility functions;
15+
- Required dependency: unix module;
16+
- Turned off dynamic loading in Makefile.
17+
918
More features to come!
1019

1120
For reference of ANSI/VT100 see: http://www.termsys.demon.co.uk/vtansi.htm

pretty.ml

+13
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,16 @@ let print_string ?(attrs = []) ?(x = -1) ?(y = -1) str =
135135
in print_string ("\027[" ^ y ^ ";" ^ x ^ "H"));
136136

137137
print_string_attrs ~attrs:attrs str
138+
139+
let noecho_aux fd f =
140+
let open Unix in
141+
let attrs = tcgetattr stdin in
142+
tcsetattr fd TCSANOW { attrs with c_echo = false };
143+
let ret = try f fd with
144+
| ex -> tcsetattr fd TCSANOW attrs; raise ex
145+
in
146+
tcsetattr fd TCSANOW attrs; ret
147+
148+
let noecho_read_line () = noecho_aux Unix.stdin (fun fd -> read_line ())
149+
let noecho_read_int () = noecho_aux Unix.stdin (fun fd -> read_int ())
150+
let noecho_read_float () = noecho_aux Unix.stdin (fun fd -> read_float ())

pretty.mli

+10
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,13 @@ val print_custom : attribute list -> unit
7979
* Supports printing text with decorative attributes applied.
8080
*)
8181
val print_string : ?attrs:attribute list -> ?x:int -> ?y:int -> string -> unit
82+
83+
(* Turn of echoing whilst reading input.
84+
*
85+
* NOTE:
86+
* Restores echoing after completion.
87+
*)
88+
val noecho_aux : Unix.file_descr -> (Unix.file_descr -> 'a) -> 'a
89+
val noecho_read_line : unit -> string
90+
val noecho_read_int : unit -> int
91+
val noecho_read_float : unit -> float

0 commit comments

Comments
 (0)