Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit d86458c

Browse files
committed
fix: pty/client performance tweaks
this also fixes a long-standing minor issue where non-focused xterms had an unthemed cursor color; you will see this usually as a brief low-contrast cursor block when launching certain apps Fixes #4397
1 parent a4a7a97 commit d86458c

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

plugins/plugin-bash-like/src/pty/client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const exitAltBufferPattern = /\x1b\[\??(47|1047|1049)l/
5151

5252
import copy from './copy'
5353

54-
import 'xterm/css/xterm.css'
5554
import '../../web/css/static/xterm.css'
5655

5756
interface Size {
@@ -898,8 +897,8 @@ export const doExec = (
898897
}
899898

900899
// heuristic for hiding empty rows
901-
terminal.element.classList.add('xterm-empty-row-heuristic')
902-
setTimeout(() => terminal.element.classList.remove('xterm-empty-row-heuristic'), 100)
900+
// terminal.element.classList.add('xterm-empty-row-heuristic')
901+
// setTimeout(() => terminal.element.classList.remove('xterm-empty-row-heuristic'), 100)
903902

904903
//
905904
// on exit, remove event handlers and the like

plugins/plugin-bash-like/web/css/static/xterm.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "~xterm/css/xterm.css";
2+
13
/* Explanation for width hacks:
24
see https://github.com/xtermjs/xterm.js/pull/2067
35
see https://github.com/IBM/kui/issues/1518
@@ -62,6 +64,7 @@ disabled see https://github.com/IBM/kui/issues/3939
6264
}
6365
&.processing {
6466
padding: 0;
67+
margin: 0;
6568
-webkit-app-region: no-drag; /* but make sure the content of the blocks are not draggable */
6669

6770
.bx--accordion__heading {
@@ -88,9 +91,9 @@ disabled see https://github.com/IBM/kui/issues/3939
8891
}
8992
}
9093

91-
.kui--tab-content:not(.xterm-alt-buffer-mode) .xterm.xterm-empty-row-heuristic .xterm-rows > div:empty {
94+
/* .kui--tab-content:not(.xterm-alt-buffer-mode) .xterm.xterm-empty-row-heuristic .xterm-rows > div:empty {
9295
display: none;
93-
}
96+
} */
9497

9598
.xterm .xterm-rows .xterm-hidden-row {
9699
display: none;
@@ -119,6 +122,7 @@ disabled see https://github.com/IBM/kui/issues/3939
119122
transition-delay: 150ms; /* only show the spinner block if the command takes a bit longer */
120123
}
121124
.xterm-container .xterm-rows:not(.xterm-focus) .xterm-cursor.xterm-cursor-block {
125+
background-color: var(--color-base03) !important;
122126
outline-color: transparent !important;
123127
}
124128

plugins/plugin-client-common/src/components/Client/TabContent.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ interface WithTabUUID {
3535
interface WithTab {
3636
tab: KuiTab
3737
tabClassList: Record<string, boolean>
38-
activateHandlers: ((isActive: boolean) => void)[]
3938
}
4039

4140
export type TabContentOptions = TerminalOptions & {
@@ -75,6 +74,9 @@ type State = Partial<WithTab> & {
7574
export default class TabContent extends React.PureComponent<Props, State> {
7675
private readonly cleaners: Cleaner[] = []
7776

77+
/** switching back or away from this tab */
78+
private activateHandlers: ((isActive: boolean) => void)[] = []
79+
7880
/** grab a ref (below) so that we can maintain focus */
7981
private _terminal: ScrollableTerminal
8082

@@ -236,9 +238,7 @@ export default class TabContent extends React.PureComponent<Props, State> {
236238
}
237239

238240
public render() {
239-
if (this.state.tab && this.state.activateHandlers) {
240-
this.state.activateHandlers.forEach(handler => handler(this.props.active))
241-
}
241+
this.activateHandlers.forEach(handler => handler(this.props.active))
242242

243243
return (
244244
<div
@@ -248,33 +248,33 @@ export default class TabContent extends React.PureComponent<Props, State> {
248248

249249
if (tab) {
250250
tab.onActivate = (handler: (isActive: boolean) => void) => {
251-
this.setState(curState => ({
252-
activateHandlers: !curState.activateHandlers ? [handler] : curState.activateHandlers.concat([handler])
253-
}))
251+
this.activateHandlers.push(handler)
254252
}
255253
tab.offActivate = (handler: (isActive: boolean) => void) => {
254+
const idx = this.activateHandlers.findIndex(_ => _ === handler)
255+
if (idx >= 0) {
256+
this.activateHandlers.splice(idx, 1)
257+
}
258+
}
259+
260+
tab.addClass = (cls: string) => {
256261
this.setState(curState => {
257-
const idx = !curState.activateHandlers ? -1 : curState.activateHandlers.findIndex(_ => _ === handler)
258-
if (idx >= 0) {
262+
if (!curState.tabClassList || !curState.tabClassList[cls]) {
259263
return {
260-
activateHandlers: curState.activateHandlers
261-
.slice(0, idx)
262-
.concat(curState.activateHandlers.slice(idx + 1))
264+
tabClassList: Object.assign({}, curState.tabClassList, { [cls]: true })
263265
}
264266
}
265267
})
266268
}
267269

268-
tab.addClass = (cls: string) => {
269-
this.setState(curState => ({ tabClassList: Object.assign({}, curState.tabClassList, { [cls]: true }) }))
270-
}
271-
272270
tab.removeClass = (cls: string) => {
273271
this.setState(curState => {
274-
const update = Object.assign({}, curState.tabClassList)
275-
delete update[cls]
276-
return {
277-
tabClassList: update
272+
if (curState.tabClassList && curState.tabClassList[cls]) {
273+
const update = Object.assign({}, curState.tabClassList)
274+
delete update[cls]
275+
return {
276+
tabClassList: update
277+
}
278278
}
279279
})
280280
}

0 commit comments

Comments
 (0)