Skip to content

Commit

Permalink
terminal: additional preferences to control opts
Browse files Browse the repository at this point in the history
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 <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Mar 5, 2020
1 parent 42b73d5 commit 7da401a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
38 changes: 35 additions & 3 deletions packages/terminal/src/browser/terminal-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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
},
}
};

Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 7da401a

Please sign in to comment.