Skip to content
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

cell representation for joined cells #2035

Merged
merged 4 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/renderer/BaseRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BaseCharAtlas from './atlas/BaseCharAtlas';
import { acquireCharAtlas } from './atlas/CharAtlasCache';
import { CellData, AttributeData } from '../BufferLine';
import { WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE } from '../Buffer';
import { JoinedCellData } from './CharacterJoinerRegistry';

export abstract class BaseRenderLayer implements IRenderLayer {
private _canvas: HTMLCanvasElement;
Expand Down Expand Up @@ -261,7 +262,10 @@ export abstract class BaseRenderLayer implements IRenderLayer {
protected drawChars(terminal: ITerminal, cell: ICellData, x: number, y: number): void {

// skip cache right away if we draw in RGB
if (cell.isFgRGB() || cell.isBgRGB()) {
// Note: to avoid bad runtime JoinedCellData will be skipped
// in the cache handler (atlasDidDraw == false) itself and
// fall through to uncached later down below
if (cell.isFgRGB() || cell.isBgRGB() || cell instanceof JoinedCellData) {
jerch marked this conversation as resolved.
Show resolved Hide resolved
this._drawUncachedChars(terminal, cell, x, y);
return;
}
Expand Down
49 changes: 47 additions & 2 deletions src/renderer/CharacterJoinerRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
import { ITerminal, IBufferLine } from '../Types';
import { ITerminal, IBufferLine, ICellData, CharData } from '../Types';
import { ICharacterJoinerRegistry, ICharacterJoiner } from './Types';
import { CellData } from '../BufferLine';
import { CellData, Content, AttributeData } from '../BufferLine';
import { WHITESPACE_CELL_CHAR } from '../Buffer';

export class JoinedCellData extends AttributeData implements ICellData {
private _width: number;
// .content carries no meaning for joined CellData, simply nullify it
// thus we have to overload all other .content accessors
public content: number = 0;
public fg: number;
public bg: number;
public combinedData: string = '';

constructor(firstCell: ICellData, chars: string, width: number) {
super();
this.fg = firstCell.fg;
this.bg = firstCell.bg;
this.combinedData = chars;
this._width = width;
}

public isCombined(): number {
// always mark joined cell data as combined
return Content.IS_COMBINED_MASK;
}

public getWidth(): number {
return this._width;
}

public getChars(): string {
return this.combinedData;
}

public getCode(): number {
// code always gets the highest possible fake codepoint (read as -1)
// this is needed as code is used by caches as identifier
return 0x1FFFFF;
}

public setFromCharData(value: CharData): void {
throw new Error('not implemented');
}

public getAsCharData(): CharData {
return [this.fg, this.getChars(), this.getWidth(), this.getCode()];
}
}

export class CharacterJoinerRegistry implements ICharacterJoinerRegistry {

private _characterJoiners: ICharacterJoiner[] = [];
Expand Down
14 changes: 6 additions & 8 deletions src/renderer/TextRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CharData, ITerminal, ICellData } from '../Types';
import { GridCache } from './GridCache';
import { BaseRenderLayer } from './BaseRenderLayer';
import { CellData, AttributeData, Content } from '../BufferLine';
import { JoinedCellData } from './CharacterJoinerRegistry';

/**
* This CharData looks like a null character, which will forc a clear and render
Expand Down Expand Up @@ -89,15 +90,12 @@ export class TextRenderLayer extends BaseRenderLayer {

// We already know the exact start and end column of the joined range,
// so we get the string and width representing it directly
cell = CellData.fromCharData([
0,

cell = new JoinedCellData(
this._workCell,
line.translateToString(true, range[0], range[1]),
range[1] - range[0],
0xFFFFFF
]);
// hacky: patch attrs
cell.fg = this._workCell.fg;
cell.bg = this._workCell.bg;
range[1] - range[0]
);

// Skip over the cells occupied by this range in the loop
lastCharX = range[1] - 1;
Expand Down