Open crinklywrappr opened 2 years ago
As an exercise, I applied some post-processing to fonts -v
so that I could query it with recutils'.
Here is a snippet of the output
/home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Cyan-Blu
char list:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
font: Use Green
char list:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄
font: Use Purple
char list:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄
font: Use Red
char list:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄
font: Use Silver
char list:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄
/home/crinklywrappr//.config/tdfgo/fonts/SECTOR.TDF
font: Sector
char list:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 14 height: 8 spacing: 1
preview: ▄▄▄▄▄▄▄▄▄▄▄▄
/home/crinklywrappr//.config/tdfgo/fonts/PANDEMON.TDF
font:
char list:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 10 height: 12 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
/home/crinklywrappr//.config/tdfgo/fonts/CALVIN.TDF
/home/crinklywrappr//.config/tdfgo/fonts/CATLKINX.TDF
font: CattleKingB
char list:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 7 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
In order for recutils to read it, it needs to look like this:
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Cyan-Blu
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Green
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Purple
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Red
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Silver
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 6 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄
file: /home/crinklywrappr//.config/tdfgo/fonts/SECTOR.TDF
font: Sector
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 14 height: 8 spacing: 1
preview: ▄▄▄▄▄▄▄▄▄▄▄▄
file: /home/crinklywrappr//.config/tdfgo/fonts/PANDEMON.TDF
font:
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 10 height: 12 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
file: /home/crinklywrappr//.config/tdfgo/fonts/CATLKINX.TDF
font: CattleKingB
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11 height: 7 spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
I wrote some code to do that post-processing, just to see what might be involved.
remove colors and null characters
$ tdfgo fonts -v \
| sed 's/\x1b\[[^\x1b]*m//g' \
| tr -d '\0' \
> out.txt
I did this w/ babashka, b/c I wanted to gain some experience. This code
char list: ...
on a single linechar list
to char_list
file: ...
value to each recordI named this file format.clj
.
(defn add-file [[prev file xs]]
(when (seq xs)
(let [x (first xs)]
(cond
(and (not (str/starts-with? prev "file:"))
(str/starts-with? x "font:")) [(str "file: " file) file xs]
(and (not (str/blank? x))
(nil? (str/index-of x \:))) (add-file ["" x (rest xs)])
:else [x file (rest xs)]))))
(defn format-line [l]
(cond
(str/blank? l) ""
:else l))
(as-> "out.txt" $
(slurp $)
(str/replace $ #"\nchar list:\n" "\nchar_list: ")
(str/split $ #"\n")
(iterate add-file ["" (first $) (rest $)])
(rest $)
(map first $)
(take-while some? $)
(map format-line $)
(doseq [x $] (println x)))
I still need to call uniq
to ensure uniform spacing between records. This was a personal goal. I'm not sure if recutils
actually requires it.
$ bb -f format.clj | uniq | recsel -p file,font
file: /home/crinklywrappr//.config/tdfgo/fonts/KANSAS.TDF
font: Kansas
file: /home/crinklywrappr//.config/tdfgo/fonts/LEGACY.TDF
font: Legacy
file: /home/crinklywrappr//.config/tdfgo/fonts/TRIBWRIT.TDF
font: Tribal Write
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Cyan-Blu
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Green
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Purple
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Red
file: /home/crinklywrappr//.config/tdfgo/fonts/USEX.TDF
font: Use Silver
file: /home/crinklywrappr//.config/tdfgo/fonts/SECTOR.TDF
font: Sector
file: /home/crinklywrappr//.config/tdfgo/fonts/PANDEMON.TDF
font:
file: /home/crinklywrappr//.config/tdfgo/fonts/CATLKINX.TDF
font: CattleKingB
The big unknown w/ this approach is COLOR. preview
, for instance, is useless w/o color, and I don't know if recutils can parse the control characters for color or not.
Based on this research, I recommend gating this feature behind a flag. e.g. tdfgo fonts --plain
.
One final thing I didn't do is separate width
, height
, and spacing
into separate lines.
I did do a bit of investigating in caching fonts data and/or bundling fonts with a single header/db chunk at the beginning to make it easier to get metadata, specifically because of the lag and/or huge reads every time it tries to lookup/find a font. Also the font completion needs to be able to lookup all the fonts each time too
Also since I was lazy and only felt like supporting the COLOR font types, the included fonts are only about 1/4 of the available fonts from RoySAC or the BBS archives. I think one of his font packs is about 4k fonts...
RoySac did come up with his own format of bundling all the fonts into a single file that was like 20Mb I believe... The originaly TheDraw spec only allows for I believe 34 fonts per font file, and there's also a size limit too.
I was trying to mimic figlet/toilet with the single directory filled with fonts and having to re-lookup the fonts every time as a starting point.
I am not too keen on another or separate utility, and also if possible keeping everything within the golang universe languages wise (lazyness again). I dont have a lot of experience with closure but learning another language isn't really the problem. It is just about maintainability/hackability and keeping it within golang makes all parts able to be hacked on similarly.
I am not shooting down your idea, but I would maybe go about it a different way? I am going to open a TODO issue and start a list of stuff if you would like to add input or converse about features/enhancements/etc in one spot.
Based on this research, I recommend gating this feature behind a flag. e.g. tdfgo fonts --plain.
I am not able to easily test it at the moment, but you should be able to export NO_COLOR=1
and have the color output be removed.
Sorry, I wrote too much last night to easily digest.
Supporting recutils does not require any additional dependency. It only requires small changes to the output format. My suggestion is to add that logic to cmd/fonts.go
, and gate it behind a flag e.g. --plain
.
char list: ...
on a single linechar list
to char_list
file: ...
value to each recordThis is what a record looks like w/ those changes.
file: /home/crinklywrappr//.config/tdfgo/fonts/CATLKINX.TDF
font: CattleKingB
char_list: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklnopqrstuvwxyz{|}~
width: 11
height: 7
spacing: 2
preview: ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
Similar changes are required for the non -v
version. Does that make sense?
You could also format to JSON and get similar usability from jq
. But recutils is no additional dependencie & less effort since tdfgo is almost in that format anyway.
I want to share an example of the sort of thing it's useful for. With this command, I am able to list all of the fonts that tdfgo
will error when rendering.
$ NO_COLOR=1 ./result/bin/tdfgo fonts | sed 's/embedded fonts/embedded_fonts/' | sed 's/font names/font_names/' | tr -d '\0' | recsel -e "!(font_names ~ '.+')" -R file
Seems like useful information to have.
I see what you are saying and at least the usefulness in standardizing the output fields so that they can be parsed via another app similar to how many utilities have a parseable output mode that can be easily awk'd
cut'd
IFS'd
read
. Or at least possibly working on a finite structure that like you said can be easily json'd or toml'd or whatever'd...
This would be helpful with two things I am looking for on TODO is that I want to also store/cache this info, and also make the library useful to be included in other applications.
I want to be able to make this work for you but I am knee deep in another project I am trying to finish up before I want to come back to this more in-depth. If you want to start with a PR I am all for it. Your ideas seem to make sense for more than just reclist
's usecase.
If you can let me have a few days to finish this other proect I will have no problem getting the list you gave worked in as well as some of the things I want to get resolved and cleaned up.
Otherwise, like I said, if you want to take charge and PR the things you listed. Our needs seem aligned and I would hugely appreciate any help since it will also further my goals/ideas too.
Thx !
I noticed that
tdfgo fonts ...
output is very nearly a recutils format.RoySac has over 1k fonts alone, and there may be others I'm unaware of, so making the (hopefully) small changes required to support recutils could improve ergonomics around querying, searching, and general composability of
tdfgo
with other cli utils.