Connect to terminal in raw mode

Able to use VIM
This commit is contained in:
wancat committed 2023-07-15 15:04:58 +08:00
1 parent 69ef435b77
commit e3d66709e4
2 files changed
+18 -11

No files matched your search

+16 -9
View File
@@ -1,11 +1,13 @@
import readline from 'readline'
import { exit } from 'process'
import { stdin, stdout, exit } from 'process'
import { io } from 'socket.io-client'
import { Writable } from 'stream'
import { pipeline } from 'stream/promises'
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
console.log(stdin)
console.log(process.stdin.isTTY)
stdin.setRawMode(true)
stdin.resume()
stdin.setEncoding('utf8')
const socket = io('ws://localhost:8080')
@@ -14,7 +16,7 @@ socket.on('open', function open() {
})
socket.on('message', function incoming(data) {
console.log(`${data}`)
stdout.write(data)
})
socket.on('close', function close() {
@@ -22,6 +24,11 @@ socket.on('close', function close() {
exit()
})
rl.on('line', (input) => {
socket.send(input)
stdin.on('data', (key) => {
if (key === '\u0003') {
socket.close()
exit()
} else {
socket.send(key)
}
})
+2 -2
View File
@@ -13,12 +13,12 @@ io.on('connection', async (socket) => {
const stream = await attachContainer(container)
stream.on('data', (chunk) => {
socket.send(chunk.toString())
socket.send(chunk)
})
socket.on('message', function incoming(message) {
console.log(`From client: ${message}`)
stream.write(message + '\n')
stream.write(message)
})
socket.on('close', () => {