Skip to content

Commit b192ba2

Browse files
authored
Merge pull request #5107 from Tyriar/tyriar/overview_ruler
Add top/bottom border overview ruler options
2 parents a7952ff + bf41eb4 commit b192ba2

File tree

9 files changed

+51
-22
lines changed

9 files changed

+51
-22
lines changed

addons/addon-fit/src/FitAddon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class FitAddon implements ITerminalAddon , IFitApi {
6767

6868
const scrollbarWidth = (this._terminal.options.scrollback === 0
6969
? 0
70-
: (this._terminal.options.overviewRulerWidth || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH));
70+
: (this._terminal.options.overviewRuler?.width || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH));
7171

7272
const parentElementStyle = window.getComputedStyle(this._terminal.element.parentElement);
7373
const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));

demo/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,10 @@ function initOptions(term: Terminal): void {
427427
'termName',
428428
'cols', 'rows', // subsumed by "size" (colsRows) option
429429
// Complex option
430+
'documentOverride',
430431
'linkHandler',
431432
'logger',
433+
'overviewRuler',
432434
'theme',
433435
'windowOptions',
434436
'windowsPty',
@@ -1159,7 +1161,7 @@ function addGraphemeClusters(): void {
11591161
}
11601162

11611163
function addDecoration(): void {
1162-
term.options['overviewRulerWidth'] = 15;
1164+
term.options['overviewRuler'] = { width: 14 };
11631165
const marker = term.registerMarker(1);
11641166
const decoration = term.registerDecoration({
11651167
marker,
@@ -1174,7 +1176,7 @@ function addDecoration(): void {
11741176
}
11751177

11761178
function addOverviewRuler(): void {
1177-
term.options['overviewRulerWidth'] = 15;
1179+
term.options['overviewRuler'] = { width: 14 };
11781180
term.registerDecoration({ marker: term.registerMarker(1), overviewRulerOptions: { color: '#ef2929' } });
11791181
term.registerDecoration({ marker: term.registerMarker(3), overviewRulerOptions: { color: '#8ae234' } });
11801182
term.registerDecoration({ marker: term.registerMarker(5), overviewRulerOptions: { color: '#729fcf' } });

src/browser/CoreBrowserTerminal.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,11 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
549549
}
550550
this.register(this.optionsService.onSpecificOptionChange('screenReaderMode', e => this._handleScreenReaderModeOptionChange(e)));
551551

552-
if (this.options.overviewRulerWidth) {
552+
if (this.options.overviewRuler.width) {
553553
this._overviewRulerRenderer = this.register(this._instantiationService.createInstance(OverviewRulerRenderer, this._viewportElement, this.screenElement));
554554
}
555-
this.optionsService.onSpecificOptionChange('overviewRulerWidth', value => {
556-
if (!this._overviewRulerRenderer && value && this._viewportElement && this.screenElement) {
555+
this.optionsService.onSpecificOptionChange('overviewRuler', value => {
556+
if (!this._overviewRulerRenderer && value.width && this._viewportElement && this.screenElement) {
557557
this._overviewRulerRenderer = this.register(this._instantiationService.createInstance(OverviewRulerRenderer, this._viewportElement, this.screenElement));
558558
}
559559
});

src/browser/Viewport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class Viewport extends Disposable {
6060
this.register(this._optionsService.onMultipleOptionChange([
6161
'scrollSensitivity',
6262
'fastScrollSensitivity',
63-
'overviewRulerWidth'
63+
'overviewRuler'
6464
], () => this._scrollableElement.updateOptions(this._getChangeOptions())));
6565
// Don't handle mouse wheel if wheel events are supported by the current mouse prototcol
6666
this.register(coreMouseService.onProtocolChange(type => {
@@ -121,7 +121,7 @@ export class Viewport extends Disposable {
121121
return {
122122
mouseWheelScrollSensitivity: this._optionsService.rawOptions.scrollSensitivity,
123123
fastScrollSensitivity: this._optionsService.rawOptions.fastScrollSensitivity,
124-
verticalScrollbarSize: this._optionsService.rawOptions.overviewRulerWidth || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH
124+
verticalScrollbarSize: this._optionsService.rawOptions.overviewRuler?.width || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH
125125
};
126126
}
127127

src/browser/decorations/OverviewRulerRenderer.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class OverviewRulerRenderer extends Disposable {
3838
private readonly _ctx: CanvasRenderingContext2D;
3939
private readonly _colorZoneStore: IColorZoneStore = new ColorZoneStore();
4040
private get _width(): number {
41-
return this._optionsService.options.overviewRulerWidth || 0;
41+
return this._optionsService.options.overviewRuler?.width || 0;
4242
}
4343
private _animationFrame: number | undefined;
4444

@@ -95,7 +95,7 @@ export class OverviewRulerRenderer extends Disposable {
9595
}));
9696

9797
this.register(this._coreBrowserService.onDprChange(() => this._queueRefresh(true)));
98-
this.register(this._optionsService.onSpecificOptionChange('overviewRulerWidth', () => this._queueRefresh(true)));
98+
this.register(this._optionsService.onSpecificOptionChange('overviewRuler', () => this._queueRefresh(true)));
9999
this.register(this._themeService.onChangeColors(() => this._queueRefresh()));
100100
this._queueRefresh(true);
101101
}
@@ -176,6 +176,12 @@ export class OverviewRulerRenderer extends Disposable {
176176
private _renderRulerOutline(): void {
177177
this._ctx.fillStyle = this._themeService.colors.overviewRulerBorder.css;
178178
this._ctx.fillRect(0, 0, Constants.OVERVIEW_RULER_BORDER_WIDTH, this._canvas.height);
179+
if (this._optionsService.rawOptions.overviewRuler.showTopBorder) {
180+
this._ctx.fillRect(Constants.OVERVIEW_RULER_BORDER_WIDTH, 0, this._canvas.width - Constants.OVERVIEW_RULER_BORDER_WIDTH, Constants.OVERVIEW_RULER_BORDER_WIDTH);
181+
}
182+
if (this._optionsService.rawOptions.overviewRuler.showBottomBorder) {
183+
this._ctx.fillRect(Constants.OVERVIEW_RULER_BORDER_WIDTH, this._canvas.height - Constants.OVERVIEW_RULER_BORDER_WIDTH, this._canvas.width - Constants.OVERVIEW_RULER_BORDER_WIDTH, this._canvas.height);
184+
}
179185
}
180186

181187
private _renderColorZone(zone: IColorZone): void {

src/common/services/OptionsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const DEFAULT_OPTIONS: Readonly<Required<ITerminalOptions>> = {
5454
convertEol: false,
5555
termName: 'xterm',
5656
cancelEvents: false,
57-
overviewRulerWidth: 0
57+
overviewRuler: {}
5858
};
5959

6060
const FONT_WEIGHT_OPTIONS: Extract<FontWeight, string>[] = ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'];

src/common/services/Services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @license MIT
44
*/
55

6-
import { IDecoration, IDecorationOptions, ILinkHandler, ILogger, IWindowsPty } from '@xterm/xterm';
6+
import { IDecoration, IDecorationOptions, ILinkHandler, ILogger, IWindowsPty, type IOverviewRulerOptions } from '@xterm/xterm';
77
import { CoreMouseEncoding, CoreMouseEventType, CursorInactiveStyle, CursorStyle, IAttributeData, ICharset, IColor, ICoreMouseEvent, ICoreMouseProtocol, IDecPrivateModes, IDisposable, IModes, IOscLinkData, IWindowOptions } from 'common/Types';
88
import { IBuffer, IBufferSet } from 'common/buffer/Types';
99
import { createDecorator } from 'common/services/ServiceRegistry';
@@ -251,7 +251,7 @@ export interface ITerminalOptions {
251251
windowsPty?: IWindowsPty;
252252
windowOptions?: IWindowOptions;
253253
wordSeparator?: string;
254-
overviewRulerWidth?: number;
254+
overviewRuler?: IOverviewRulerOptions;
255255

256256
[key: string]: any;
257257
cancelEvents: boolean;

test/playwright/Terminal.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ test.describe('API Integration Tests', () => {
760760
await pollFor(ctx.page, `document.querySelectorAll('.xterm-decoration-overview-ruler').length`, 0);
761761
});
762762
test('should add an overview ruler when width is set', async () => {
763-
await openTerminal(ctx, { overviewRulerWidth: 15 });
763+
await openTerminal(ctx, { overviewRuler: { width: 15 } });
764764
await ctx.page.evaluate(`window.marker1 = window.term.registerMarker(1)`);
765765
await ctx.page.evaluate(`window.marker2 = window.term.registerMarker(2)`);
766766
await ctx.page.evaluate(`window.term.registerDecoration({ marker: window.marker1, overviewRulerOptions: { color: 'red', position: 'full' } })`);

typings/xterm.d.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ declare module '@xterm/xterm' {
327327
windowOptions?: IWindowOptions;
328328

329329
/**
330-
* The width, in pixels, of the canvas for the overview ruler. The overview
331-
* ruler will be hidden when not set.
330+
* Controls the visibility and style of the overview ruler which visualizes
331+
* decorations underneath the scroll bar.
332332
*/
333-
overviewRulerWidth?: number;
333+
overviewRuler?: IOverviewRulerOptions;
334334
}
335335

336336
/**
@@ -387,9 +387,8 @@ declare module '@xterm/xterm' {
387387
scrollbarSliderActiveBackground?: string;
388388
/**
389389
* The border color of the overview ruler. This visually separates the
390-
* terminal from the scroll bar when
391-
* {@link ITerminalOptions.overviewRulerWidth overviewRulerWidth} is set.
392-
* When this is not set it defaults to black (`#000000`).
390+
* terminal from the scroll bar when {@link IOverviewRulerOptions.width} is
391+
* set. When this is not set it defaults to black (`#000000`).
393392
*/
394393
overviewRulerBorder?: string;
395394
/** ANSI black (eg. `\x1b[30m`) */
@@ -617,8 +616,8 @@ declare module '@xterm/xterm' {
617616

618617
/**
619618
* When defined, renders the decoration in the overview ruler to the right
620-
* of the terminal. {@link ITerminalOptions.overviewRulerWidth} must be set
621-
* in order to see the overview ruler.
619+
* of the terminal. {@link IOverviewRulerOptions.width} must be set in order
620+
* to see the overview ruler.
622621
* @param color The color of the decoration.
623622
* @param position The position of the decoration.
624623
*/
@@ -641,6 +640,28 @@ declare module '@xterm/xterm' {
641640
tooMuchOutput: string;
642641
}
643642

643+
export interface IOverviewRulerOptions {
644+
/**
645+
* When defined, renders decorations in the overview ruler to the right of
646+
* the terminal. This must be set in order to see the overview ruler.
647+
* @param color The color of the decoration.
648+
* @param position The position of the decoration.
649+
*/
650+
width?: number;
651+
652+
/**
653+
* Whether to show the top border of the overview ruler, which uses the
654+
* {@link ITheme.overviewRulerBorder} color.
655+
*/
656+
showTopBorder?: boolean;
657+
658+
/**
659+
* Whether to show the bottom border of the overview ruler, which uses the
660+
* {@link ITheme.overviewRulerBorder} color.
661+
*/
662+
showBottomBorder?: boolean;
663+
}
664+
644665
/**
645666
* Enable various window manipulation and report features
646667
* (`CSI Ps ; Ps ; Ps t`).

0 commit comments

Comments
 (0)