MCPcopy Index your code
hub / github.com/banga/git-split-diffs / applyFormatting

Function applyFormatting

src/formattedString.ts:11–45  ·  view source on GitHub ↗
(
    context: Context,
    string: FormattedString
)

Source from the content-addressed store, hash-verified

9}
10
11export function applyFormatting(
12 context: Context,
13 string: FormattedString
14): string {
15 const { CHALK, DEFAULT_COLOR } = context;
16
17 let formattedString = '';
18 for (const [substring, colors] of string.iterSubstrings()) {
19 let formattedSubstring = substring;
20 const themeColor = reduceThemeColors([...colors, DEFAULT_COLOR]);
21
22 const { color, backgroundColor, modifiers } = themeColor;
23 if (color) {
24 formattedSubstring = CHALK.rgb(
25 Math.floor(color.r),
26 Math.floor(color.g),
27 Math.floor(color.b)
28 )(formattedSubstring);
29 }
30 if (backgroundColor) {
31 formattedSubstring = CHALK.bgRgb(
32 Math.floor(backgroundColor.r),
33 Math.floor(backgroundColor.g),
34 Math.floor(backgroundColor.b)
35 )(formattedSubstring);
36 }
37 if (modifiers) {
38 for (const modifier of modifiers) {
39 formattedSubstring = CHALK[modifier](formattedSubstring);
40 }
41 }
42 formattedString += formattedSubstring;
43 }
44 return formattedString;
45}

Callers 1

iterSideBySideDiffsFunction · 0.90

Calls 2

reduceThemeColorsFunction · 0.90
iterSubstringsMethod · 0.80

Tested by

no test coverage detected