Skip to content

Commit

Permalink
support letter spacing and line height config (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kun Chen committed Apr 30, 2023
1 parent 84d5f56 commit ff415d4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apps/app/src/nativeBridge/modules/configModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class ConfigModule extends NativeBridgeModule {
throw new Error('Invalid config: `module.exports` not set');
}

Logger.getInstance().log('info', `Loaded config from ${configPath}}: ${JSON.stringify(mod.exports)}`);

const resolved = resolveConfig(mod.exports);
this.config = resolved;
} catch (err: any) {
Expand Down
6 changes: 5 additions & 1 deletion apps/terminal/components/Terminal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const Terminal = ({ active, shellName }: { active: boolean; shellName: string })

// TODO: refactor this into multiple effects
const xterm = new XTerm();
xterm.loadAddon(new WebglAddon());

const webglAddon = new WebglAddon();
xterm.loadAddon(webglAddon);

const fitAddon = new FitAddon();
xterm.loadAddon(fitAddon);
Expand All @@ -50,6 +52,8 @@ const Terminal = ({ active, shellName }: { active: boolean; shellName: string })
xterm.options.fontFamily = config.fontFamily;
xterm.options.fontWeight = config.fontWeight;
xterm.options.fontWeightBold = config.fontWeightBold;
xterm.options.letterSpacing = config.letterSpacing;
xterm.options.lineHeight = config.lineHeight;
xterm.options.theme = theme;

window.TerminalOne?.terminal
Expand Down
14 changes: 12 additions & 2 deletions packages/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const ConfigTypeContent = {
fontFamily: t.string,
fontWeight: t.number,
fontWeightBold: t.number,
letterSpacing: t.number,
lineHeight: t.number,
tabContentPadding: PaddingType,
themes: t.array(ThemeConfigType),
shells: t.array(ShellConfigType),
Expand Down Expand Up @@ -90,6 +92,12 @@ export const validateConfig = (config: unknown): Config => {
if (result.fontWeightBold !== undefined && (result.fontWeightBold <= 0 || result.fontWeightBold > 1000)) {
throw Error(`Invalid font weight bold: ${result.fontWeightBold}`);
}
if (result.letterSpacing !== undefined && (result.letterSpacing < 0 || result.letterSpacing > 2)) {
throw Error(`Invalid letter spacing: ${result.letterSpacing}`);
}
if (result.lineHeight !== undefined && (result.lineHeight <= 0 || result.lineHeight > 4)) {
throw Error(`Invalid line height: ${result.lineHeight}`);
}
if (result.tabContentPadding !== undefined) {
if (result.tabContentPadding.top < 0 || result.tabContentPadding.top > 128) {
throw Error(`Invalid tab content padding top: ${result.tabContentPadding.top}`);
Expand Down Expand Up @@ -119,10 +127,12 @@ export const DEFAULT_CONFIG: ResolvedConfig = {
cursorBlink: false,
cursorStyle: 'block',
cursorWidth: 1,
fontSize: 15,
fontSize: 16,
fontFamily: 'Consolas, Menlo, monospace',
fontWeight: 500,
fontWeight: 400,
fontWeightBold: 700,
letterSpacing: 1,
lineHeight: 1,
tabContentPadding: {
top: 8,
right: 8,
Expand Down
10 changes: 6 additions & 4 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
]
},
"build:app": {
"outputs": [
"dist/**"
]
"cache": false
},
"dev:terminal": {
"cache": false,
"persistent": true
},
"lint": {},
"test": {}
"test": {
"outputs": [
"coverage/**"
]
}
}
}

0 comments on commit ff415d4

Please sign in to comment.