Skip to content

Commit

Permalink
xterm 5
Browse files Browse the repository at this point in the history
  • Loading branch information
LabhanshAgrawal committed Jan 1, 2023
1 parent 304e91f commit d738d24
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 72 deletions.
69 changes: 32 additions & 37 deletions lib/components/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {FitAddon} from 'xterm-addon-fit';
import {WebLinksAddon} from 'xterm-addon-web-links';
import {SearchAddon, ISearchDecorationOptions} from 'xterm-addon-search';
import {WebglAddon} from 'xterm-addon-webgl';
import {CanvasAddon} from 'xterm-addon-canvas';
import {LigaturesAddon} from 'xterm-addon-ligatures';
import {Unicode11Addon} from 'xterm-addon-unicode11';
import {clipboard, shell} from 'electron';
Expand All @@ -15,6 +16,7 @@ import {TermProps} from '../hyper';
import {ObjectTypedKeys} from '../utils/object';
import {decorate} from '../utils/plugins';
import 'xterm/css/xterm.css';
import _ from 'lodash';

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

Expand Down Expand Up @@ -57,14 +59,14 @@ const getTermOptions = (props: TermProps): ITerminalOptions => {
letterSpacing: props.letterSpacing,
allowTransparency: needTransparency,
macOptionClickForcesSelection: props.macOptionSelectionMode === 'force',
bellStyle: props.bell === 'SOUND' ? 'sound' : 'none',
// bellStyle: props.bell === 'SOUND' ? 'sound' : 'none',
windowsMode: isWindows,
theme: {
foreground: props.foregroundColor,
background: backgroundColor,
cursor: props.cursorColor,
cursorAccent: props.cursorAccentColor,
selection: props.selectionColor,
selectionBackground: props.selectionColor,
black: props.colors.black,
red: props.colors.red,
green: props.colors.green,
Expand All @@ -83,7 +85,8 @@ const getTermOptions = (props: TermProps): ITerminalOptions => {
brightWhite: props.colors.lightWhite
},
screenReaderMode: props.screenReaderMode,
overviewRulerWidth: 20
overviewRulerWidth: 20,
allowProposedApi: true
};
};

Expand Down Expand Up @@ -158,7 +161,7 @@ export default class Term extends React.PureComponent<

this.termOptions = getTermOptions(props);
this.term = props.term || new Terminal(this.termOptions);
this.termDefaultBellSound = this.term.getOption('bellSound');
// this.termDefaultBellSound = this.term.getOption('bellSound');

// The parent element for the terminal is attached and removed manually so
// that we can preserve it across mounts and unmounts of the component
Expand Down Expand Up @@ -195,26 +198,28 @@ export default class Term extends React.PureComponent<
this.term.attachCustomKeyEventHandler(this.keyboardHandler);
this.term.loadAddon(this.fitAddon);
this.term.loadAddon(this.searchAddon);
this.term.loadAddon(
new WebLinksAddon(
(event: MouseEvent | undefined, uri: string) => {
if (shallActivateWebLink(event)) void shell.openExternal(uri);
},
{
// prevent default electron link handling to allow selection, e.g. via double-click
willLinkActivate: (event: MouseEvent | undefined) => {
event?.preventDefault();
return shallActivateWebLink(event);
},
priority: Date.now()
}
)
);
// this.term.loadAddon(
// new WebLinksAddon(
// (event: MouseEvent | undefined, uri: string) => {
// if (shallActivateWebLink(event)) void shell.openExternal(uri);
// },
// {
// // prevent default electron link handling to allow selection, e.g. via double-click
// willLinkActivate: (event: MouseEvent | undefined) => {
// event?.preventDefault();
// return shallActivateWebLink(event);
// },
// priority: Date.now()
// }
// )
// );
this.term.open(this.termRef);
if (useWebGL) {
this.term.loadAddon(new WebglAddon());
} else {
this.term.loadAddon(new CanvasAddon());
}
if (props.disableLigatures !== true && !useWebGL) {
if (props.disableLigatures !== true) {
this.term.loadAddon(new LigaturesAddon());
}
this.term.loadAddon(new Unicode11Addon());
Expand Down Expand Up @@ -402,37 +407,27 @@ export default class Term extends React.PureComponent<

// Use bellSound in nextProps if it exists
// otherwise use the default sound found in xterm.
nextTermOptions.bellSound = this.props.bellSound || this.termDefaultBellSound!;
// nextTermOptions.bellSound = this.props.bellSound || this.termDefaultBellSound!;

if (prevProps.search && !this.props.search) {
this.closeSearchBox();
}

// Update only options that have changed.
ObjectTypedKeys(nextTermOptions)
.filter((option) => option !== 'theme' && nextTermOptions[option] !== this.termOptions[option])
.forEach((option) => {
try {
this.term.setOption(option, nextTermOptions[option]);
} catch (_e) {
const e = _e as {message: string};
if (/The webgl renderer only works with the webgl char atlas/i.test(e.message)) {
// Ignore this because the char atlas will also be changed
} else {
throw e;
}
}
});
this.term.options = _.pickBy(
nextTermOptions,
(value, key) => this.termOptions[key as keyof ITerminalOptions] !== value && key !== 'theme'
);

// Do we need to update theme?
const shouldUpdateTheme =
!this.termOptions.theme ||
nextTermOptions.rendererType !== this.termOptions.rendererType ||
// nextTermOptions.rendererType !== this.termOptions.rendererType ||
ObjectTypedKeys(nextTermOptions.theme!).some(
(option) => nextTermOptions.theme![option] !== this.termOptions.theme![option]
);
if (shouldUpdateTheme) {
this.term.setOption('theme', nextTermOptions.theme);
this.term.options.theme = nextTermOptions.theme!;
}

this.termOptions = nextTermOptions;
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@
"typescript-json-schema": "0.55.0",
"uuid": "9.0.0",
"webpack-cli": "5.0.1",
"xterm": "4.19.0",
"xterm-addon-fit": "^0.5.0",
"xterm-addon-ligatures": "0.6.0-beta.19",
"xterm-addon-search": "^0.9.0",
"xterm-addon-unicode11": "^0.3.0",
"xterm-addon-web-links": "^0.6.0",
"xterm-addon-webgl": "0.12.0"
"xterm": "5.1.0",
"xterm-addon-canvas": "0.3.0",
"xterm-addon-fit": "0.7.0",
"xterm-addon-ligatures": "0.6.0",
"xterm-addon-search": "0.11.0",
"xterm-addon-unicode11": "0.5.0",
"xterm-addon-web-links": "0.8.0",
"xterm-addon-webgl": "0.14.0"
},
"devDependencies": {
"@ava/babel": "2.0.0",
Expand Down
61 changes: 33 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8459,43 +8459,48 @@ xtend@^4.0.0, xtend@^4.0.2, xtend@~4.0.0:
resolved "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==

xterm-addon-fit@^0.5.0:
version "0.5.0"
resolved "https://registry.npmjs.org/xterm-addon-fit/-/xterm-addon-fit-0.5.0.tgz#2d51b983b786a97dcd6cde805e700c7f913bc596"
integrity sha512-DsS9fqhXHacEmsPxBJZvfj2la30Iz9xk+UKjhQgnYNkrUIN5CYLbw7WEfz117c7+S86S/tpHPfvNxJsF5/G8wQ==
[email protected]:
version "0.3.0"
resolved "https://registry.npmjs.org/xterm-addon-canvas/-/xterm-addon-canvas-0.3.0.tgz#8cfb5a13297f4a31a12870c1119af2c139392b50"
integrity sha512-2deF4ev6T+NjgSM56H+jcAWz4k5viEoaBtuDEyfo5Qdh1r7HOvNzLC45HSeegdH38qmEcL9XIt0KXyOINpSFRA==

[email protected]:
version "0.7.0"
resolved "https://registry.npmjs.org/xterm-addon-fit/-/xterm-addon-fit-0.7.0.tgz#b8ade6d96e63b47443862088f6670b49fb752c6a"
integrity sha512-tQgHGoHqRTgeROPnvmtEJywLKoC/V9eNs4bLLz7iyJr1aW/QFzRwfd3MGiJ6odJd9xEfxcW36/xRU47JkD5NKQ==

[email protected]-beta.19:
version "0.6.0-beta.19"
resolved "https://registry.npmjs.org/xterm-addon-ligatures/-/xterm-addon-ligatures-0.6.0-beta.19.tgz#5e43eeaf84968e014769a5f2c6a3a3601dc4771c"
integrity sha512-A0BIjFF6g5aPI0HiI2JMhhMV3gaHbpZ+ua+UNagkID0GxZ/ezn0wVOAtNQl/KlqnFueoyZIxlbyXmWNAfJVPRg==
[email protected]:
version "0.6.0"
resolved "https://registry.npmjs.org/xterm-addon-ligatures/-/xterm-addon-ligatures-0.6.0.tgz#c51801b0150c62ac1165654757b55c796457d195"
integrity sha512-DxiYCXXYEpnwr8li4/QhG64exjrLX1nHBfNNfrQgx5e8Z9tK2SjWKpxI6PZEy++8+YdL1F7VjWI4aKOaDt2VVw==
dependencies:
font-finder "^1.1.0"
font-ligatures "^1.4.1"

xterm-addon-search@^0.9.0:
version "0.9.0"
resolved "https://registry.npmjs.org/xterm-addon-search/-/xterm-addon-search-0.9.0.tgz#95278ebb818cfcf882209ae75be96e0bea5d52a5"
integrity sha512-aoolI8YuHvdGw+Qjg8g2M4kst0v86GtB7WeBm4F0jNXA005/6QbWWy9eCsvnIDLJOFI5JSSrZnD6CaOkvBQYPA==
xterm-addon-search@0.11.0:
version "0.11.0"
resolved "https://registry.npmjs.org/xterm-addon-search/-/xterm-addon-search-0.11.0.tgz#2a00ff7f9848f6140e7c4d1782486b0b18b06e0d"
integrity sha512-6U4uHXcQ7G5igsdaGqrJ9ehm7vep24bXqWxuy3AnIosXF2Z5uy2MvmYRyTGNembIqPV/x1YhBQ7uShtuqBHhOQ==

xterm-addon-unicode11@^0.3.0:
version "0.3.0"
resolved "https://registry.npmjs.org/xterm-addon-unicode11/-/xterm-addon-unicode11-0.3.0.tgz#e4435c3c91a5294a7eb8b79c380acbb28a659463"
integrity sha512-x5fHDZT2j9tlTlHnzPHt++9uKZ2kJ/lYQOj3L6xJA22xoJsS8UQRw/5YIFg2FUHqEAbV77Z1fZij/9NycMSH/A==
xterm-addon-unicode11@0.5.0:
version "0.5.0"
resolved "https://registry.npmjs.org/xterm-addon-unicode11/-/xterm-addon-unicode11-0.5.0.tgz#41c0d96acc1e3bb6c6596eee64e163b6bca74be7"
integrity sha512-Jm4/g4QiTxiKiTbYICQgC791ubhIZyoIwxAIgOW8z8HWFNY+lwk+dwaKEaEeGBfM48Vk8fklsUW9u/PlenYEBg==

xterm-addon-web-links@^0.6.0:
version "0.6.0"
resolved "https://registry.npmjs.org/xterm-addon-web-links/-/xterm-addon-web-links-0.6.0.tgz#0296cb6c99588847894670d998c9ea6a6aeb26ee"
integrity sha512-H6XzjWWZu8FBo+fnYpxdPk9w5M6drbsvwPEJZGRS38MihiQaVFpKlCMKdfRgDbKGE530tw1yH54rhpZfHgt2/A==
xterm-addon-web-links@0.8.0:
version "0.8.0"
resolved "https://registry.npmjs.org/xterm-addon-web-links/-/xterm-addon-web-links-0.8.0.tgz#2cb1d57129271022569208578b0bf4774e7e6ea9"
integrity sha512-J4tKngmIu20ytX9SEJjAP3UGksah7iALqBtfTwT9ZnmFHVplCumYQsUJfKuS+JwMhjsjH61YXfndenLNvjRrEw==

xterm-addon-webgl@0.12.0:
version "0.12.0"
resolved "https://registry.npmjs.org/xterm-addon-webgl/-/xterm-addon-webgl-0.12.0.tgz#2fba8d31890a122adafa1c2fb945482e2ae12973"
integrity sha512-3P5ihdjPnxH6Wrvqjki9UD+duoVrp1fvnO/pSpXP2F1L2GwY6TDNExgj8Yg141vMCNgQbcVqmsTLYEYZxjY92A==
xterm-addon-webgl@0.14.0:
version "0.14.0"
resolved "https://registry.npmjs.org/xterm-addon-webgl/-/xterm-addon-webgl-0.14.0.tgz#bd9136710bd5d130a0a51fd42e6d14ea39348236"
integrity sha512-zcxL4RVVjeS7NNFeKe5HHQI8OUEx3wZpE4EqLoTVipa2UrTR+qLsigo16UEp/yVcYBMhK7tsJ/AJokoEe/f0mw==

xterm@4.19.0:
version "4.19.0"
resolved "https://registry.npmjs.org/xterm/-/xterm-4.19.0.tgz#c0f9d09cd61de1d658f43ca75f992197add9ef6d"
integrity sha512-c3Cp4eOVsYY5Q839dR5IejghRPpxciGmLWWaP9g+ppfMeBChMeLa1DCA+pmX/jyDZ+zxFOmlJL/82qVdayVoGQ==
xterm@5.1.0:
version "5.1.0"
resolved "https://registry.npmjs.org/xterm/-/xterm-5.1.0.tgz#3e160d60e6801c864b55adf19171c49d2ff2b4fc"
integrity sha512-LovENH4WDzpwynj+OTkLyZgJPeDom9Gra4DMlGAgz6pZhIDCQ+YuO7yfwanY+gVbn/mmZIStNOnVRU/ikQuAEQ==

y18n@^5.0.5:
version "5.0.5"
Expand Down

0 comments on commit d738d24

Please sign in to comment.