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

Render using canvas #938

Merged
merged 108 commits into from
Sep 8, 2017
Merged
Changes from 1 commit
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
c6d4c73
Initial prototype
Tyriar Aug 30, 2017
640cd18
Support bold, underline, fix colors
Tyriar Aug 31, 2017
e98794a
progress
Tyriar Aug 31, 2017
5ce39d3
GPU ascii rendering
Tyriar Aug 31, 2017
137847e
Linkify all rows at once to prevent multiple timeout restarts
Tyriar Aug 31, 2017
0db42e2
Pull bg rendering into an IRenderLayer
Tyriar Aug 31, 2017
5961bdb
typescript@2.3.0 for ImageBitmap interface
Tyriar Aug 31, 2017
2cb6593
Move fg rendering into IRenderLayer
Tyriar Aug 31, 2017
18e1134
Tidy up
Tyriar Aug 31, 2017
129633a
Only draw background when needed
Tyriar Aug 31, 2017
d93a803
Draw unicode characters
Tyriar Aug 31, 2017
6a0b9bd
Only render fg cells if there are changes
Tyriar Aug 31, 2017
1291dc5
Support inverse
Tyriar Aug 31, 2017
a224ed7
Move canvas Renderer into folder
Tyriar Aug 31, 2017
7aff45c
Remove additional frame skipping as rendering is so fast now
Tyriar Aug 31, 2017
5953bba
Start SelectionRenderLayer
Tyriar Aug 31, 2017
3d1bb2c
Support selection
Tyriar Aug 31, 2017
d601f0a
Hang on to selection state to avoid redrawing
Tyriar Aug 31, 2017
dff3d16
Support 256 color
Tyriar Aug 31, 2017
d3650d9
Draw selection underneath foreground
Tyriar Aug 31, 2017
fd18f7c
Support basic cursor
Tyriar Sep 1, 2017
a91380a
Pull common parts into BaseRenderLayer
Tyriar Sep 1, 2017
fe7b424
Move char atlas into BaseRenderLayer
Tyriar Sep 1, 2017
1998675
Move char drawing to base and use in cursor layer
Tyriar Sep 1, 2017
c888241
Simplify color generation code
Tyriar Sep 1, 2017
15c73ef
Add fontSize and fontFamily options
Tyriar Sep 1, 2017
6588e9e
Fix cursor which cursor character is rendered
Tyriar Sep 1, 2017
9323833
Move scaledCharWidth/Height into base render layer
Tyriar Sep 1, 2017
5109403
Provide convenience draw methods that deal with cells
Tyriar Sep 1, 2017
42e5b34
Don't clear fg char if it's null or ' '
Tyriar Sep 1, 2017
81d93b8
Ensure CharMeasure exposes integers
Tyriar Sep 1, 2017
848c85c
Fix more cases where ' ' doesn't have code
Tyriar Sep 1, 2017
882d7e4
Add basic support for cursor blinking
Tyriar Sep 1, 2017
3fc500b
Pull cursor animation state management into a helper class
Tyriar Sep 1, 2017
076156b
Properly support blinking cursors
Tyriar Sep 1, 2017
62fea4d
Add theme support
Tyriar Sep 1, 2017
bc3bdac
Add a char atlas cache to allow different styles+reuse across terminals
Tyriar Sep 1, 2017
de4fcb9
Merge render layer interface types
Tyriar Sep 1, 2017
2c9dbc6
Add some jsdoc
Tyriar Sep 1, 2017
bf95333
Fix the fit addon
Tyriar Sep 2, 2017
1f444b1
Support invisible attr
Tyriar Sep 2, 2017
70764a7
Use the proper bg/fg colors for inverse attr
Tyriar Sep 2, 2017
b0653fe
Support underline
Tyriar Sep 2, 2017
5cd189e
Fix demo pty size
Tyriar Sep 2, 2017
6ee8e91
Remove some old dead code
Tyriar Sep 2, 2017
b57b94a
Improve focus/blur state, fire only once
Tyriar Sep 2, 2017
dc1e727
Support blurred cursor
Tyriar Sep 2, 2017
4919c40
Add cursor to ITheme
Tyriar Sep 2, 2017
f8ece10
Rerender cursor if state changes
Tyriar Sep 2, 2017
06b5458
Fix cursor render when after focusing underline/bar
Tyriar Sep 2, 2017
cf7237d
Fix remaining cursor animation state issues
Tyriar Sep 2, 2017
36a723c
Fix 256 FG chars
Tyriar Sep 2, 2017
6dd6d03
Add cell spacing to char atlas
Tyriar Sep 2, 2017
ae72e1c
Fix uncached chars bleeding into other cells
Tyriar Sep 2, 2017
32a3c98
Support wide character drawing and cursors
Tyriar Sep 2, 2017
b8732a2
Support Safari
Tyriar Sep 2, 2017
ee4b71c
Remove Terminal.options.colors
Tyriar Sep 2, 2017
9cabb93
Organize temporary color handling code
Tyriar Sep 2, 2017
c92a2f9
Support lineHeight
Tyriar Sep 2, 2017
66d41fe
Expose setTheme through .d.ts
Tyriar Sep 2, 2017
24a98f2
Remove rowContainer and children, disable Linkifier
Tyriar Sep 2, 2017
8039fd3
Remove unused CSS, selectionElement
Tyriar Sep 2, 2017
4f81cdf
Make the terminal background theme aware
Tyriar Sep 2, 2017
c5a6d96
Remove padding from terminal, not support atm
Tyriar Sep 2, 2017
7ccac09
Fix the composition element's position
Tyriar Sep 3, 2017
c94e874
Fix CharMeasure getting taller on successive calls
Tyriar Sep 3, 2017
7973b26
Include new options in ITerminalOptions
Tyriar Sep 3, 2017
8427f74
Clear state when resizing as canvases get cleared
Tyriar Sep 3, 2017
fd4e9d8
Fix graphical glitch wide chars would leave behind
Tyriar Sep 3, 2017
5a48516
Prevent updating of invalid terminal row ranges
Tyriar Sep 3, 2017
deb47e2
Fix canvas resizing with non-1 lineHeight
Tyriar Sep 3, 2017
a3297b0
Fix viewport/background size after char size changed
Tyriar Sep 3, 2017
bc3470c
Fix default bold text
Tyriar Sep 3, 2017
48b3745
Ensure char measure's line height isn't influenced by outside
Tyriar Sep 3, 2017
2d1a1bf
Fix inconsistency with lineHeight
Tyriar Sep 3, 2017
5619abe
Basic link support using mouse zone manager
Tyriar Sep 3, 2017
923ea72
Get links working on proper coords
Tyriar Sep 3, 2017
b30cb58
Support hover callback in links
Tyriar Sep 3, 2017
17731c3
Support multiple links in a line, fix Linkifier tests
Tyriar Sep 3, 2017
e518ea0
Get tests reporting failures again
Tyriar Sep 3, 2017
3677818
Fix tests
Tyriar Sep 3, 2017
e123dd1
Null check if clicking on scroll bar
Tyriar Sep 4, 2017
7934e05
jsdoc Linkifier
Tyriar Sep 4, 2017
e77f1a9
Use default colors if not defined in a theme
Tyriar Sep 4, 2017
29a7ee3
Fix lint
Tyriar Sep 4, 2017
0bfdff0
Theme unfocused cursor using cursor color
Tyriar Sep 4, 2017
ff31f34
Add selection to ITheme
Tyriar Sep 4, 2017
a179502
Support emoji
Tyriar Sep 4, 2017
1c3028c
Work around an emoji bug
Tyriar Sep 4, 2017
a35cf02
Add GridCache tests
Tyriar Sep 4, 2017
6f6f17f
Add tests for ColorManager
Tyriar Sep 4, 2017
1f38c2f
Remove unused file
Tyriar Sep 4, 2017
9506c01
Add tests for utils/Mouse
Tyriar Sep 4, 2017
da1e3b4
Don't use ImageBitmap on Firefox
Tyriar Sep 4, 2017
8e07af0
Drop support for IE/Opera and indicate latest
Tyriar Sep 4, 2017
0dc24cf
Move theme setting into setOption API
Tyriar Sep 4, 2017
46b0857
Resolve TODOs
Tyriar Sep 4, 2017
1e728d4
Add new API to typings test
Tyriar Sep 4, 2017
5c2d5dc
Document methods of BaseRenderLayer
Tyriar Sep 5, 2017
7b199ac
Some more documentation
Tyriar Sep 5, 2017
b69ff5d
Redraw terminal when devicePixelRatio changes
Tyriar Sep 6, 2017
fb90c98
Fix blurry text by supporting floating pt devicePixelRatios
Tyriar Sep 6, 2017
66c891d
Fix resize adding right padding on demo
Tyriar Sep 6, 2017
e960a0a
Add ILinkMatcherOptions.hoverEndCallback
Tyriar Sep 6, 2017
67962a5
typescript@2.4
Tyriar Sep 7, 2017
ea8dbbd
Underline links on hover
Tyriar Sep 7, 2017
75b91c6
Update license text
Tyriar Sep 8, 2017
0c19bc9
Fix tests
Tyriar Sep 8, 2017
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
Next Next commit
Initial prototype
  • Loading branch information
Tyriar committed Aug 30, 2017
commit c6d4c73c8a8c23ce102918fc0342cf33d2986711
2 changes: 2 additions & 0 deletions src/Interfaces.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ export interface ITerminal extends IEventEmitter {
element: HTMLElement;
rowContainer: HTMLElement;
selectionContainer: HTMLElement;
canvasElement: HTMLCanvasElement;
canvasContext: CanvasRenderingContext2D;
selectionManager: ISelectionManager;
charMeasure: ICharMeasure;
textarea: HTMLTextAreaElement;
76 changes: 75 additions & 1 deletion src/Renderer.ts
Original file line number Diff line number Diff line change
@@ -97,7 +97,8 @@ export class Renderer {
}
this._refreshRowsQueue = [];
this._refreshAnimationFrame = null;
this._refresh(start, end);
// this._refresh(start, end);
this._canvasRender(start, end);
}

/**
@@ -323,6 +324,79 @@ export class Renderer {
this._terminal.emit('refresh', {start, end});
};

private _imageDataCache = {};
private _colors = [
// dark:
'#2e3436',
'#cc0000',
'#4e9a06',
'#c4a000',
'#3465a4',
'#75507b',
'#06989a',
'#d3d7cf',
// bright:
'#555753',
'#ef2929',
'#8ae234',
'#fce94f',
'#729fcf',
'#ad7fa8',
'#34e2e2',
'#eeeeec'
];

private _canvasRender(start: number, end: number): void {
const charWidth = Math.ceil(this._terminal.charMeasure.width);
const charHeight = Math.ceil(this._terminal.charMeasure.height);
const ctx = this._terminal.canvasContext;
ctx.font = '16px Hack';
ctx.fillStyle = '#000000';
// console.log('fill', start, end);
// console.log('fill', start * charHeight, (end - start + 1) * charHeight);
ctx.fillRect(0, start * charHeight, charWidth * this._terminal.cols, (end - start + 1) * charHeight);
ctx.fillStyle = 'rgb(255, 255, 255)';
ctx.textBaseline = 'top';

for (let y = start; y <= end; y++) {
let row = y + this._terminal.buffer.ydisp;
let line = this._terminal.buffer.lines.get(row);
for (let x = 0; x < this._terminal.cols; x++) {
let data: any = line[x][0];
const ch = line[x][CHAR_DATA_CHAR_INDEX];

// if (ch === ' ') {
// continue;
// }

let bg = data & 0x1ff;
let fg = (data >> 9) & 0x1ff;
let flags = data >> 18;

// if (bg < 16) {
// }

if (fg < 16) {
ctx.fillStyle = this._colors[fg];
}

// let imageData;
// let key = ch + fg;
// if (key in this._imageDataCache) {
// imageData = this._imageDataCache[key];
// } else {
ctx.fillText(ch, x * charWidth, y * charHeight);
// imageData = ctx.getImageData(x * charWidth, y * charHeight, charWidth, charHeight);
// this._imageDataCache[key] = imageData;
// }

// ctx.fillText(ch, x * charWidth, y * charHeight);
// ctx.putImageData(imageData, x * charWidth, y * charHeight);
}
}
this._imageDataCache = {};
}

/**
* Refreshes the selection in the DOM.
* @param start The selection start.
13 changes: 13 additions & 0 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
@@ -175,6 +175,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
private body: HTMLBodyElement;
private viewportScrollArea: HTMLElement;
private viewportElement: HTMLElement;
public canvasElement: HTMLCanvasElement;
public canvasContext: CanvasRenderingContext2D;
public selectionContainer: HTMLElement;
private helperContainer: HTMLElement;
private compositionView: HTMLElement;
@@ -703,6 +705,12 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.selectionContainer.classList.add('xterm-selection');
this.element.appendChild(this.selectionContainer);


this.canvasElement = document.createElement('canvas');
this.canvasContext = this.canvasElement.getContext('2d');
this.element.appendChild(this.canvasElement);


// Create the container that will hold the lines of the terminal and then
// produce the lines the lines.
this.rowContainer = document.createElement('div');
@@ -746,6 +754,11 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
});
this.charMeasure.measure();

this.charMeasure.on('charsizechanged', () => {
this.canvasElement.setAttribute('width', `${Math.ceil(this.charMeasure.width) * this.cols}px`);
this.canvasElement.setAttribute('height', `${Math.ceil(this.charMeasure.height) * this.rows}px`);
});

this.viewport = new Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
this.renderer = new Renderer(this);
this.selectionManager = new SelectionManager(this, this.buffer, this.rowContainer, this.charMeasure);