Chat TUI
This commit is contained in:
@@ -1,12 +1,30 @@
|
||||
/**
|
||||
* Swarm chat CLI — uses ctx.bareOsChat* when the booter exposes swarm chat (bare-os-chat-v1).
|
||||
* Swarm chat — full-screen TUI on a TTY (like edit/nano); scriptable subcommands otherwise.
|
||||
*/
|
||||
async function run(ctx, argv) {
|
||||
const cs = ctx.bareOsChatSend
|
||||
const sub = argv[1] || ''
|
||||
const rest = argv.slice(2).join(' ').trim()
|
||||
const args = argv.slice(1)
|
||||
if (args.includes('-h') || args.includes('--help')) {
|
||||
ctx.console.log(
|
||||
'usage: ' +
|
||||
(argv[0] || 'chat') +
|
||||
' [send TEXT | history [N] | who | join]\n' +
|
||||
'With no arguments on a terminal: full-screen swarm chat (bare-os-chat-v1).\n' +
|
||||
'Requires host booter with swarm chat (see BARE_OS_PROTOMUX_CHAT_CHANNEL).\n' +
|
||||
'See man chat.'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (sub === 'send' && rest) {
|
||||
const sub = args[0] || ''
|
||||
const cs = ctx.bareOsChatSend
|
||||
|
||||
if (sub === 'send') {
|
||||
const rest = args.slice(1).join(' ').trim()
|
||||
if (!rest) {
|
||||
ctx.console.error('chat: send requires text')
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
if (typeof cs !== 'function') {
|
||||
ctx.console.error(
|
||||
'chat: bareOsChatSend unavailable — stock hosts enable swarm chat unless BARE_OS_PROTOMUX_CHAT_CHANNEL=0'
|
||||
@@ -20,7 +38,7 @@ async function run(ctx, argv) {
|
||||
}
|
||||
|
||||
if (sub === 'history') {
|
||||
const n = argv[2] ? Number.parseInt(argv[2], 10) : 20
|
||||
const n = args[1] ? Number.parseInt(args[1], 10) : 20
|
||||
const hist =
|
||||
typeof ctx.vfs?.readFile === 'function'
|
||||
? await ctx.vfs.readFile('/proc/bare_os/chat.json')
|
||||
@@ -45,24 +63,24 @@ async function run(ctx, argv) {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof ctx.readLine !== 'function' || typeof cs !== 'function') {
|
||||
const stdin = ctx.replStdin
|
||||
const stdout = ctx.replStdout || ctx.stdout
|
||||
const isTTY = Boolean(stdin && /** @type {{ isTTY?: boolean }} */ (stdin).isTTY)
|
||||
if (!isTTY || !stdout) {
|
||||
ctx.console.error(
|
||||
'chat: interactive mode requires bareOsChatSend and readLine (host booter; chat off if BARE_OS_PROTOMUX_CHAT_CHANNEL=0)'
|
||||
'chat: a terminal (TTY) is required for full-screen mode; use: chat send TEXT, chat history, chat who'
|
||||
)
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
ctx.console.log('[chat] general room — type a line; /quit to exit')
|
||||
while (true) {
|
||||
const line = await ctx.readLine('chat> ')
|
||||
if (line == null) break
|
||||
const t = line.trim()
|
||||
if (t === '/quit' || t === '/exit') break
|
||||
if (!t) continue
|
||||
const r = cs.call(ctx, t)
|
||||
if (r && r.ok === false) {
|
||||
ctx.console.error('chat: send failed')
|
||||
}
|
||||
if (typeof cs !== 'function') {
|
||||
ctx.console.error(
|
||||
'chat: swarm chat unavailable on this host — stock default is on unless BARE_OS_PROTOMUX_CHAT_CHANNEL=0'
|
||||
)
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
await bareOsRunChatTui(ctx, argv[0] || 'chat')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user