Skip to content

Commit

Permalink
Merge pull request #2035 from jerch/2028_handle_joined_cells
Browse files Browse the repository at this point in the history
cell representation for joined cells
  • Loading branch information
jerch committed May 6, 2019
2 parents 15a6c98 + c6138ed commit d6da010
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
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) {
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

0 comments on commit d6da010

Please sign in to comment.