Skip to content

Commit ae29d2c

Browse files
Merge pull request #8 from realandygithub/wrap
prompt
2 parents 9604016 + 2423e5f commit ae29d2c

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

.eslintrc.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": "eslint:recommended",
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"rules": {
13+
}
14+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"electron": "^17.0.0",
9595
"electron-packager": "^15.4.0",
9696
"electron-reloader": "^1.2.3",
97+
"eslint": "^8.15.0",
9798
"mocha": "^9.2.0",
9899
"rollup": "^2.67.0",
99100
"rollup-plugin-babel": "^4.4.0",

src/XTerm.svelte

+17-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
import { onMount } from "svelte";
33
import { FitAddon } from "xterm-addon-fit";
44
import "./xterm.css";
5+
56
const { remote, ipcRenderer, BrowserWindow } = require("electron");
67
const Terminal = require("xterm").Terminal;
78
89
const fitAddon = new FitAddon();
9-
const term = new Terminal({ convertEol: true });
10+
const term = new Terminal({
11+
fontFamily: "Fira Code, courier-new, courier, monospace",
12+
});
1013
1114
const fitOnTheGo = () => {
1215
fitAddon.fit();
@@ -15,26 +18,36 @@
1518
onMount(() => {
1619
term.options.cursorStyle = "block";
1720
term.options.cursorBlink = true;
18-
term.options.fontSize = 14;
21+
term.options.fontSize = 12;
1922
2023
term.loadAddon(fitAddon);
2124
term.open(document.getElementById("xterm"));
2225
fitAddon.fit();
2326
2427
//2022-ST-AJ prompt appears after welcome message
28+
//2022-ST-AJ immediately call resize to have proper prompt in, and have node-pty adjust to correct size.
29+
2530
term.prompt = () => {
26-
term.write("\r\n$ ");
31+
//TODO: to get the cwd showing. pass it from ipcMain
32+
33+
ipcRenderer.send("terminal-into", "\r");
2734
};
2835
2936
term.writeln("Welcome to SvelteStorm");
30-
term.write("\b \b");
37+
// term.writeln("\b \b");
3138
3239
term.prompt();
40+
term.focus();
3341
3442
term.onData((e) => {
3543
ipcRenderer.send("terminal-into", e);
3644
});
3745
46+
term.onResize((size) => {
47+
// console.log("terminal resized. size:", size);
48+
ipcRenderer.send("terminal-resize", size);
49+
});
50+
3851
ipcRenderer.on("terminal-incData", (event, data) => {
3952
term.write(data);
4053
});

src/index.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require('@electron/remote/main').enable(webContents);
2121
//hot reload for electron development
2222
try {
2323
require('electron-reloader')(module);
24-
} catch (_) {}
24+
} catch (err) {console.log(err) }
2525

2626
let userFile = '';
2727

@@ -101,10 +101,12 @@ const createWindow = (exports.createWindow = () => {
101101
//loading index.html into the app
102102
newWindow.loadURL(`file://${path.join(__dirname, '../public/index.html')}`);
103103

104+
//show window by calling the listener once
104105
newWindow.once('ready-to-show', () => {
105106
newWindow.show();
106107
});
107108

109+
108110
newWindow.on('focus', createApplicationMenu);
109111

110112
//save changes dialog modal message
@@ -147,22 +149,38 @@ const createWindow = (exports.createWindow = () => {
147149
});
148150

149151
var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
152+
150153
var ptyProcess = pty.spawn(shell, [], {
151154
name: 'xterm-color',
152155
cols: 80,
153156
rows: 24,
154157
cwd: process.env.HOME,
155158
env: process.env,
156159
});
160+
161+
//2022-ST-AJ sends to renderer cwd for it to display on prompt
162+
ipcMain.on('cwd',(event,data) => {
163+
event.reply('cwdreply',process.env.HOME);
164+
});
157165

166+
//2022-ST-AJ node-pty listens to data and send whatever it receives back to xterm to render
158167
ptyProcess.onData((data) => {
159168
newWindow.webContents.send('terminal-incData', data);
160169
});
161-
170+
171+
//2022-ST-AJ ipcMain listens on data passed from xterm to write to shell
162172
ipcMain.on('terminal-into', (event, data) => {
163173
ptyProcess.write(data);
164174
});
165175

176+
//2022-ST-AJ ipcMain listens to resizing event from renderer and calls resize on node-pty to align size between node-pty and xterm. They need to align otherwise there are wierd bugs everywhere.
177+
ipcMain.on('terminal-resize', (event,size) => {
178+
const cols = size.cols;
179+
const rows = size.rows;
180+
console.log('pty resizing to cols and rows', cols,rows);
181+
ptyProcess.resize(cols, rows);
182+
})
183+
166184
require('electron-reload')(__dirname, {
167185
electron: path.join(__dirname, '../node_modules', '.bin', 'electron'),
168186
awaitWriteFinish: true,

src/svelte.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import App from './App.svelte';
22

33
const app = new App({
44
target: document.body,
5-
props: {},
5+
props: {},
66
});
77

88
export default app;

0 commit comments

Comments
 (0)