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
}
interface Keys {
enter: (input: EnterArgs) => void,
up_arrow: (ps1input: HTMLInputElement) => void,
enter: (input: EnterArgs) => void,
up_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 pwd from "./builtin/pwd"
import cat from "./builtin/cat"
@ -8,12 +8,13 @@ import ls from "./builtin/ls"
type Term = HTMLElement
type Args = string[]
type Command = (term: Term, args: Args) => boolean
interface CommandsList {
[index: string]: Command,
}
const commands: CommandsList = {
["history"]: history_cmd,
["history"]: history,
["clear"]: clear,
["pwd"]: pwd,
["cat"]: cat,

View File

@ -4,9 +4,9 @@ interface HistoryFile {
cursor_reset: () => void
}
interface History {
file: HistoryFile
add: (cmd: string) => void,
index_up: (ps1input: HTMLInputElement) => void,
file: HistoryFile
add: (cmd: string) => void,
index_up: (ps1input: HTMLInputElement) => void,
index_down: (ps1input: HTMLInputElement) => void
}
@ -36,7 +36,7 @@ history.index_down = function(ps1input: HTMLInputElement) {
if (this.file.cursor!==0) {
this.file.cursor-=1
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 }
} else {
this.file.cursor_reset()