Skip to content

Commit 4c9e955

Browse files
committed
Cleanup some things
1 parent d478893 commit 4c9e955

File tree

4 files changed

+108
-87
lines changed

4 files changed

+108
-87
lines changed

.readme.gotxt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ ChangeLog
207207
### 2.5.0 (unreleased)
208208

209209
- Add support for properties; they can be displayed with `%(props)` in
210-
`-format`, and printed with `uni print` (e.g. `uni print dash`).
210+
`-format`, and selected in `print` (e.g. `uni print dash`).
211211

212212
- Add `uni list` command, to list categories, blocks, and properties.
213213

@@ -227,7 +227,8 @@ ChangeLog
227227
alias for compatibility.
228228

229229
- Don't use the Go stdlib `unicode` package; since this is a Unicode 13 database
230-
some operations would fail on codepoints added in Unicode 14.
230+
and some operations would fail on codepoints added in Unicode 14 due to the
231+
mismatch.
231232

232233
### v2.4.0 (2021-12-20)
233234

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ ChangeLog
448448
### 2.5.0 (unreleased)
449449

450450
- Add support for properties; they can be displayed with `%(props)` in
451-
`-format`, and printed with `uni print` (e.g. `uni print dash`).
451+
`-format`, and selected in `print` (e.g. `uni print dash`).
452452

453453
- Add `uni list` command, to list categories, blocks, and properties.
454454

@@ -468,7 +468,8 @@ ChangeLog
468468
alias for compatibility.
469469

470470
- Don't use the Go stdlib `unicode` package; since this is a Unicode 13 database
471-
some operations would fail on codepoints added in Unicode 14.
471+
and some operations would fail on codepoints added in Unicode 14 due to the
472+
mismatch.
472473

473474
### v2.4.0 (2021-12-20)
474475

format.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ type Format struct {
6161
autoalign []int // Max line lengths for autoalign.
6262
ntrim int // Number of columns with "trim"
6363

64-
//tblData []map[string]string
6564
tblData []unidata.Codepoint
6665
}
6766

uni.go

Lines changed: 102 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ Usage: %(prog) [command] [flags]
2828
uni queries the unicode database. https://github.com/arp242/uni
2929
3030
Flags:
31+
-f, -format Output format.
32+
-a, -as How to print the results: list (default), json, or table.
3133
-c, -compact More compact output.
3234
-r, -raw Don't use graphical variants or add combining characters.
3335
-p, -pager Output to $PAGER.
3436
-o, -or Use "or" when searching instead of "and".
35-
-f, -format Output format.
36-
-a, -as How to print the results: list (default), json, or table.
3737
3838
Commands:
3939
list List blocks, categories, or properties.
@@ -42,7 +42,7 @@ Commands:
4242
print Print characters by codepoint, category, or block.
4343
emoji Search emojis.
4444
45-
Use "%(prog) help" for a more detailed help.
45+
Use "%(prog) help" or "%(prog) -h" for a more detailed help.
4646
`)
4747

4848
var usage = zli.Usage(zli.UsageHeaders|zli.UsageProgram|zli.UsageTrim, `
@@ -52,47 +52,51 @@ uni queries the unicode database. https://github.com/arp242/uni
5252
5353
Flags:
5454
Flags can appear anywhere; "uni search euro -c" and "uni -c search euro"
55-
are identical. Use "uni search -- -c" if you want to search for "-c". This
56-
also applies to flags specific to a command (e.g. "-gender" for "emoji").
55+
are identical. Use "uni search -- -c" if you want to search for "-c".
56+
57+
-f, -format Columns to print and their formatting; see Format section
58+
below for details.
59+
60+
-a, -as How to print the results: list (default), json, or table.
61+
62+
json The columns listed in -format are included,
63+
ignoring formatting flags. Use "-format all" to
64+
include all columns.
65+
table Output as table; instead of listing the codepoints
66+
on every line use a table. This ignores the
67+
-format flag.
5768
5869
-c, -compact More compact output; don't print header, "no matches", etc.
59-
For json it will use minified output, and for table it will
60-
have less padding.
70+
For json output it uses minified output, and for table it
71+
has less padding.
72+
6173
-r, -raw Don't use graphical variants for control characters and
6274
don't add ◌ (U+25CC) before combining characters.
75+
6376
-p, -pager Output to $PAGER.
77+
6478
-o, -or Use "or" when searching: print if at least one parameter
6579
matches, instead of only when all parameters match.
66-
-f, -format Output format; see Format section below for details.
67-
-a, -as How to print the results: list (default), json, or table.
68-
69-
json The columns listed in -format are included, ignoring
70-
formatting flags. Use "-format all" to include all
71-
columns.
7280
73-
table Output as table; instead of listing the codepoints
74-
on every line use a table. This ignores the -format
75-
flag.
7681
-q, -quiet Backwards-compatible alias for -c/-compact.
7782
-j, -json Backwards-compatible alias for -as json
7883
7984
Commands:
8085
list [query] List an overview of blocks, categories, or properties.
81-
Every name can be abbreviated (i.e. "b")
86+
Every name can be abbreviated (i.e. "b" for "block"). Use
87+
"all" to show everything.
8288
83-
identify [text] Identify all the characters in the given strings.
89+
identify [text] Identify all the characters in the given arguments.
8490
8591
search [query] Search description for any of the words.
8692
87-
print [query] Print characters.
93+
print [query] Print characters. The query can be any of the following:
8894
89-
The query can be any of the following:
90-
91-
Codepoint Specific codepoint, as:
92-
hex U+20, U20, 0x20
93-
decimal 0d32
94-
octal 0o40
95-
binary 0b100000
95+
Codepoint Specific codepoint, in number formats:
96+
hexadecimal U+20, U20, 0x20, x20
97+
decimal 0d32
98+
octal 0o40, o40
99+
binary 0b100000
96100
97101
Range Range of codepoints, as "start-end" or
98102
"start..end", using the same notation as
@@ -117,22 +121,23 @@ Commands:
117121
118122
Property Prefix with "property:", "prop:", or "p:".
119123
120-
all Everything
124+
all All codepoints we know about.
121125
122126
The category, block, and property can be abbreviated, and
123-
non-letter characters can be omitted. These are all
124-
identical:
127+
non-letter characters can be omitted. These are identical:
128+
129+
block:'Block Drawing' block:box
130+
131+
As are these:
125132
126-
block:'Block Drawing' block:box
127-
cat:Dash_Punctuation cat:dashpunctuation
133+
cat:Dash_Punctuation cat:dashpunctuation
128134
129135
If nothing of the above matches it will try to find by
130136
block, category, or property, giving an error if more than
131137
one matches.
132138
133-
emoji [query] Search emojis.
134-
135-
The query is matched on the emoji name and CLDR data.
139+
emoji [query] Search emojis. The query is matched on the emoji name and
140+
CLDR data.
136141
137142
The CLDR data is a list of keywords. For example 🙏
138143
(folded hands) contains "ask, high 5, high five, please,
@@ -141,13 +146,13 @@ Commands:
141146
142147
You can use <prefix>:query to search in specific fields:
143148
144-
group: g: Group and subgroup
145-
name: n: Emoji name
146-
cldr: c: CLDR data
149+
group: g: Group and subgroup
150+
name: n: Emoji name
151+
cldr: c: CLDR data
147152
148153
The query parameters are AND'd together, so this:
149154
150-
uni emoji smiling g:cat-face
155+
uni emoji smiling g:cat-face
151156
152157
Will match everything in the cat-face group with smiling
153158
in the name. Use the -or flag to change this to "cat-face
@@ -157,18 +162,18 @@ Commands:
157162
158163
Modifier flags, both accept a comma-separated list:
159164
160-
-g, -gender Set the gender:
161-
p, person, people
162-
m, man, men, male
163-
f, female, w, woman, women
165+
-g, -gender Set the gender:
166+
p, person, people
167+
m, man, men, male
168+
f, female, w, woman, women
164169
165-
-t, -tone Set the skin tone modifier:
166-
n, none
167-
l, light
168-
ml, mediumlight, medium-light
169-
m, medium
170-
md, mediumdark, medium-dark
171-
d, dark
170+
-t, -tone Set the skin tone modifier:
171+
n, none
172+
l, light
173+
ml, mediumlight, medium-light
174+
m, medium
175+
md, mediumdark, medium-dark
176+
d, dark
172177
173178
Use "all" to include all combinations; the default is to
174179
include no skin tones and the "person" gender.
@@ -192,8 +197,8 @@ Format:
192197
%(name r:5) Right-align and pad with 5 spaces
193198
%(name q) Quote with single quotes, excluding any padding
194199
%(name t) Trim this column if it's longer than the screen width
195-
%(name f:C) Fill this column with character C; especially useful for
196-
numbers: %(bin r:auto f:0)
200+
%(name f:C) Fill this column with character C; especially useful
201+
for numbers: %(bin r:auto f:0)
197202
198203
Placeholders that work for all commands:
199204
%(tab) A literal tab when outputting to a terminal, or four
@@ -202,26 +207,26 @@ Format:
202207
with tabs.
203208
204209
Placeholders for identify, search, and print:
205-
%(char) The literal character
206-
%(cpoint) As codepoint U+2713
207-
%(hex) As hex 2713
208-
%(oct) As octal 23423
209-
%(bin) As binary (little-endian) 10011100010011
210-
%(dec) As decimal 10003
211-
%(utf8) As UTF-8 e2 9c 93
212-
%(utf16le) As UTF-16 LE (Windows) 13 27
213-
%(utf16be) As UTF-16 BE 27 13
214-
%(html) HTML entity &check;
215-
%(xml) XML entity &#x2713;
216-
%(json) JSON escape \u2713
217-
%(keysym) X11 keysym; can be blank checkmark
218-
%(digraph) Vim Digraph; can be blank OK
219-
%(name) Code point name CHECK MARK
220-
%(cat) Category name Other_Symbol
221-
%(block) Block name Dingbats
222-
%(props) Properties, separated by , Pattern Syntax
223-
%(plane) Plane name Basic Multilingual Plane
224-
%(width) Character width Narrow
210+
%(char) The literal character ✓
211+
%(cpoint) As codepoint U+2713
212+
%(hex) As hex 2713
213+
%(oct) As octal 23423
214+
%(bin) As binary (little-endian) 10011100010011
215+
%(dec) As decimal 10003
216+
%(utf8) As UTF-8 e2 9c 93
217+
%(utf16le) As UTF-16 LE (Windows) 13 27
218+
%(utf16be) As UTF-16 BE 27 13
219+
%(html) HTML entity &check;
220+
%(xml) XML entity &#x2713;
221+
%(json) JSON escape \u2713
222+
%(keysym) X11 keysym; can be blank checkmark
223+
%(digraph) Vim Digraph; can be blank OK
224+
%(name) Code point name CHECK MARK
225+
%(cat) Category name Other_Symbol
226+
%(block) Block name Dingbats
227+
%(props) Properties, separated by , Pattern Syntax
228+
%(plane) Plane name Basic Multilingual Plane
229+
%(width) Character width Narrow
225230
%(wide_padding) Blank for wide characters,
226231
space otherwise; for alignment
227232
@@ -230,13 +235,13 @@ Format:
230235
231236
Placeholders for emoji:
232237
233-
%(emoji) The emoji itself 🧑‍🚒
234-
%(name) Emoji name firefighter
235-
%(group) Emoji group People & Body
236-
%(subgroup) Emoji subgroup person-role
237-
%(cpoint) Codepoints U+1F9D1 U+200D U+1F692
238-
%(cldr) CLDR data, w/o duplicating name firetruck
239-
%(cldr_full) Full CLDR data firefighter, firetruck
238+
%(emoji) The emoji itself 🧑‍🚒
239+
%(name) Emoji name firefighter
240+
%(group) Emoji group People & Body
241+
%(subgroup) Emoji subgroup person-role
242+
%(cpoint) Codepoints U+1F9D1 U+200D U+1F692
243+
%(cldr) CLDR data, w/o emoji name firetruck
244+
%(cldr_full) Full CLDR data firefighter, firetruck
240245
241246
The default is:
242247
`+defaultEmojiFormat+`
@@ -310,8 +315,10 @@ func main() {
310315
raw = rawF.Set()
311316
args = flag.Args
312317
)
313-
args, err = zli.InputOrArgs(args, " \t\n", quiet)
314-
zli.F(err)
318+
if cmd != "list" {
319+
args, err = zli.InputOrArgs(args, " \t\n", quiet)
320+
zli.F(err)
321+
}
315322

316323
format := formatF.String()
317324
if !formatF.Set() && cmd == "emoji" {
@@ -478,12 +485,22 @@ func list(ls []string, as printAs) error {
478485
zli.Fatalf("can't use -as table with the list command")
479486
}
480487

481-
for _, l := range ls {
488+
if len(ls) == 0 || zstring.Contains(ls, "all") {
489+
ls = []string{"blocks", "categories", "properties"}
490+
}
491+
492+
for i, l := range ls {
482493
cmd, err := match(l, "blocks", "categories", "properties")
494+
if cmd != "" && len(ls) > 0 && as == printAsList {
495+
if i > 0 {
496+
fmt.Fprintln(zli.Stdout)
497+
}
498+
fmt.Fprintf(zli.Stdout, "%s:\n", zstring.UpperFirst(cmd))
499+
}
483500

484501
switch cmd {
485502
case "":
486-
zli.F(err)
503+
zli.Fatalf("list: %s", err)
487504

488505
case "blocks":
489506
order := make([]struct {
@@ -871,6 +888,9 @@ func print(args []string, format string, raw bool, as printAs) error {
871888
func emoji(args []string, format string, raw bool, as printAs, or bool, tones, genders unidata.EmojiModifier) error {
872889
if as == printAsTable || as == printAsTableCompact {
873890
// TODO: it should
891+
// The reason it doesn't work is because printTbl() assumes that every
892+
// entry is a codepoint. Should instead duplicate some data in
893+
// Format.tblData, instead of using []unidata.Codepoint.
874894
return errors.New("-table doesn't work with emoji")
875895
}
876896

0 commit comments

Comments
 (0)