ludus-repl/sender.ts

32 lines
668 B
TypeScript
Raw Permalink Normal View History

export async function send() {
const repl_file = Bun.file("./.lrepl")
let repl_info
try {
repl_info = await repl_file.json()
} catch (e) {
console.log("No .lrepl file found.")
process.exit(1)
}
2023-12-27 17:07:24 +00:00
const unix_socket = repl_info.unix_socket
// console.log("Attempting connection to", unix_socket)
const socket = await Bun.connect({
2023-12-27 17:07:24 +00:00
unix: unix_socket,
socket: {
data: () => process.exit()
}
})
for await (const input of Bun.stdin.stream()) {
const chunk = Buffer.from(input).toString("utf-8")
2023-12-27 17:07:24 +00:00
// console.log("Sending:", chunk)
// console.log(`To: ${unix_socket}`)
socket.write(chunk)
socket.end()
process.exit()
}
}
2023-12-27 17:07:24 +00:00
// await send()