fix history indexing down

This commit is contained in:
2025-02-22 01:39:21 -05:00
parent 1fe21b1592
commit bf40d524b7
3 changed files with 9 additions and 8 deletions

View File

@ -8,8 +8,8 @@ interface EnterArgs {
readonly closure: InputClosure readonly closure: InputClosure
} }
interface Keys { interface Keys {
enter: (input: EnterArgs) => void, enter: (input: EnterArgs) => void,
up_arrow: (ps1input: HTMLInputElement) => void, up_arrow: (ps1input: HTMLInputElement) => void,
down_arrow: (ps1input: HTMLInputElement) => void, down_arrow: (ps1input: HTMLInputElement) => void,
} }

View File

@ -1,4 +1,4 @@
import history_cmd from "./builtin/history" import history from "./builtin/history"
import clear from "./builtin/clear" import clear from "./builtin/clear"
import pwd from "./builtin/pwd" import pwd from "./builtin/pwd"
import cat from "./builtin/cat" import cat from "./builtin/cat"
@ -8,12 +8,13 @@ import ls from "./builtin/ls"
type Term = HTMLElement type Term = HTMLElement
type Args = string[] type Args = string[]
type Command = (term: Term, args: Args) => boolean type Command = (term: Term, args: Args) => boolean
interface CommandsList { interface CommandsList {
[index: string]: Command, [index: string]: Command,
} }
const commands: CommandsList = { const commands: CommandsList = {
["history"]: history_cmd, ["history"]: history,
["clear"]: clear, ["clear"]: clear,
["pwd"]: pwd, ["pwd"]: pwd,
["cat"]: cat, ["cat"]: cat,

View File

@ -4,9 +4,9 @@ interface HistoryFile {
cursor_reset: () => void cursor_reset: () => void
} }
interface History { interface History {
file: HistoryFile file: HistoryFile
add: (cmd: string) => void, add: (cmd: string) => void,
index_up: (ps1input: HTMLInputElement) => void, index_up: (ps1input: HTMLInputElement) => void,
index_down: (ps1input: HTMLInputElement) => void index_down: (ps1input: HTMLInputElement) => void
} }
@ -36,7 +36,7 @@ history.index_down = function(ps1input: HTMLInputElement) {
if (this.file.cursor!==0) { if (this.file.cursor!==0) {
this.file.cursor-=1 this.file.cursor-=1
if (this.file.cursor!==0) { if (this.file.cursor!==0) {
const item = this.file.inner[this.file.cursor] const item = this.file.inner[this.file.cursor-1]
if (item) { ps1input.value = item } if (item) { ps1input.value = item }
} else { } else {
this.file.cursor_reset() this.file.cursor_reset()