Skip to content

Commit 5e089b0

Browse files
committed
try different visuals, height = penalty
1 parent 9375ceb commit 5e089b0

File tree

4 files changed

+194
-283
lines changed

4 files changed

+194
-283
lines changed

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ suite("hatStats", () => {
188188
const lineTokens = allTokens.filter(
189189
(token) => token.token.range.end.line === lineno,
190190
);
191-
let shapeLine = "";
192-
let colorLine = "";
191+
let line1 = "";
192+
let line2 = "";
193193
let rangeLine = "";
194194
lineTokens.forEach((token) => {
195195
const tokenRange = token.token.range;
@@ -209,15 +209,24 @@ suite("hatStats", () => {
209209
}
210210
const hatRange = hat.hatRange;
211211
const [color, shape] = colorShapeForHatStyle(hat.hatStyle);
212-
shapeLine += " ".repeat(
213-
hatRange.start.character - shapeLine.length,
214-
);
215-
shapeLine += charForShape.get(shape);
216-
if (color !== "default") {
217-
colorLine += " ".repeat(
218-
hatRange.start.character - colorLine.length,
219-
);
220-
colorLine += charForColor.get(color);
212+
const penalty = penaltyForHatStyle(hat.hatStyle);
213+
if (penalty == 0) {
214+
line1 += " ".repeat(hatRange.start.character - line1.length);
215+
line1 += "_";
216+
} else if (penalty == 1) {
217+
const char =
218+
color == "default"
219+
? charForShape.get(shape)
220+
: charForColor.get(color);
221+
line1 += " ".repeat(hatRange.start.character - line1.length);
222+
line1 += char;
223+
} else if (penalty == 2) {
224+
line1 += " ".repeat(hatRange.start.character - line1.length);
225+
line1 += charForShape.get(shape);
226+
line2 += " ".repeat(hatRange.start.character - line2.length);
227+
line2 += charForColor.get(color);
228+
} else {
229+
throw new Error(`unexpected penalty: ${penalty}`);
221230
}
222231
const width =
223232
tokenRange.end.character - tokenRange.start.character;
@@ -236,11 +245,11 @@ suite("hatStats", () => {
236245
);
237246
rangeLine += rangeStr;
238247
});
239-
if (colorLine.length !== 0) {
240-
w.write(colorLine + "\n");
248+
if (line2.length !== 0) {
249+
w.write(line2 + "\n");
241250
}
242-
if (colorLine.length !== 0 || shapeLine.length !== 0) {
243-
w.write(shapeLine + "\n");
251+
if (line1.length !== 0) {
252+
w.write(line1 + "\n");
244253
}
245254
if (line.length !== 0) {
246255
// TODO: tabs, emoji, sigh
Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,144 @@
1-
* * * * * *
1+
_ _ _ _ _ _
22
// Package intern interns strings.
33
[] [-----] [----] [-----] [-----]|
44

5-
b b
6-
* * * * * * *
5+
b _ _ _ _ _ b
76
// Interning is best effort only.
87
[] [-------] [] [--] [----] [--]|
98

10-
g
11-
* * * * * * *
9+
g _ _ _ _ _ _
1210
// Interned strings may be removed automatically
1311
[] [------] [-----] [-] [] [-----] [-----------]
1412

15-
r b b g
16-
* * * * * * *
13+
r b b _ _ _ g
1714
// at any time without notification.
1815
[] [] [-] [--] [-----] [----------]|
1916

20-
p b b b b b
21-
* * * * * * *
17+
p b _ b b b b
2218
// All functions may be called concurrently
2319
[] [-] [-------] [-] [] [----] [----------]
2420

25-
y b g b gr
26-
* * * * * **
21+
y _ b g b gr
2722
// with themselves and each other.
2823
[] [--] [--------] [-] [--] [---]|
2924

30-
g
31-
* *
25+
_ g
3226
package intern
3327
[-----] [----]
3428

35-
g b
36-
* * * *
29+
_ _ g b
3730
import "sync"
3831
[----] |[--]|
3932

40-
b g r p b p y g
41-
* * * * * * * * * *
33+
b g r p b _ p y g _
4234
var pool sync.Pool = sync.Pool{
4335
[-] [--] [--]|[--] | [--]|[--]|
4436

45-
b b g b g
46-
** * ** * ** *
37+
b_ b __ g b_ g
4738
␉New: func() interface{} {
4839
[-]| [--]|| [-------]|| |
4940

50-
g b b b b r b
51-
* * * ** ** * *
41+
g b b b_ b_ r b
5242
␉␉return make(map[string]string)
5343
[----] [--]|[-]|[----]|[----]|
5444

55-
b
56-
**
45+
b_
5746
␉},
5847
||
5948

6049
g
61-
*
6250
}
6351
|
6452

6553
1 p r bb r1
66-
* * * ** **
6754
// String returns s, interned.
6855
[] [----] [-----] || [------]|
6956

7057
g ggg y g 1 r
71-
* *** * * * *
7258
func String(s string) string {
7359
[--] [----]|| [----]| [----] |
7460

75-
b bb r 2 g rr p g b r b 2 p
76-
* ** * * * **x* * * * * * *
61+
b bb r 2 g rrxp g b r b 2 p
7762
␉m := pool.Get().(map[string]string)
7863
| || [--]|[-]||||[-]|[----]|[----]|
7964

8065
rg g gg ggrg
81-
** * ** ****
8266
␉c, ok := m[s]
8367
|| [] || ||||
8468

8569
b r p
86-
* * *
8770
␉if ok {
8871
[] [] |
8972

90-
r p yry
91-
*v * ***
73+
rv p yry
9274
␉␉pool.Put(m)
9375
[--]|[-]|||
9476

9577
r p
96-
* *
9778
␉␉return c
9879
[----] |
9980

10081
r
101-
*
10282
␉}
10383
|
10484

10585
prpr r y
106-
**** * *
10786
␉m[s] = s
10887
|||| | |
10988

110-
p y 1y1
111-
* w * ***
89+
p w y 1y1
11290
␉pool.Put(m)
11391
[--]|[-]|||
11492

11593
p 1
116-
* *
11794
␉return s
11895
[----] |
11996

12097
p
121-
*
12298
}
12399
|
124100

125-
2 y 1 b g y r rr y
126-
* * * * * * * ** * o
101+
2 y 1 b g y r rr y o
127102
// Bytes returns b converted to a string, interned.
128103
[] [---] [-----] | [-------] [] | [----]| [------]|
129104

130105
2 1 2g pp 2 2 p y
131-
* * ** ** * * * *
132106
func Bytes(b []byte) string {
133107
[--] [---]|| ||[--]| [----] |
134108

135-
1 rp p 1 p y p y
136-
* ** *# * xx^v * * * * x v
109+
1 rp p# 1 xx^v p y p y x v
137110
␉m := pool.Get().(map[string]string)
138111
| || [--]|[-]||||[-]|[----]|[----]|
139112

140-
yp p py 21 r 1
141-
** * ** ** v w*w*
113+
yp p py 21 v wrw1
142114
␉c, ok := m[string(b)]
143115
|| [] || ||[----]||||
144116

145117
g y 1
146-
* * *
147118
␉if ok {
148119
[] [] |
149120

150-
y
151-
*0 x oxo
121+
y0 x oxo
152122
␉␉pool.Put(m)
153123
[--]|[-]|||
154124

155125
2 1
156-
* *
157126
␉␉return c
158127
[----] |
159128

160129
y
161-
*
162130
␉}
163131
|
164132

165-
2 y1 y p
166-
* ** *#*#
133+
2 y1 y#p#
167134
␉s := string(b)
168135
| || [----]|||
169136

170-
2 2 2
171-
v*x* * v
137+
v2x2 2 v
172138
␉m[s] = s
173139
|||| | |
174140

175-
1
176-
* > v ^w^
141+
1 > v ^w^
177142
␉pool.Put(m)
178143
[--]|[-]|||
179144

@@ -182,7 +147,6 @@ func Bytes(b []byte) string {
182147
[----] |
183148

184149
1
185-
*
186150
}
187151
|
188152

0 commit comments

Comments
 (0)