Skip to content

Commit

Permalink
Merge pull request #1645 from jerch/fix_convertEol
Browse files Browse the repository at this point in the history
fix convertEol option
  • Loading branch information
jerch committed Sep 2, 2018
2 parents f148238 + 33b65bb commit 1aec57e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/InputHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NULL_CELL_CHAR, NULL_CELL_CODE, NULL_CELL_WIDTH, CHAR_DATA_CHAR_INDEX }
import { Terminal } from './Terminal';
import { IBufferLine } from './Types';


// TODO: This and the sections related to this object in associated tests can be
// removed safely after InputHandler refactors are finished
class OldInputHandler extends InputHandler {
Expand Down Expand Up @@ -445,4 +446,33 @@ describe('InputHandler', () => {
expect(termContent(termNew)).eql(termContent(termOld));
});
});
it('convertEol setting', function(): void {
// not converting
let s = '';
const termNotConverting = new Terminal({cols: 15, rows: 10});
(termNotConverting as any)._inputHandler.parse('Hello\nWorld');
for (let i = 0; i < termNotConverting.cols; ++i) {
s += termNotConverting.buffer.lines.get(0).get(i)[CHAR_DATA_CHAR_INDEX];
}
expect(s).equals('Hello ');
s = '';
for (let i = 0; i < termNotConverting.cols; ++i) {
s += termNotConverting.buffer.lines.get(1).get(i)[CHAR_DATA_CHAR_INDEX];
}
expect(s).equals(' World ');

// converting
s = '';
const termConverting = new Terminal({cols: 15, rows: 10, convertEol: true});
(termConverting as any)._inputHandler.parse('Hello\nWorld');
for (let i = 0; i < termConverting.cols; ++i) {
s += termConverting.buffer.lines.get(0).get(i)[CHAR_DATA_CHAR_INDEX];
}
expect(s).equals('Hello ');
s = '';
for (let i = 0; i < termConverting.cols; ++i) {
s += termConverting.buffer.lines.get(1).get(i)[CHAR_DATA_CHAR_INDEX];
}
expect(s).equals('World ');
});
});
2 changes: 1 addition & 1 deletion src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export class InputHandler extends Disposable implements IInputHandler {
// make buffer local for faster access
const buffer = this._terminal.buffer;

if (this._terminal.convertEol) {
if (this._terminal.options.convertEol) {
buffer.x = 0;
}
buffer.y++;
Expand Down
1 change: 0 additions & 1 deletion src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
// TODO: This can be changed to an enum or boolean, 0 and 1 seem to be the only options
public cursorState: number;
public cursorHidden: boolean;
public convertEol: boolean;

private _customKeyEventHandler: CustomKeyEventHandler;

Expand Down
1 change: 0 additions & 1 deletion src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface IInputHandlingTerminal extends IEventEmitter {

bell(): void;
focus(): void;
convertEol: boolean;
updateRange(y: number): void;
scroll(isWrapped?: boolean): void;
setgLevel(g: number): void;
Expand Down
10 changes: 10 additions & 0 deletions typings/xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ declare module 'xterm' {
*/
bellStyle?: 'none' /*| 'visual'*/ | 'sound' /*| 'both'*/;

/**
* When enabled the cursor will be set to the beginning of the next line
* with every new line. This equivalent to sending '\r\n' for each '\n'.
* Normally the termios settings of the underlying PTY deals with the
* translation of '\n' to '\r\n' and this setting should not be used. If you
* deal with data from a non-PTY related source, this settings might be
* useful.
*/
convertEol?: boolean;

/**
* The number of columns in the terminal.
*/
Expand Down

0 comments on commit 1aec57e

Please sign in to comment.