
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@loopmode/xpty
Advanced tools
A react component and some helpers for building terminals in electron apps.
Based on xterm and node-pty.
Make sure to include the xterm stylesheet in your app:
import 'xterm/css/xterm.css';
Also, have a look at the troubleshooting section.
There are two parts to using this:
There are multiple ways to create a pty.
ptyManager class that you can use to connect to the same pty from multiple callsitesusePtyCommand hook that uses ptyManager under the hood. The pty is reusable if you provide a custom id option.usePty hook for simpler cases. It creates a pty "inline" and returns it - you can not connect to it from multipe callsites.There is an XTerminal component that expects an existing pty as a prop. You're free to choose how and where you create that, which depends on your use case.
usePtyCommandimport React from 'react';
import { XTerminal, usePtyCommand } from '@loopmode/xpty';
export const Example = () => {
const { pty, execute } = usePtyCommand({
cmd: 'ls -lah'
cwd: '~'
});
return (
<>
<XTerminal pty={pty}>
<button onClick={execute}>Execute</button>
</>
)
};
Here's an example with custom id and multiple components using the same pty
export const ExampleCommandScreen = () => {
const { pty, execute } = usePtyCommand({
id: 'my-command',
cmd: 'ls -lah'
});
return (
<>
<XTerminal pty={pty}>
<button onClick={execute}>Execute</button>
</>
);
};
export const ExampleSidebarItem = () => {
const { pty, execute } = usePtyCommand({
id: 'my-command'
});
return (
<>
<button onClick={execute}>Execute</button>
</>
)
}
usePtyThis simpler variant allows you to simply execute() some CLI command.
import React from 'react';
import { XTerminal, usePty } from '@loopmode/xpty';
export const Example = () => {
const { pty, execute } = usePty();
const run = () => execute('ls -lah')
return (
<>
<XTerminal pty={pty}>
<button onClick={run}>Execute</button>
</>
)
}
After installation, the native node-pty module will be compiled for your local system. However, it needs to be compiled for the node version of used by electron, not necessarily the one on your local system.
You can use the electron-builder package and its install-app-deps command to do this:
npx electron-builder install-app-deps
Better yet: Add electron-builder locally and use a package script.
yarn add electron-builder --dev
{
"scripts": {
"rebuild": "electron-builder install-app-deps"
}
}
If you use this in an electron app with webpack, make sure to add node-pty to webpack externals:
// webpack.config.js
module.exports = {
// ...
externals: ['node-pty']
};
FAQs
Provides xterm.js and node-pty helpers for react electron apps
We found that @loopmode/xpty demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.