-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathcontext.ts
More file actions
42 lines (38 loc) · 1.08 KB
/
context.ts
File metadata and controls
42 lines (38 loc) · 1.08 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
import * as shiki from 'shiki';
import { Config } from './getConfig';
import { FormattedString, T } from './formattedString';
import { ChalkInstance } from 'chalk';
/**
* Internal context object used to pass around config and config-derived
* constants.
*/
export type Context = Config & {
CHALK: ChalkInstance;
SCREEN_WIDTH: number;
HORIZONTAL_SEPARATOR: FormattedString;
HIGHLIGHTER?: shiki.Highlighter;
};
export async function getContextForConfig(
config: Config,
chalk: ChalkInstance,
screenWidth: number
): Promise<Context> {
const SCREEN_WIDTH = screenWidth;
const HORIZONTAL_SEPARATOR = T()
.fillWidth(SCREEN_WIDTH, '─')
.addSpan(0, SCREEN_WIDTH, config.BORDER_COLOR);
let HIGHLIGHTER = undefined;
if (config.SYNTAX_HIGHLIGHTING_THEME) {
HIGHLIGHTER = await shiki.createHighlighter({
themes: [config.SYNTAX_HIGHLIGHTING_THEME],
langs: [],
});
}
return {
...config,
CHALK: chalk,
SCREEN_WIDTH,
HORIZONTAL_SEPARATOR,
HIGHLIGHTER,
};
}