Skip to content

Commit 6c16e45

Browse files
committed
simpler (fake) hat shapes and colors
1 parent 57e9db4 commit 6c16e45

File tree

7 files changed

+397
-429
lines changed

7 files changed

+397
-429
lines changed

packages/cursorless-engine/src/core/hatStats.test.ts

Lines changed: 30 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,33 @@ import {
1919
getRankedTokens,
2020
} from "../util/allocateHats/getRankedTokens";
2121

22-
// TODO: dedup with vscode
23-
24-
export const HAT_COLORS = [
25-
"default",
26-
"blue",
27-
"green",
28-
"red",
29-
"pink",
30-
"yellow",
31-
"userColor1",
32-
"userColor2",
33-
] as const;
34-
35-
export const HAT_NON_DEFAULT_SHAPES = [
36-
"ex",
37-
"fox",
38-
"wing",
39-
"hole",
40-
"frame",
41-
"curve",
42-
"eye",
43-
"play",
44-
"bolt",
45-
"crosshairs",
46-
] as const;
47-
48-
export const HAT_SHAPES = ["default", ...HAT_NON_DEFAULT_SHAPES] as const;
49-
50-
const charForShape: Map<string, string> = new Map(
51-
Object.entries({
52-
default: "*",
53-
ex: "x",
54-
fox: "v",
55-
wing: "w", // TODO: this is the only one that looks nothing like its shape
56-
hole: "o",
57-
frame: "#",
58-
curve: "^",
59-
eye: "0",
60-
play: ">",
61-
bolt: "~",
62-
crosshairs: "+",
63-
}),
64-
);
65-
66-
const charForColor: Map<string, string> = new Map(
67-
Object.entries({
68-
default: "*",
69-
blue: "b",
70-
green: "g",
71-
red: "r",
72-
pink: "p",
73-
yellow: "y",
74-
userColor1: "1",
75-
userColor2: "2",
76-
}),
77-
);
22+
// We use special hat "colors"/"shapes" for nice ASCII art output.
23+
const HAT_COLORS = ["default", ..."ABCDEF"];
24+
const HAT_NON_DEFAULT_SHAPES = [..."123456"];
25+
const allHatStyles: HatStyleMap = {
26+
...Object.fromEntries(
27+
HAT_COLORS.map((color) => [
28+
color,
29+
{
30+
color,
31+
shape: "default",
32+
penalty: penaltyForColorShape(color, "default"),
33+
},
34+
]),
35+
),
36+
...Object.fromEntries(
37+
HAT_COLORS.flatMap((color) =>
38+
HAT_NON_DEFAULT_SHAPES.map((shape) => [
39+
`${color}-${shape}`,
40+
{
41+
color,
42+
shape,
43+
penalty: penaltyForColorShape(color, shape),
44+
},
45+
]),
46+
),
47+
),
48+
};
7849

7950
const tokenHatSplittingDefaults: TokenHatSplittingMode = {
8051
preserveCase: false,
@@ -101,31 +72,6 @@ suite("hatStats", () => {
10172
...tokenHatSplittingDefaults,
10273
});
10374
});
104-
// Set up hat styles, mimicking the real thing.
105-
const allHatStyles: HatStyleMap = {
106-
...Object.fromEntries(
107-
HAT_COLORS.map((color) => [
108-
color,
109-
{
110-
color,
111-
shape: "default",
112-
penalty: penaltyForColorShape(color, "default"),
113-
},
114-
]),
115-
),
116-
...Object.fromEntries(
117-
HAT_COLORS.flatMap((color) =>
118-
HAT_NON_DEFAULT_SHAPES.map((shape) => [
119-
`${color}-${shape}`,
120-
{
121-
color,
122-
shape,
123-
penalty: penaltyForColorShape(color, shape),
124-
},
125-
]),
126-
),
127-
),
128-
};
12975

13076
const fixturePath = path.join(
13177
getCursorlessRepoRoot(),
@@ -328,17 +274,14 @@ function goldenHatFile(
328274
line1 += " ".repeat(hatRange.start.character - line1.length);
329275
line1 += "_";
330276
} else if (penalty === 1) {
331-
const char =
332-
color === "default"
333-
? charForShape.get(shape)
334-
: charForColor.get(color);
277+
const char = color === "default" ? shape : color;
335278
line1 += " ".repeat(hatRange.start.character - line1.length);
336279
line1 += char;
337280
} else if (penalty === 2) {
338281
line1 += " ".repeat(hatRange.start.character - line1.length);
339-
line1 += charForShape.get(shape);
282+
line1 += shape;
340283
line2 += " ".repeat(hatRange.start.character - line2.length);
341-
line2 += charForColor.get(color);
284+
line2 += color;
342285
} else {
343286
throw new Error(`unexpected penalty: ${penalty}`);
344287
}

packages/cursorless-engine/src/test/fixtures/hat-stats/intern.go.golden

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,153 +2,158 @@ _ _ _ _ _ _
22
// Package intern interns strings.
33
[] [-----] [----] [-----] [-----]|
44

5-
b _ b _ _ _ b
5+
A _ A _ _ _ A
66
// Interning is best effort only.
77
[] [-------] [] [--] [----] [--]|
88

9-
g _ _ _ b _ _
9+
B _ _ _ A _ _
1010
// Interned strings may be removed automatically
1111
[] [------] [-----] [-] [] [-----] [-----------]
1212

13-
r _ _ b _ _ g
13+
C _ _ A _ _ B
1414
// at any time without notification.
1515
[] [] [-] [--] [-----] [----------]|
1616

17-
p b _ _ g b _
17+
D A _ _ B A _
1818
// All functions may be called concurrently
1919
[] [-] [-------] [-] [] [----] [----------]
2020

21-
y _ b b b b r
21+
E _ A A A A C
2222
// with themselves and each other.
2323
[] [--] [--------] [-] [--] [---]|
2424

25-
_ b
25+
_ A
2626
package intern
2727
[-----] [----]
2828

29-
b _ b b
29+
A _ A A
3030
import "sync"
3131
[----] |[--]|
3232

33-
g g g pb _ r yg _
33+
B B B DA _ C EB _
3434
var pool sync.Pool = sync.Pool{
3535
[-] [--] [--]|[--] | [--]|[--]|
3636

37-
b_ b __ g b_ g
37+
A_ A __ B A_ B
3838
␉New: func() interface{} {
3939
[-]| [--]|| [-------]|| |
4040

41-
b b b r_ b_p b
41+
A A A C_ A_D A
4242
␉␉return make(map[string]string)
4343
[----] [--]|[-]|[----]|[----]|
4444

45-
b_
45+
A_
4646
␉},
4747
||
4848

49-
g
49+
B
5050
}
5151
|
5252

53-
1 y g 1b g1
53+
F E B FA BF
5454
// String returns s, interned.
5555
[] [----] [-----] || [------]|
5656

57-
g gg2 b g x r
57+
B BB1 A B 2 C
5858
func String(s string) string {
5959
[--] [----]|| [----]| [----] |
6060

61-
g bb g 2 g rrxp g bv bw p
61+
B AA B 1 B CC2D B A3 A4 D
6262
␉m := pool.Get().(map[string]string)
6363
| || [--]|[-]||||[-]|[----]|[----]|
6464

65-
gg g gg rgog
65+
BB B BB CB5B
6666
␉c, ok := m[s]
6767
|| [] || ||||
6868

69-
r r p
69+
C C D
7070
␉if ok {
7171
[] [] |
7272

73-
rv r ypy
73+
C3 C EDE
7474
␉␉pool.Put(m)
7575
[--]|[-]|||
7676

77-
r r
77+
C C
7878
␉␉return c
7979
[----] |
8080

81-
r
81+
C
8282
␉}
8383
|
8484

85-
yr#r r ^
85+
A
86+
EC6C C 1
8687
␉m[s] = s
8788
|||| | |
8889

89-
p w p 111
90+
D 4 D FFF
9091
␉pool.Put(m)
9192
[--]|[-]|||
9293

93-
b 0
94+
A
95+
A 2
9496
␉return s
9597
[----] |
9698

97-
p
99+
D
98100
}
99101
|
100102

101-
2 r g p r g r rr p o
103+
1 C B D C B C CC D 5
102104
// Bytes returns b converted to a string, interned.
103105
[] [---] [-----] | [-------] [] | [----]| [------]|
104106

105-
p g 2y pp r 2 p y
107+
D B 1E DD C 1 D E
106108
func Bytes(b []byte) string {
107109
[--] [---]|| ||[--]| [----] |
108110

109-
2 rp p# y xx^v p y> y~ v
111+
A
112+
1 CD D6 E 2213 D E C E C 3
110113
␉m := pool.Get().(map[string]string)
111114
| || [--]|[-]||||[-]|[----]|[----]|
112115

113-
pp r py x1+ w1w1
116+
DD C DE 2F D 4F4F
114117
␉c, ok := m[string(b)]
115118
|| [] || ||[----]||||
116119

117-
y y 1
120+
E E F
118121
␉if ok {
119122
[] [] |
120123

121-
y0 y ovo
124+
A
125+
E2 E 535
122126
␉␉pool.Put(m)
123127
[--]|[-]|||
124128

125-
1 y
129+
F E
126130
␉␉return c
127131
[----] |
128132

129-
y
133+
E
130134
␉}
131135
|
132136

133-
b
134-
x y1 y#2#
137+
A
138+
3 EF E616
135139
␉s := string(b)
136140
| || [----]|||
137141

138-
b b
139-
w2v2 2 w
142+
A A
143+
4141 1 5
140144
␉m[s] = s
141145
|||| | |
142146

143-
1 > 1 ^o^
147+
A A A
148+
F 3 F 151
144149
␉pool.Put(m)
145150
[--]|[-]|||
146151

147-
b
148-
2 o
152+
A
153+
1 6
149154
␉return s
150155
[----] |
151156

152-
1
157+
F
153158
}
154159
|

packages/cursorless-engine/src/test/fixtures/hat-stats/intern.go.stats

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ nPenalty0:
1515
spark: 0 █ 25 50 75 100
1616

1717
nPenalty1:
18-
mean: 84%
18+
mean: 81%
1919
std: 1%
20-
min: 83%
21-
max: 85%
22-
spark: 0 25 50 75 ▅█ 100
20+
min: 80%
21+
max: 82%
22+
spark: 0 25 50 75 ▂█▆ 100
2323

2424
nPenalty2:
25-
mean: 1%
25+
mean: 4%
2626
std: 1%
27-
min: 0%
28-
max: 2%
29-
spark: 0 25 50 75 100
27+
min: 3%
28+
max: 5%
29+
spark: 0 █▅ 25 50 75 100

0 commit comments

Comments
 (0)