From 7da401ae60cfcc7cf3489aac583f31b4aec4d2b6 Mon Sep 17 00:00:00 2001 From: Vincent Fugnitto Date: Thu, 5 Mar 2020 11:11:58 -0500 Subject: [PATCH] terminal: additional preferences to control opts This commit adds additional `preferences` to control the options passed to `xterm`. The commit includes the following new preferences: - `terminal.integrated.drawBoldTextInBrightColors` - `terminal.integrated.fastScrollSensitivity` - `terminal.integrated.cursorBlinking` - `terminal.integrated.cursorStyle` - `terminal.integrated.cursorWidth` Signed-off-by: Vincent Fugnitto --- .../src/browser/terminal-preferences.ts | 38 +++++++++++++++++-- .../src/browser/terminal-widget-impl.ts | 17 ++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/packages/terminal/src/browser/terminal-preferences.ts b/packages/terminal/src/browser/terminal-preferences.ts index e205dc2bcd9d3..8ab087251a77a 100644 --- a/packages/terminal/src/browser/terminal-preferences.ts +++ b/packages/terminal/src/browser/terminal-preferences.ts @@ -54,6 +54,11 @@ export const TerminalConfigSchema: PreferenceSchema = { description: 'The font weight to use within the terminal for bold text.', default: 'bold' }, + 'terminal.integrated.drawBoldTextInBrightColors': { + description: 'Controls whether to draw bold text in bright colors.', + type: 'boolean', + default: true, + }, 'terminal.integrated.letterSpacing': { description: 'Controls the letter spacing of the terminal, this is an integer value which represents the amount of additional pixels to add between characters.', type: 'number', @@ -70,6 +75,11 @@ export const TerminalConfigSchema: PreferenceSchema = { type: 'number', default: 1000 }, + 'terminal.integrated.fastScrollSensitivity': { + description: 'Controls the scrolling speed when pressing \'alt\'.', + type: 'number', + default: 5, + }, 'terminal.integrated.rendererType': { description: 'Controls how the terminal is rendered.', type: 'string', @@ -80,7 +90,22 @@ export const TerminalConfigSchema: PreferenceSchema = { description: 'Controls whether text selected in the terminal will be copied to the clipboard.', type: 'boolean', default: false, - } + }, + 'terminal.integrated.cursorBlinking': { + description: 'Controls whether the terminal cursor blinks.', + type: 'boolean', + default: false + }, + 'terminal.integrated.cursorStyle': { + description: 'Controls the style of the terminal cursor/', + enum: ['block', 'underline', 'line'], + default: 'block' + }, + 'terminal.integrated.cursorWidth': { + description: 'Controls the width of the cursor when \'cursorStyle\' is set to \'line\'.', + type: 'number', + default: 1 + }, } }; @@ -90,16 +115,23 @@ export interface TerminalConfiguration { 'terminal.integrated.fontFamily': string 'terminal.integrated.fontSize': number 'terminal.integrated.fontWeight': FontWeight - 'terminal.integrated.fontWeightBold': FontWeight + 'terminal.integrated.fontWeightBold': FontWeight, + 'terminal.integrated.drawBoldTextInBrightColors': boolean, 'terminal.integrated.letterSpacing': number 'terminal.integrated.lineHeight': number, 'terminal.integrated.scrollback': number, + 'terminal.integrated.fastScrollSensitivity': number, 'terminal.integrated.rendererType': TerminalRendererType, 'terminal.integrated.copyOnSelection': boolean, + 'terminal.integrated.cursorBlinking': boolean, + 'terminal.integrated.cursorStyle': CursorStyleVSCode, + 'terminal.integrated.cursorWidth': number } type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'; - +export type CursorStyle = 'block' | 'underline' | 'bar'; +// VS Code uses 'line' to represent 'bar'. The following conversion is necessary to support their preferences. +export type CursorStyleVSCode = CursorStyle | 'line'; export type TerminalRendererType = 'canvas' | 'dom'; export const DEFAULT_TERMINAL_RENDERER_TYPE = 'canvas'; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/packages/terminal/src/browser/terminal-widget-impl.ts b/packages/terminal/src/browser/terminal-widget-impl.ts index 7abab545f1e2d..16c2eab99443c 100644 --- a/packages/terminal/src/browser/terminal-widget-impl.ts +++ b/packages/terminal/src/browser/terminal-widget-impl.ts @@ -28,7 +28,7 @@ import { TerminalWatcher } from '../common/terminal-watcher'; import { TerminalWidgetOptions, TerminalWidget } from './base/terminal-widget'; import { MessageConnection } from 'vscode-jsonrpc'; import { Deferred } from '@theia/core/lib/common/promise-util'; -import { TerminalPreferences, TerminalRendererType, isTerminalRendererType, DEFAULT_TERMINAL_RENDERER_TYPE } from './terminal-preferences'; +import { TerminalPreferences, TerminalRendererType, isTerminalRendererType, DEFAULT_TERMINAL_RENDERER_TYPE, CursorStyle } from './terminal-preferences'; import { TerminalContribution } from './terminal-contribution'; import URI from '@theia/core/lib/common/uri'; import { TerminalService } from './base/terminal-service'; @@ -93,14 +93,18 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget this.addClass('terminal-container'); this.term = new Terminal({ - cursorBlink: false, + cursorBlink: this.preferences['terminal.integrated.cursorBlinking'], + cursorStyle: this.getCursorStyle(), + cursorWidth: this.preferences['terminal.integrated.cursorWidth'], fontFamily: this.preferences['terminal.integrated.fontFamily'], fontSize: this.preferences['terminal.integrated.fontSize'], fontWeight: this.preferences['terminal.integrated.fontWeight'], fontWeightBold: this.preferences['terminal.integrated.fontWeightBold'], + drawBoldTextInBrightColors: this.preferences['terminal.integrated.drawBoldTextInBrightColors'], letterSpacing: this.preferences['terminal.integrated.letterSpacing'], lineHeight: this.preferences['terminal.integrated.lineHeight'], scrollback: this.preferences['terminal.integrated.scrollback'], + fastScrollSensitivity: this.preferences['terminal.integrated.fastScrollSensitivity'], rendererType: this.getTerminalRendererType(this.preferences['terminal.integrated.rendererType']), theme: this.themeService.theme }); @@ -204,6 +208,15 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget this.toDispose.push(this.searchBox); } + /** + * Get the cursor style compatible with `xterm`. + * @returns CursorStyle + */ + private getCursorStyle(): CursorStyle { + const value = this.preferences['terminal.integrated.cursorStyle']; + return value === 'line' ? 'bar' : value; + } + /** * Returns given renderer type if it is valid and supported or default renderer otherwise. *