diff --git a/src/components/client/shell/command/builtin/history.ts b/src/components/client/shell/command/builtin/history.ts new file mode 100644 index 0000000..3630227 --- /dev/null +++ b/src/components/client/shell/command/builtin/history.ts @@ -0,0 +1,31 @@ +import type { Args, Term } from "../list"; +import { bold } from "../../color"; + +import stdout, { stdout_horizontal } from "../../../elements/stdout"; +import SubCommand, { type SubCommandAction } from "../subcommand"; +import history from "../../history"; +import create from "../../../elements/create"; + +const history_command = new SubCommand("show and manipulate command history") + +history_command.add("show", [], "Show the history", function(term: Term) { + history.file.inner.forEach((entry, ind) => term.appendChild(stdout(`${ind} ${entry}`))) +}) + +history_command.add("clear", ["delete"], "Delete the command history", function(term: Term) { + const entries = history.file.inner.length + history.file.inner = [] + term.appendChild(stdout(`Cleared ${entries} entries from the history.`)) +}) + +export default function history_cmd(term: Term, args: Args) { + const subc = args[1] + if (subc) { + const subc_f = history_command.data[subc] + if (subc_f) { subc_f.inner(term) } else { + term.appendChild(SubCommand.unknown("history", subc)) + history_command.data.help.inner(term) + } + } + return true +} \ No newline at end of file diff --git a/src/components/client/shell/command/history.ts b/src/components/client/shell/command/history.ts deleted file mode 100644 index d4c0af1..0000000 --- a/src/components/client/shell/command/history.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { Args, Term } from "./list"; -import { bold } from "../color"; - -import stdout, { stdout_horizontal } from "../../elements/stdout"; -import subcmd, { type SubCommandAction } from "./subcommand"; -import history from "../history"; -import create from "../../elements/create"; - -const history_command = subcmd() - -history_command.show = {} as SubCommandAction -history_command.show.inner = function(term: Term) { - history.file.inner.forEach((entry, ind) => term.appendChild(stdout(`${ind} ${entry}`))) -} -history_command.show.description = "Show the history" - -export default function history_cmd(term: Term, args: Args) { - const subc = args[1] - if (subc) { - const subc_f = history_command[subc] - if (subc_f) { subc_f.inner(term) } else { history_command.help.inner(term) } - } - return true -} \ No newline at end of file