Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit b03f564

Browse files
committed
Do not modify screen buffer storage to add a cursor.
1 parent f34697d commit b03f564

File tree

3 files changed

+25
-34
lines changed

3 files changed

+25
-34
lines changed

src/ANSIParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,6 @@ function or1(value: number | undefined) {
565565

566566
// TODO: Move to
567567
function logPosition(buffer: ScreenBuffer) {
568-
const position = buffer.cursorPosition;
569-
debug(`%crow: ${position.row}\tcolumn: ${position.column}\t value: ${buffer.at(position)}`, "color: green");
568+
const position = {row: buffer.cursorRow, column: buffer.cursorColumn};
569+
debug(`%crow: ${position.row}\tcolumn: ${buffer.cursorColumn}\t value: ${buffer.at(position)}`, "color: green");
570570
}

src/ScreenBuffer.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,36 +91,12 @@ export class ScreenBuffer extends events.EventEmitter {
9191
this._attributes = attributesFlyweight({...this._attributes, ...attributes});
9292
}
9393

94-
toRenderable(status: e.Status, fromStorage = this.storage): List<List<Char>> {
95-
let storage = fromStorage;
96-
97-
if (status === e.Status.InProgress && (this._showCursor || this._blinkCursor)) {
98-
const cursorRow = this.cursorRow - (this.storage.size - fromStorage.size);
99-
const cursorColumn = this.cursorColumn;
100-
101-
const cursorCoordinates = [cursorRow, cursorColumn];
102-
103-
if (!storage.get(cursorRow)) {
104-
storage = storage.set(cursorRow, List<Char>(Array(cursorColumn).fill(Char.empty)));
105-
}
106-
107-
108-
if (!storage.getIn(cursorCoordinates)) {
109-
storage = storage.setIn(cursorCoordinates, Char.empty);
110-
}
111-
112-
let char: Char = storage.getIn(cursorCoordinates);
113-
storage = storage.setIn(
114-
cursorCoordinates,
115-
Char.flyweight(char.toString(), {...char.attributes, cursor: true}),
116-
);
117-
}
118-
119-
return storage;
94+
toRenderable(fromStorage = this.storage): List<List<Char>> {
95+
return fromStorage;
12096
}
12197

122-
toCutRenderable(status: e.Status): List<List<Char>> {
123-
return this.toRenderable(status, <List<List<Char>>>(this.storage.takeLast(ScreenBuffer.hugeOutputThreshold)));
98+
toCutRenderable(): List<List<Char>> {
99+
return this.toRenderable(<List<List<Char>>>(this.storage.takeLast(ScreenBuffer.hugeOutputThreshold)));
124100
}
125101

126102
toLines(): string[] {

src/views/BufferComponent.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Cut extends React.Component<CutProps, CutState> {
4040
}
4141
interface RowProps {
4242
row: List<Char>;
43+
hasCursor: boolean;
4344
status: Status;
4445
job: Job;
4546
}
@@ -48,11 +49,22 @@ const charGrouper = (a: Char, b: Char) => a.attributes === b.attributes;
4849

4950
class RowComponent extends React.Component<RowProps, {}> {
5051
shouldComponentUpdate(nextProps: RowProps) {
51-
return this.props.row !== nextProps.row || this.props.status !== nextProps.status;
52+
return this.props.row !== nextProps.row ||
53+
this.props.status !== nextProps.status ||
54+
this.props.hasCursor !== nextProps.hasCursor;
5255
}
5356

5457
render() {
55-
const rowWithoutHoles = this.props.row.toArray().map(char => char || Char.empty);
58+
const rowWithoutHoles = this.props.row.toArray().map((char, index) => {
59+
const char2 = char || Char.empty;
60+
const attributes = (this.props.hasCursor && index === this.props.job.screenBuffer.cursorColumn) ?
61+
{...char2.attributes, cursor: true} :
62+
char2.attributes;
63+
64+
return Char.flyweight(char2.toString(), attributes);
65+
66+
});
67+
5668
const charGroups = groupWhen(charGrouper, rowWithoutHoles).map((charGroup: Char[], index: number) =>
5769
<CharGroupComponent job={this.props.job} group={charGroup} key={index}/>,
5870
);
@@ -78,14 +90,17 @@ export class BufferComponent extends React.Component<Props, State> {
7890
}
7991

8092
render() {
93+
const buffer = this.props.job.screenBuffer;
94+
8195
return (
8296
<div className="output"
8397
style={css.output(this.props.job.screenBuffer.activeScreenBufferType, this.props.job.status)}>
8498
{this.shouldCutOutput ? <Cut job={this.props.job} clickHandler={() => this.setState({ expandButtonPressed: true })}/> : undefined}
85-
{this.renderableRows.map((row, index) =>
99+
{this.renderableRows.map((row, index: number) =>
86100
<RowComponent
87101
key={index}
88102
row={row || List<Char>()}
103+
hasCursor={index === buffer.cursorRow && this.props.job.status === Status.InProgress && (buffer._showCursor || buffer._blinkCursor)}
89104
status={this.props.job.status}
90105
job={this.props.job}/>,
91106
)}
@@ -98,6 +113,6 @@ export class BufferComponent extends React.Component<Props, State> {
98113
}
99114

100115
private get renderableRows(): List<List<Char>> {
101-
return this.shouldCutOutput ? this.props.job.screenBuffer.toCutRenderable(this.props.job.status) : this.props.job.screenBuffer.toRenderable(this.props.job.status);
116+
return this.shouldCutOutput ? this.props.job.screenBuffer.toCutRenderable() : this.props.job.screenBuffer.toRenderable();
102117
}
103118
}

0 commit comments

Comments
 (0)