Silent resize cmds & Auto resize terminal #1

This commit is contained in:
LukeGus
2024-12-07 00:32:06 -06:00
parent 4b927decce
commit a2a441cdca
4 changed files with 37 additions and 23 deletions

19
.idea/workspace.xml generated
View File

@@ -4,9 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="8497df64-d86b-4c98-ac58-c157d9d3fb1e" name="Changes" comment="Terminal size fix #18 (rows &amp; cols fix)"> <list default="true" id="8497df64-d86b-4c98-ac58-c157d9d3fb1e" name="Changes" comment="Test ntfy build notification system">
<change beforePath="$PROJECT_DIR$/.github/workflows/docker-image.yml" beforeDir="false" afterPath="$PROJECT_DIR$/.github/workflows/docker-image.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/backend/server.js" beforeDir="false" afterPath="$PROJECT_DIR$/backend/server.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/frontend/src/App.jsx" beforeDir="false" afterPath="$PROJECT_DIR$/frontend/src/App.jsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/info.txt" beforeDir="false" afterPath="$PROJECT_DIR$/info.txt" afterDir="false" /> <change beforePath="$PROJECT_DIR$/info.txt" beforeDir="false" afterPath="$PROJECT_DIR$/info.txt" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@@ -116,6 +117,7 @@
<updated>1733439468142</updated> <updated>1733439468142</updated>
<workItem from="1733439479708" duration="5489000" /> <workItem from="1733439479708" duration="5489000" />
<workItem from="1733448523969" duration="3535000" /> <workItem from="1733448523969" duration="3535000" />
<workItem from="1733549186397" duration="3022000" />
</task> </task>
<task id="LOCAL-00001" summary="Nano zoom fix #11"> <task id="LOCAL-00001" summary="Nano zoom fix #11">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -197,7 +199,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1733538097802</updated> <updated>1733538097802</updated>
</task> </task>
<option name="localTasksCounter" value="11" /> <task id="LOCAL-00011" summary="Test ntfy build notification system">
<option name="closed" value="true" />
<created>1733539381433</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1733539381433</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -233,6 +243,7 @@
<MESSAGE value="Nano zoom fix #16 (ssh-2-promise)" /> <MESSAGE value="Nano zoom fix #16 (ssh-2-promise)" />
<MESSAGE value="Full return back to old code with minor fixes" /> <MESSAGE value="Full return back to old code with minor fixes" />
<MESSAGE value="Terminal size fix #18 (rows &amp; cols fix)" /> <MESSAGE value="Terminal size fix #18 (rows &amp; cols fix)" />
<option name="LAST_COMMIT_MESSAGE" value="Terminal size fix #18 (rows &amp; cols fix)" /> <MESSAGE value="Test ntfy build notification system" />
<option name="LAST_COMMIT_MESSAGE" value="Test ntfy build notification system" />
</component> </component>
</project> </project>

View File

@@ -50,8 +50,8 @@ wss.on('connection', (ws) => {
} }
// Set the terminal size dynamically based on the WebSocket message // Set the terminal size dynamically based on the WebSocket message
const sttyCommand = `export TERM=xterm && stty rows ${data.rows} cols ${data.cols}`; const sttyCommand = `stty -echo rows ${data.rows} cols ${data.cols}\n`;
stream.write(sttyCommand + '\n'); // Send the stty command to set terminal size stream.write(sttyCommand);
// Handle data from SSH session // Handle data from SSH session
stream.on('data', (data) => { stream.on('data', (data) => {
@@ -66,9 +66,14 @@ wss.on('connection', (ws) => {
}); });
// When the WebSocket client sends a message (from terminal input), forward it to the SSH stream // When the WebSocket client sends a message (from terminal input), forward it to the SSH stream
ws.on('message', (message) => { ws.on('message', (msg) => {
console.log(`Received message from WebSocket: ${message}`); const input = JSON.parse(msg);
stream.write(message); // Write the message (input) to the SSH shell if (input.type === 'resize') {
const resizeCommand = `stty rows ${input.rows} cols ${input.cols}\n`;
stream.write(resizeCommand);
} else {
stream.write(input);
}
}); });
}); });
}).on('error', (err) => { }).on('error', (err) => {

View File

@@ -39,25 +39,22 @@ const App = () => {
fitAddon.current.fit(); fitAddon.current.fit();
// Adjust terminal size on window resize // Adjust terminal size on window resize
const resizeListener = () => { const handleResize = () => {
fitAddon.current.fit(); fitAddon.current.fit();
};
window.addEventListener('resize', resizeListener);
// Monitor terminal data (activity)
terminal.current.onData((data) => {
if (socket.current && socket.current.readyState === WebSocket.OPEN) { if (socket.current && socket.current.readyState === WebSocket.OPEN) {
socket.current.send(data); socket.current.send(JSON.stringify({
type: 'resize',
rows: terminal.current.rows,
cols: terminal.current.cols,
}));
} }
}); };
// Cleanup on component unmount window.addEventListener('resize', handleResize);
return () => { return () => {
terminal.current.dispose(); terminal.current.dispose();
if (socket.current) { if (socket.current) socket.current.close();
socket.current.close(); window.removeEventListener('resize', handleResize);
}
window.removeEventListener('resize', resizeListener);
}; };
}, []); }, []);

View File

@@ -1,7 +1,8 @@
Currently: Currently:
make the cmds run at start not show up make the cmds run at start not show up
see if it auto resizes the terminal via cmds after the browser window size has changed or +/- clicked (does not) see if it auto resizes the terminal via cmds after the browser window size has changed or +/- clicked (does not)
ntfy notifcation after build push (I think I did) before release, call this version 1.0 (don't do beta and shit/come uip with naming scheme like 1.1 or just increment by 1 and when to go to next version)
fix all the giuthub workflow problems
Overall Features: Overall Features:
SSH/RDP(?)/VNC(?) SSH/RDP(?)/VNC(?)