Add edit program
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
async function run(ctx, argv) {
|
||||
const args = argv.slice(1)
|
||||
if (args.includes('-h') || args.includes('--help')) {
|
||||
ctx.console.log(
|
||||
'usage: ' +
|
||||
(argv[0] || 'edit') +
|
||||
' [file]\n' +
|
||||
'Terminal editor with syntax highlighting. Requires a TTY.\n' +
|
||||
'See man edit for key bindings.'
|
||||
)
|
||||
return
|
||||
}
|
||||
let path = 'Untitled'
|
||||
for (const a of args) {
|
||||
if (a && !String(a).startsWith('-')) {
|
||||
path = String(a)
|
||||
break
|
||||
}
|
||||
}
|
||||
const stdin = ctx.replStdin
|
||||
const stdout = ctx.replStdout || ctx.stdout
|
||||
if (!stdin || !/** @type {{ isTTY?: boolean }} */ (stdin).isTTY) {
|
||||
ctx.console.error('edit: a terminal (TTY) is required')
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
if (!stdout) {
|
||||
ctx.console.error('edit: missing stdout')
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
let initial = ''
|
||||
try {
|
||||
const fileBuf = await ctx.vfs.readFile(path)
|
||||
if (fileBuf) initial = ctx.b4a.toString(fileBuf)
|
||||
} catch {
|
||||
initial = ''
|
||||
}
|
||||
const maxChars = 2000000
|
||||
if (initial.length > maxChars) {
|
||||
ctx.console.error('edit: file too large (max ' + maxChars + ' characters)')
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
await bareOsRunEditTui(ctx, {
|
||||
path,
|
||||
initialText: initial,
|
||||
argv0: argv[0] || 'edit'
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
async function run(ctx, argv) {
|
||||
ctx.console.log(
|
||||
'Bare OS — default user: guest | shell builtins: alias, barerc, cd, command, export, exit, login, logout, readonly, type, umask, unalias, unset, : | /bin: awk basename cat chgrp chmod chown cksum clear cp crontab curl cut date dirname dircolors du echo env exit false find getconf grep head hdms help hostname id journalctl jq ln login logout logname ls man mkdir mkfifo mv nl od pathchk printenv printf pwd readlink rm rmdir savevault sed seq sleep sort stat systemctl tail tee test theme time touch tr true tty uname wc wget which whoami xargs'
|
||||
'Bare OS — default user: guest | shell builtins: alias, barerc, cd, command, export, exit, login, logout, readonly, type, umask, unalias, unset, : | /bin: awk basename cat chgrp chmod chown cksum clear cp crontab curl cut date dirname dircolors du edit echo env exit false find getconf grep head hdms help hostname id journalctl jq ln login logout logname ls man mkdir mkfifo mktemp nano mv nl od pathchk printenv printf pwd readlink rm rmdir savevault sed seq sleep sort stat systemctl tail tee test theme time touch tr true tty uname wc wget which whoami xargs'
|
||||
)
|
||||
ctx.console.log(
|
||||
'Docs: man <command> | man handbook (full handbook, section 7) | man bare-os-shell | man -k <word> | man -l'
|
||||
|
||||
Reference in New Issue
Block a user