Skip to content

Commit

Permalink
Add terminal renderer option into terminal preferences
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun committed Oct 30, 2019
1 parent 2da0870 commit 8dae863
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packages/terminal/src/browser/terminal-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ export const TerminalConfigSchema: PreferenceSchema = {
'terminal.integrated.scrollback': {
description: 'Controls the maximum amount of lines the terminal keeps in its buffer.',
type: 'number',
default: 1000,
default: 1000
},
'terminal.integrated.rendererType': {
description: 'Controls how the terminal is rendered.',
type: 'string',
enum: ['canvas', 'dom'],
default: 'canvas'
}
}
};
Expand All @@ -83,10 +89,18 @@ export interface TerminalConfiguration {
'terminal.integrated.letterSpacing': number
'terminal.integrated.lineHeight': number,
'terminal.integrated.scrollback': number,
'terminal.integrated.rendererType': TerminalRendererType
}

type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';

export type TerminalRendererType = 'canvas' | 'dom';
export const DEFAULT_TERMINAL_RENDERER_TYPE = 'canvas';
// tslint:disable-next-line:no-any
export function isTerminalRendererType(arg: any): arg is TerminalRendererType {
return typeof arg === 'string' && (arg === 'canvas' || arg === 'dom');
}

export const TerminalPreferences = Symbol('TerminalPreferences');
export type TerminalPreferences = PreferenceProxy<TerminalConfiguration>;

Expand Down
27 changes: 25 additions & 2 deletions packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { ThemeService } from '@theia/core/lib/browser/theming';
import { TerminalWidgetOptions, TerminalWidget } from './base/terminal-widget';
import { MessageConnection } from 'vscode-jsonrpc';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { TerminalPreferences } from './terminal-preferences';
import { TerminalPreferences, TerminalRendererType, isTerminalRendererType, DEFAULT_TERMINAL_RENDERER_TYPE } 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 @@ -109,6 +109,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
letterSpacing: this.preferences['terminal.integrated.letterSpacing'],
lineHeight: this.preferences['terminal.integrated.lineHeight'],
scrollback: this.preferences['terminal.integrated.scrollback'],
rendererType: this.getTerminalRendererType(this.preferences['terminal.integrated.rendererType']),
theme: {
foreground: cssProps.foreground,
background: cssProps.background,
Expand Down Expand Up @@ -137,7 +138,17 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
const lastSeparator = change.preferenceName.lastIndexOf('.');
if (lastSeparator > 0) {
const preferenceName = change.preferenceName.substr(lastSeparator + 1);
this.term.setOption(preferenceName, this.preferences[change.preferenceName]);
let preferenceValue = this.preferences[change.preferenceName];

if (preferenceName === 'rendererType') {
const newRendererType: string = this.preferences[change.preferenceName] as string;
if (newRendererType !== this.getTerminalRendererType(newRendererType)) {
// given terminal renderer type is not supported or invalid
preferenceValue = DEFAULT_TERMINAL_RENDERER_TYPE;
}
}

this.term.setOption(preferenceName, preferenceValue);
this.needsResize = true;
this.update();
}
Expand Down Expand Up @@ -191,6 +202,18 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
}
}

/**
* Returns given renderer type if it is valid and supported or default renderer otherwise.
*
* @param terminalRendererType desired terminal renderer type
*/
private getTerminalRendererType(terminalRendererType?: string | TerminalRendererType): Xterm.RendererType {
if (terminalRendererType && isTerminalRendererType(terminalRendererType)) {
return terminalRendererType;
}
return DEFAULT_TERMINAL_RENDERER_TYPE;
}

showHoverMessage(x: number, y: number, message: string): void {
this.hoverMessage.innerText = message;
this.hoverMessage.style.display = 'inline';
Expand Down

0 comments on commit 8dae863

Please sign in to comment.