Skip to content

Commit fd222b5

Browse files
authored
Merge branch 'master' into fix/select-all
2 parents b7695d2 + 83ba481 commit fd222b5

File tree

17 files changed

+191
-46
lines changed

17 files changed

+191
-46
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ Xterm.js is used in several world-class applications to provide great terminal e
169169
- [**TeleType**](https://github.com/akshaykmr/TeleType): cli tool that allows you to share your terminal online conveniently. Show off mad cli-fu, help a colleague, teach, or troubleshoot.
170170
- [**Intervue**](https://www.intervue.io): Pair programming for interviews. Multiple programming languages supported, with results displayed by xterm.js.
171171
- [**TRASA**](https://trasa.io): Zero trust access to Web, SSH, RDP and Database services.
172+
- [**Commas**](https://github.com/CyanSalt/commas): Commas is a hackable terminal and command runner.
172173
[And much more...](https://github.com/xtermjs/xterm.js/network/dependents)
173174

174175
Do you use xterm.js in your application as well? Please [open a Pull Request](https://github.com/sourcelair/xterm.js/pulls) to include it here. We would love to have it in our list. Note: Please add any new contributions to the end of the list only.

addons/xterm-addon-ligatures/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"license": "MIT",
3333
"dependencies": {
34-
"font-finder": "^1.0.4",
34+
"font-finder": "^1.1.0",
3535
"font-ligatures": "^1.3.3"
3636
},
3737
"devDependencies": {

addons/xterm-addon-ligatures/yarn.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,21 @@ follow-redirects@1.5.10:
7878
dependencies:
7979
debug "=3.1.0"
8080

81-
font-finder@^1.0.3, font-finder@^1.0.4:
81+
font-finder@^1.0.3:
8282
version "1.0.4"
8383
resolved "https://registry.yarnpkg.com/font-finder/-/font-finder-1.0.4.tgz#2ca944954dd8d0e1b5bdc4c596cc08607761d89b"
8484
dependencies:
8585
get-system-fonts "^2.0.0"
8686
promise-stream-reader "^1.0.1"
8787

88+
font-finder@^1.1.0:
89+
version "1.1.0"
90+
resolved "https://registry.yarnpkg.com/font-finder/-/font-finder-1.1.0.tgz#2bff2b2762acba720239c8bec898a96daae90858"
91+
integrity sha512-wpCL2uIbi6GurJbU7ZlQ3nGd61Ho+dSU6U83/xJT5UPFfN35EeCW/rOtS+5k+IuEZu2SYmHzDIPL9eA5tSYRAw==
92+
dependencies:
93+
get-system-fonts "^2.0.0"
94+
promise-stream-reader "^1.0.1"
95+
8896
font-ligatures@^1.3.3:
8997
version "1.3.3"
9098
resolved "https://registry.yarnpkg.com/font-ligatures/-/font-ligatures-1.3.3.tgz#63fff18dc8adb3a11fe5eec1f4e8d7edfa8075b9"

addons/xterm-addon-search/src/SearchAddon.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,15 @@ export class SearchAddon implements ITerminalAddon {
158158
};
159159

160160
if (incremental) {
161+
// Try to expand selection to right first.
161162
result = this._findInLine(term, searchPosition, searchOptions, false);
162-
if (!(result && result.row === startRow && result.col === startCol)) {
163+
const isOldResultHighlighted = result && result.row === startRow && result.col === startCol;
164+
if (!isOldResultHighlighted) {
165+
// If selection was not able to be expanded to the right, then try reverse search
166+
if (currentSelection) {
167+
searchPosition.startRow = currentSelection.endRow;
168+
searchPosition.startCol = currentSelection.endColumn;
169+
}
163170
result = this._findInLine(term, searchPosition, searchOptions, true);
164171
}
165172
} else {
@@ -245,6 +252,7 @@ export class SearchAddon implements ITerminalAddon {
245252
* @param term The search term.
246253
* @param position The position to start the search.
247254
* @param searchOptions Search options.
255+
* @param isReverseSearch Whether the search should start from the right side of the terminal and search to the left.
248256
* @return The search result if it was found.
249257
*/
250258
protected _findInLine(term: string, searchPosition: ISearchPosition, searchOptions: ISearchOptions = {}, isReverseSearch: boolean = false): ISearchResult | undefined {

demo/server.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ function startServer() {
4343
const env = Object.assign({}, process.env);
4444
env['COLORTERM'] = 'truecolor';
4545
var cols = parseInt(req.query.cols),
46-
rows = parseInt(req.query.rows),
47-
term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], {
48-
name: 'xterm-256color',
49-
cols: cols || 80,
50-
rows: rows || 24,
51-
cwd: env.PWD,
52-
env: env,
53-
encoding: USE_BINARY ? null : 'utf8'
54-
});
46+
rows = parseInt(req.query.rows),
47+
term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], {
48+
name: 'xterm-256color',
49+
cols: cols || 80,
50+
rows: rows || 24,
51+
cwd: process.platform === 'win32' ? undefined : env.PWD,
52+
env: env,
53+
encoding: USE_BINARY ? null : 'utf8'
54+
});
5555

5656
console.log('Created terminal with PID: ' + term.pid);
5757
terminals[term.pid] = term;

src/browser/AccessibilityManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export class AccessibilityManager extends Disposable {
263263
const element = this._rowElements[i];
264264
if (element) {
265265
if (lineData.length === 0) {
266-
element.innerHTML = ' ';
266+
element.innerText = '\u00a0';
267267
} else {
268268
element.textContent = lineData;
269269
}

src/browser/ColorManager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ const DEFAULT_SELECTION = {
1717
rgba: 0xFFFFFF4D
1818
};
1919

20-
// An IIFE to generate DEFAULT_ANSI_COLORS. Do not mutate DEFAULT_ANSI_COLORS, instead make a copy
21-
// and mutate that.
22-
export const DEFAULT_ANSI_COLORS = (() => {
20+
// An IIFE to generate DEFAULT_ANSI_COLORS.
21+
export const DEFAULT_ANSI_COLORS = Object.freeze((() => {
2322
const colors = [
2423
// dark:
2524
css.toColor('#2e3436'),
@@ -64,7 +63,7 @@ export const DEFAULT_ANSI_COLORS = (() => {
6463
}
6564

6665
return colors;
67-
})();
66+
})());
6867

6968
/**
7069
* Manages the source of truth for a terminal's colors.

src/browser/Terminal.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { MouseZoneManager } from 'browser/MouseZoneManager';
3939
import { AccessibilityManager } from './AccessibilityManager';
4040
import { ITheme, IMarker, IDisposable, ISelectionPosition, ILinkProvider } from 'xterm';
4141
import { DomRenderer } from 'browser/renderer/dom/DomRenderer';
42-
import { IKeyboardEvent, KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions } from 'common/Types';
42+
import { IKeyboardEvent, KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, IAnsiColorChangeEvent } from 'common/Types';
4343
import { evaluateKeyboardEvent } from 'common/input/Keyboard';
4444
import { EventEmitter, IEvent, forwardEvent } from 'common/EventEmitter';
4545
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
@@ -53,6 +53,7 @@ import { Linkifier2 } from 'browser/Linkifier2';
5353
import { CoreBrowserService } from 'browser/services/CoreBrowserService';
5454
import { CoreTerminal } from 'common/CoreTerminal';
5555
import { ITerminalOptions as IInitializedTerminalOptions } from 'common/services/Services';
56+
import { rgba } from 'browser/Color';
5657

5758
// Let it work inside Node.js for automated testing purposes.
5859
const document: Document = (typeof window !== 'undefined') ? window.document : null as any;
@@ -148,6 +149,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
148149
this.register(this._inputHandler.onRequestReset(() => this.reset()));
149150
this.register(this._inputHandler.onRequestScroll((eraseAttr, isWrapped) => this.scroll(eraseAttr, isWrapped || undefined)));
150151
this.register(this._inputHandler.onRequestWindowsOptionsReport(type => this._reportWindowsOptions(type)));
152+
this.register(this._inputHandler.onAnsiColorChange((event) => this._changeAnsiColor(event)));
151153
this.register(forwardEvent(this._inputHandler.onCursorMove, this._onCursorMove));
152154
this.register(forwardEvent(this._inputHandler.onTitleChange, this._onTitleChange));
153155
this.register(forwardEvent(this._inputHandler.onA11yChar, this._onA11yCharEmitter));
@@ -157,6 +159,19 @@ export class Terminal extends CoreTerminal implements ITerminal {
157159
this.register(this._bufferService.onResize(e => this._afterResize(e.cols, e.rows)));
158160
}
159161

162+
private _changeAnsiColor(event: IAnsiColorChangeEvent): void {
163+
if (!this._colorManager) { return; }
164+
165+
event.colors.forEach(ansiColor => {
166+
const color = rgba.toColor(ansiColor.red, ansiColor.green, ansiColor.blue);
167+
168+
this._colorManager!.colors.ansi[ansiColor.colorIndex] = color;
169+
});
170+
171+
this._renderService?.setColors(this._colorManager!.colors);
172+
this.viewport?.onThemeChange(this._colorManager!.colors);
173+
}
174+
160175
public dispose(): void {
161176
if (this._isDisposed) {
162177
return;

src/browser/public/Terminal.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import * as Strings from '../LocalizableStrings';
1313
import { IEvent, EventEmitter } from 'common/EventEmitter';
1414
import { AddonManager } from './AddonManager';
1515
import { IParams } from 'common/parser/Types';
16+
import { BufferSet } from 'common/buffer/BufferSet';
1617

1718
export class Terminal implements ITerminalApi {
1819
private _core: ITerminal;
1920
private _addonManager: AddonManager;
2021
private _parser: IParser | undefined;
22+
private _buffer: BufferNamespaceApi | undefined;
2123

2224
constructor(options?: ITerminalOptions) {
2325
this._core = new TerminalCore(options);
@@ -58,7 +60,10 @@ export class Terminal implements ITerminalApi {
5860
public get cols(): number { return this._core.cols; }
5961
public get buffer(): IBufferNamespaceApi {
6062
this._checkProposedApi();
61-
return new BufferNamespaceApi(this._core.buffers);
63+
if (!this._buffer) {
64+
this._buffer = new BufferNamespaceApi(this._core);
65+
}
66+
return this._buffer;
6267
}
6368
public get markers(): ReadonlyArray<IMarker> {
6469
this._checkProposedApi();
@@ -245,21 +250,21 @@ class BufferNamespaceApi implements IBufferNamespaceApi {
245250
private _onBufferChange = new EventEmitter<IBufferApi>();
246251
public get onBufferChange(): IEvent<IBufferApi> { return this._onBufferChange.event; }
247252

248-
constructor(private _buffers: IBufferSet) {
249-
this._normal = new BufferApiView(this._buffers.normal, 'normal');
250-
this._alternate = new BufferApiView(this._buffers.alt, 'alternate');
251-
this._buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
253+
constructor(private _core: ITerminal) {
254+
this._normal = new BufferApiView(this._core.buffers.normal, 'normal');
255+
this._alternate = new BufferApiView(this._core.buffers.alt, 'alternate');
256+
this._core.buffers.onBufferActivate(() => this._onBufferChange.fire(this.active));
252257
}
253258
public get active(): IBufferApi {
254-
if (this._buffers.active === this._buffers.normal) { return this.normal; }
255-
if (this._buffers.active === this._buffers.alt) { return this.alternate; }
259+
if (this._core.buffers.active === this._core.buffers.normal) { return this.normal; }
260+
if (this._core.buffers.active === this._core.buffers.alt) { return this.alternate; }
256261
throw new Error('Active buffer is neither normal nor alternate');
257262
}
258263
public get normal(): IBufferApi {
259-
return this._normal.init(this._buffers.normal);
264+
return this._normal.init(this._core.buffers.normal);
260265
}
261266
public get alternate(): IBufferApi {
262-
return this._alternate.init(this._buffers.alt);
267+
return this._alternate.init(this._core.buffers.alt);
263268
}
264269
}
265270

src/browser/renderer/atlas/CharAtlasUtils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ export function generateConfig(scaledCharWidth: number, scaledCharHeight: number
1616
cursor: undefined,
1717
cursorAccent: undefined,
1818
selection: undefined,
19-
// For the static char atlas, we only use the first 16 colors, but we need all 256 for the
20-
// dynamic character atlas.
21-
ansi: colors.ansi.slice(0, 16)
19+
ansi: colors.ansi
2220
};
2321
return {
2422
devicePixelRatio: window.devicePixelRatio,

0 commit comments

Comments
 (0)