-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial decorations API #3302
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, ITerminalAddon, ISelectionPosition, IBuffer as IBufferApi, IBufferNamespace as IBufferNamespaceApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi, IParser, IFunctionIdentifier, ILinkProvider, IUnicodeHandling, IUnicodeVersionProvider, FontWeight } from 'xterm'; | ||
import { ITerminal } from 'browser/Types'; | ||
import { IBufferLine, ICellData } from 'common/Types'; | ||
import { IBufferLine, ICellData, IDecorationElement, IDecorationHandle } from 'common/Types'; | ||
import { IBuffer, IBufferSet } from 'common/buffer/Types'; | ||
import { CellData } from 'common/buffer/CellData'; | ||
import { Terminal as TerminalCore } from '../Terminal'; | ||
|
@@ -175,6 +175,16 @@ export class Terminal implements ITerminalApi { | |
public paste(data: string): void { | ||
this._core.paste(data); | ||
} | ||
public addDecoration(element: IDecorationElement): IDecorationHandle | undefined { | ||
return this._core.addDecoration(element); | ||
} | ||
public removeDeoration(handle: IDecorationHandle): boolean { | ||
return this._core.removeDeoration(handle); | ||
} | ||
Comment on lines
+178
to
+183
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've started moving towards returning registerDecoration(range: IBufferRange): IDecoration;
interface IDecoration extends IDisposable {
// This uses a setter and is implemented by the core so changes can
// be applied immediately
range: IBufferRange;
// This will give ultimate flexibility, perf will probably be fine unless the terminal is covered in decorations
readonly element: HTMLElement;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
public clearDecorations(): number { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think we need a return type here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort of success value for removal - I can remove it. |
||
return this._core.clearDecorations(); | ||
} | ||
|
||
public getOption(key: 'bellSound' | 'bellStyle' | 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string; | ||
public getOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'popOnBell' | 'visualBell'): boolean; | ||
public getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2017 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { IRenderDimensions } from 'browser/renderer/Types'; | ||
import { BaseRenderLayer } from 'browser/renderer/BaseRenderLayer'; | ||
import { IColorSet } from 'browser/Types'; | ||
import { IBufferService, IOptionsService } from 'common/services/Services'; | ||
import { IDecorationService } from 'browser/services/Services'; | ||
|
||
|
||
export class DecorationRenderLayer extends BaseRenderLayer { | ||
|
||
private _decorationService: IDecorationService; | ||
|
||
constructor( | ||
container: HTMLElement, | ||
zIndex: number, | ||
colors: IColorSet, | ||
rendererId: number, | ||
@IDecorationService decorationService: IDecorationService, | ||
@IBufferService bufferService: IBufferService, | ||
@IOptionsService optionsService: IOptionsService, | ||
) { | ||
super(container, 'decorations', zIndex, true, colors, rendererId, bufferService, optionsService); | ||
this._decorationService = decorationService; | ||
} | ||
|
||
public reset(): void { | ||
this._clearAll(); | ||
} | ||
|
||
public onDecorationsChanged(): void { | ||
// Remove all decorations | ||
this._clearAll(); | ||
|
||
this._decorationService.forEachDecoration((element) => { | ||
// Translate from buffer position to viewport position | ||
const viewportStartRow = element.startRow - this._bufferService.buffer.ydisp; | ||
const viewportEndRow = element.endRow - this._bufferService.buffer.ydisp; | ||
const viewportCappedStartRow = Math.max(viewportStartRow, 0); | ||
const viewportCappedEndRow = Math.min(viewportEndRow, this._bufferService.rows - 1); | ||
const width = element.endColumn - element.startColumn; | ||
const height = viewportCappedEndRow - viewportCappedStartRow + 1; | ||
if (viewportStartRow <= viewportEndRow) { | ||
if (element.fillStyle) { | ||
this._ctx.fillStyle = element.fillStyle; | ||
this._fillCells(element.startColumn, viewportCappedStartRow, width, height); | ||
} | ||
if (element.strokeStyle) { | ||
this._ctx.strokeStyle = element.strokeStyle; | ||
this._strokeRectAtCell(element.startColumn, viewportCappedStartRow, width, height); | ||
} | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual API is declared in xterm.d.ts so the new interface will need to go there.