Skip to content

Commit 95807fa

Browse files
authored
Add support for displaying images (#6987)
1 parent 11c9238 commit 95807fa

File tree

13 files changed

+39
-2
lines changed

13 files changed

+39
-2
lines changed

app/config/config-default.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"disableAutoUpdates": false,
6262
"autoUpdatePlugins": true,
6363
"preserveCWD": true,
64-
"screenReaderMode": false
64+
"screenReaderMode": false,
65+
"imageSupport": true
6566
},
6667
"plugins": [],
6768
"localPlugins": [],

app/config/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@
202202
"description": "color of the text",
203203
"type": "string"
204204
},
205+
"imageSupport": {
206+
"description": "Whether to enable Sixel and iTerm2 inline image protocol support or not.",
207+
"type": "boolean"
208+
},
205209
"letterSpacing": {
206210
"description": "letter spacing as a relative unit",
207211
"type": "number"
@@ -355,6 +359,7 @@
355359
"fontWeight",
356360
"fontWeightBold",
357361
"foregroundColor",
362+
"imageSupport",
358363
"letterSpacing",
359364
"lineHeight",
360365
"macOptionSelectionMode",

bin/snapshot-libs.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ if (false) {
2323
require('mousetrap');
2424
require('open');
2525
require('xterm-addon-fit');
26+
require('xterm-addon-image');
2627
require('xterm-addon-search');
2728
require('xterm-addon-web-links');
2829
require('xterm-addon-webgl');

lib/components/term-group.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class TermGroup_ extends React.PureComponent<TermGroupProps> {
107107
disableLigatures: this.props.disableLigatures,
108108
screenReaderMode: this.props.screenReaderMode,
109109
windowsPty: this.props.windowsPty,
110+
imageSupport: this.props.imageSupport,
110111
uid
111112
});
112113

lib/components/term.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {TermProps} from '../hyper';
1616
import {pickBy, isEqual} from 'lodash';
1717
import {decorate} from '../utils/plugins';
1818
import 'xterm/css/xterm.css';
19+
import {ImageAddon} from 'xterm-addon-image';
1920

2021
const SearchBox = decorate(_SearchBox, 'SearchBox');
2122

@@ -212,16 +213,23 @@ export default class Term extends React.PureComponent<
212213
})
213214
);
214215
this.term.open(this.termRef);
216+
215217
if (useWebGL) {
216218
this.term.loadAddon(new WebglAddon());
217219
} else {
218220
this.term.loadAddon(new CanvasAddon());
219221
}
222+
220223
if (props.disableLigatures !== true) {
221224
this.term.loadAddon(new LigaturesAddon());
222225
}
226+
223227
this.term.loadAddon(new Unicode11Addon());
224228
this.term.unicode.activeVersion = '11';
229+
230+
if (props.imageSupport) {
231+
this.term.loadAddon(new ImageAddon());
232+
}
225233
} else {
226234
// get the cached plugins
227235
this.fitAddon = props.fitAddon!;

lib/components/terms.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export default class Terms extends React.Component<TermsProps> {
120120
disableLigatures: this.props.disableLigatures,
121121
screenReaderMode: this.props.screenReaderMode,
122122
windowsPty: this.props.windowsPty,
123+
imageSupport: this.props.imageSupport,
123124
parentProps: this.props
124125
});
125126

lib/config.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ export type configOptions = {
8686
fontWeightBold: FontWeight;
8787
/** color of the text */
8888
foregroundColor: string;
89+
/**
90+
* Whether to enable Sixel and iTerm2 inline image protocol support or not.
91+
*/
92+
imageSupport: boolean;
8993
/** letter spacing as a relative unit */
9094
letterSpacing: number;
9195
/** line height as a relative unit */

lib/containers/terms.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const mapStateToProps = (state: HyperState) => {
5454
macOptionSelectionMode: state.ui.macOptionSelectionMode,
5555
disableLigatures: state.ui.disableLigatures,
5656
screenReaderMode: state.ui.screenReaderMode,
57-
windowsPty: state.ui.windowsPty
57+
windowsPty: state.ui.windowsPty,
58+
imageSupport: state.ui.imageSupport
5859
};
5960
};
6061

lib/hyper.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export type uiState = Immutable<{
6868
fontWeightBold: FontWeight;
6969
foregroundColor: string;
7070
fullScreen: boolean;
71+
imageSupport: boolean;
7172
letterSpacing: number;
7273
lineHeight: number;
7374
macOptionSelectionMode: string;
@@ -310,6 +311,7 @@ export type TermGroupOwnProps = {
310311
| 'webGLRenderer'
311312
| 'webLinksActivationKey'
312313
| 'windowsPty'
314+
| 'imageSupport'
313315
>;
314316

315317
import {TermGroupConnectedProps} from './components/term-group';
@@ -357,6 +359,7 @@ export type TermProps = {
357359
fontWeight: FontWeight;
358360
fontWeightBold: FontWeight;
359361
foregroundColor: string;
362+
imageSupport: boolean;
360363
isTermActive: boolean;
361364
letterSpacing: number;
362365
lineHeight: number;

lib/reducers/ui.ts

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const initial: uiState = Immutable<Mutable<uiState>>({
5353
fontSmoothingOverride: 'antialiased',
5454
fontWeight: 'normal',
5555
fontWeightBold: 'bold',
56+
imageSupport: true,
5657
lineHeight: 1,
5758
letterSpacing: 0,
5859
css: '',
@@ -281,6 +282,10 @@ const reducer: IUiReducer = (state = initial, action) => {
281282
};
282283
}
283284

285+
if (config.imageSupport !== undefined) {
286+
ret.imageSupport = config.imageSupport;
287+
}
288+
284289
ret._lastUpdate = now;
285290

286291
return ret;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"xterm": "5.2.1",
6363
"xterm-addon-canvas": "0.4.0",
6464
"xterm-addon-fit": "0.7.0",
65+
"xterm-addon-image": "0.4.1",
6566
"xterm-addon-ligatures": "0.6.0",
6667
"xterm-addon-search": "0.12.0",
6768
"xterm-addon-unicode11": "0.5.0",

webpack.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const config: webpack.Configuration[] = [
118118
mousetrap: 'require("./node_modules/mousetrap/mousetrap.js")',
119119
open: 'require("./node_modules/open/index.js")',
120120
'xterm-addon-fit': 'require("./node_modules/xterm-addon-fit/lib/xterm-addon-fit.js")',
121+
'xterm-addon-image': 'require("./node_modules/xterm-addon-image/lib/xterm-addon-image.js")',
121122
'xterm-addon-search': 'require("./node_modules/xterm-addon-search/lib/xterm-addon-search.js")',
122123
'xterm-addon-web-links': 'require("./node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js")',
123124
'xterm-addon-webgl': 'require("./node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js")',

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -7542,6 +7542,11 @@ [email protected]:
75427542
resolved "https://registry.npmjs.org/xterm-addon-fit/-/xterm-addon-fit-0.7.0.tgz#b8ade6d96e63b47443862088f6670b49fb752c6a"
75437543
integrity sha512-tQgHGoHqRTgeROPnvmtEJywLKoC/V9eNs4bLLz7iyJr1aW/QFzRwfd3MGiJ6odJd9xEfxcW36/xRU47JkD5NKQ==
75447544

7545+
7546+
version "0.4.1"
7547+
resolved "https://registry.npmjs.org/xterm-addon-image/-/xterm-addon-image-0.4.1.tgz#ec8f750af48005ad641c1128fa1f551ac198472a"
7548+
integrity sha512-iJpYyvtbHg4oXSv+D6J73ZfCjnboZpbZ567MLplXDBlYSUknv3kvPTfVMPJATV7Zsx7+bDgyXboCh9vsDf/m/w==
7549+
75457550
75467551
version "0.6.0"
75477552
resolved "https://registry.npmjs.org/xterm-addon-ligatures/-/xterm-addon-ligatures-0.6.0.tgz#c51801b0150c62ac1165654757b55c796457d195"

0 commit comments

Comments
 (0)