2 * Copyright (c) 2019 The xterm.js authors. All rights reserved.
6 import { IDisposable } from 'xterm';
7 import { ITerminal } from './Types';
8 import { CHAR_DATA_CODE_INDEX, NULL_CELL_CODE, WHITESPACE_CELL_CODE } from 'common/buffer/Constants';
10 export function applyWindowsMode(terminal: ITerminal): IDisposable {
11 // Winpty does not support wraparound mode which means that lines will never
12 // be marked as wrapped. This causes issues for things like copying a line
13 // retaining the wrapped new line characters or if consumers are listening
14 // in on the data stream.
16 // The workaround for this is to listen to every incoming line feed and mark
17 // the line as wrapped if the last character in the previous line is not a
18 // space. This is certainly not without its problems, but generally on
19 // Windows when text reaches the end of the terminal it's likely going to be
21 return terminal.onLineFeed(() => {
22 const line = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y - 1);
23 const lastChar = line.get(terminal.cols - 1);
25 const nextLine = terminal.buffer.lines.get(terminal.buffer.ybase + terminal.buffer.y);
26 nextLine.isWrapped = (lastChar[CHAR_DATA_CODE_INDEX] !== NULL_CELL_CODE && lastChar[CHAR_DATA_CODE_INDEX] !== WHITESPACE_CELL_CODE);