-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathiterFormatFileName.ts
More file actions
59 lines (54 loc) · 1.76 KB
/
iterFormatFileName.ts
File metadata and controls
59 lines (54 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Context } from './context';
import { T, FormattedString } from './formattedString';
import { iterFitTextToWidth } from './iterFitTextToWidth';
export function* iterFormatFileName(
context: Context,
fileNameA: string,
fileNameB: string
): Iterable<FormattedString> {
const {
HORIZONTAL_SEPARATOR,
INSERTED_LINE_COLOR,
DELETED_LINE_COLOR,
INSERTED_LINE_NO_COLOR,
DELETED_LINE_NO_COLOR,
FILE_NAME_COLOR,
SCREEN_WIDTH,
} = context;
yield HORIZONTAL_SEPARATOR;
const formattedString = T().appendString(' ■■ ');
let fileNameLabel;
if (!fileNameA) {
formattedString
.addSpan(1, 3, INSERTED_LINE_NO_COLOR)
.addSpan(1, 3, INSERTED_LINE_COLOR);
fileNameLabel = fileNameB;
} else if (!fileNameB) {
formattedString
.addSpan(1, 3, DELETED_LINE_NO_COLOR)
.addSpan(1, 3, DELETED_LINE_COLOR);
fileNameLabel = fileNameA;
} else if (fileNameA === fileNameB) {
formattedString
.addSpan(1, 2, DELETED_LINE_NO_COLOR)
.addSpan(2, 3, INSERTED_LINE_NO_COLOR)
.addSpan(1, 2, DELETED_LINE_COLOR)
.addSpan(2, 3, INSERTED_LINE_COLOR);
fileNameLabel = fileNameA;
} else {
formattedString
.addSpan(1, 2, DELETED_LINE_NO_COLOR)
.addSpan(2, 3, INSERTED_LINE_NO_COLOR)
.addSpan(1, 2, DELETED_LINE_COLOR)
.addSpan(2, 3, INSERTED_LINE_COLOR);
fileNameLabel = `${fileNameA} -> ${fileNameB}`;
}
formattedString.appendString(fileNameLabel);
yield* iterFitTextToWidth(
context,
formattedString,
SCREEN_WIDTH,
FILE_NAME_COLOR
);
yield HORIZONTAL_SEPARATOR;
}