add doc comments. replace render-out with render-to-string
This commit is contained in:
parent
b9e30d0f22
commit
2f332a6ee5
|
@ -62,7 +62,10 @@
|
||||||
charmap))
|
charmap))
|
||||||
{})))
|
{})))
|
||||||
|
|
||||||
(defn load-flf [file]
|
(defn load-flf
|
||||||
|
"Loads a FIGlet font from a file, returning the data needed to render text with it as a map.
|
||||||
|
This map can be passed to one of the render functions as the flf argument."
|
||||||
|
[file]
|
||||||
(let [flf-file (slurp file)]
|
(let [flf-file (slurp file)]
|
||||||
(if-not (= "flf2a" (subs flf-file 0 5))
|
(if-not (= "flf2a" (subs flf-file 0 5))
|
||||||
(throw (new Exception (str "Not a valid flf font file: " file))))
|
(throw (new Exception (str "Not a valid flf font file: " file))))
|
||||||
|
@ -91,7 +94,12 @@
|
||||||
(defn- get-initial-output-lines [flf]
|
(defn- get-initial-output-lines [flf]
|
||||||
(take (get-in flf [:header :height]) (repeat "")))
|
(take (get-in flf [:header :height]) (repeat "")))
|
||||||
|
|
||||||
(defn render-char [^Character c flf & [initial-output]]
|
(defn render-char
|
||||||
|
"Renders a single character using the given FIGlet font. A new sequence of strings
|
||||||
|
representing the rendered output lines is returned, or if initial-output is provided,
|
||||||
|
that set of lines will be appended to and returned. If initial-output is specified,
|
||||||
|
that collection should have the same size as the flf font height."
|
||||||
|
[^Character c flf & [initial-output]]
|
||||||
(let [output-lines (or initial-output (get-initial-output-lines flf))
|
(let [output-lines (or initial-output (get-initial-output-lines flf))
|
||||||
char-lines (get-in flf [:chars c])
|
char-lines (get-in flf [:chars c])
|
||||||
hardblank (get-in flf [:header :hardblank-str])]
|
hardblank (get-in flf [:header :hardblank-str])]
|
||||||
|
@ -107,7 +115,14 @@
|
||||||
output-lines)
|
output-lines)
|
||||||
output-lines)))
|
output-lines)))
|
||||||
|
|
||||||
(defn render-line [^String s flf & [initial-output]]
|
(defn render-line
|
||||||
|
"Renders a single line of text using the given FIGlet font. A new sequence of strings
|
||||||
|
representing the rendered output lines is returned, or if initial-output is provided,
|
||||||
|
that set of lines will be appended to and returned. If initial-output is specified,
|
||||||
|
that collection should have the same size as the flf font height. Any characters
|
||||||
|
not present in the flf font are ignored, except for tab characters which are rendered
|
||||||
|
as 8 space characters."
|
||||||
|
[^String s flf & [initial-output]]
|
||||||
(let [output (or initial-output (get-initial-output-lines flf))]
|
(let [output (or initial-output (get-initial-output-lines flf))]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [out c]
|
(fn [out c]
|
||||||
|
@ -117,14 +132,20 @@
|
||||||
output
|
output
|
||||||
s)))
|
s)))
|
||||||
|
|
||||||
(defn render [^String s flf]
|
(defn render
|
||||||
|
"Renders a string of text using the given FIGlet font. The rendered output is returned
|
||||||
|
as a sequence of lines. The text given is split up on each newline character found and
|
||||||
|
each line is rendered as a new line in the output. So the number of lines in the final
|
||||||
|
rendered output will be equal to [number of lines in 's'] * [height of flf font]"
|
||||||
|
[^String s flf]
|
||||||
(->> (str/split s #"\n")
|
(->> (str/split s #"\n")
|
||||||
(map #(render-line % flf))
|
(map #(render-line % flf))
|
||||||
(apply concat)))
|
(apply concat)))
|
||||||
|
|
||||||
(defn render-out [flf & more]
|
(defn render-to-string
|
||||||
(let [s (str/join " " more)
|
"Renders a string of text using the given FIGlet font. The rendered output is returned
|
||||||
lines (render s flf)]
|
as a single string which is created by concatenating each line of output from rendering
|
||||||
(->> lines
|
the same string using clj-figlet.core/render."
|
||||||
(str/join \newline)
|
[^String s flf]
|
||||||
(clojure.core/print))))
|
(->> (render s flf)
|
||||||
|
(str/join \newline)))
|
Loading…
Reference in a new issue