Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ export function activate(context: vscode.ExtensionContext) {
viewProvider?.syncState();
}, 50);
}
if (e.affectsConfiguration('terminal.integrated.fontSize') && viewProvider) {
viewProvider.updateTerminalFontSize();
}
})
);
}
Expand Down
26 changes: 25 additions & 1 deletion src/webviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ export class EspDecoderWebviewPanel implements vscode.WebviewViewProvider {
return this.config.elfPath;
}

/**
* Push the current `terminal.integrated.fontSize` to the webview so the
* serial output font updates live without rebuilding the HTML.
*/
public updateTerminalFontSize(): void {
this.postMessage({ type: 'fontSizeChanged', fontSize: this.getTerminalFontSize() });
}

private handleSerialData(data: Buffer): void {
// Use StringDecoder to correctly handle multi-byte UTF-8 characters
// (e.g. ▂▄▆█) that may be split across consecutive data chunks.
Expand Down Expand Up @@ -1035,11 +1043,23 @@ export class EspDecoderWebviewPanel implements vscode.WebviewViewProvider {
}
}

/**
* Read the serial-output font size from the user's VS Code settings.
* Uses `terminal.integrated.fontSize` (falling back to 13px when unset or
* when set to VS Code's "0 = use editor default" sentinel).
*/
private getTerminalFontSize(): number {
return vscode.workspace
.getConfiguration('terminal')
.get<number>('integrated.fontSize') || 13;
}

private getHtmlContent(): string {
const nonce = getNonce();
const ansiParserJs = fs.readFileSync(
path.join(this.extensionUri.fsPath, 'dist', 'ansiParser.js'), 'utf8'
);
const terminalFontSize = this.getTerminalFontSize();

return /*html*/ `<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -1069,6 +1089,7 @@ export class EspDecoderWebviewPanel implements vscode.WebviewViewProvider {
--warning-fg: var(--vscode-editorWarning-foreground, #fa4);
--success-fg: var(--vscode-terminal-ansiGreen, #4a4);
--link-fg: var(--vscode-textLink-foreground, #3794ff);
--serial-font-size: ${terminalFontSize}px;
}

* {
Expand Down Expand Up @@ -1240,7 +1261,7 @@ export class EspDecoderWebviewPanel implements vscode.WebviewViewProvider {
overflow-x: hidden;
padding: 4px 8px;
font-family: var(--vscode-editor-font-family, 'Courier New', monospace);
font-size: var(--vscode-editor-font-size, 13px);
font-size: var(--serial-font-size, 13px);
line-height: 1.4;
white-space: pre-wrap;
word-break: break-all;
Expand Down Expand Up @@ -2466,6 +2487,9 @@ export class EspDecoderWebviewPanel implements vscode.WebviewViewProvider {
case 'filtersSaved':
showFilterSaveFeedback(msg.ok !== false, msg.error);
break;
case 'fontSizeChanged':
document.documentElement.style.setProperty('--serial-font-size', msg.fontSize + 'px');
break;
}
});

Expand Down