Merge branch 'refs/heads/master' into minbranch

This commit is contained in:
Laukka 2025-01-12 17:55:50 +01:00
commit a785c7df3b
2 changed files with 20 additions and 9 deletions

View File

@ -81,7 +81,7 @@ func input_str(env *environment.Env) string {
for { for {
r_rune, _, err := reader.ReadRune() r_rune, _, err := reader.ReadRune()
if err != nil { if err != nil {
fmt.Print(fmt.Sprintf("Error reading user input: ", err.Error())) fmt.Print(fmt.Sprintf("Error reading user input: %s", err.Error()))
} }
switch r_rune { switch r_rune {
case 3: // ^C case 3: // ^C
@ -90,10 +90,9 @@ func input_str(env *environment.Env) string {
case 4: // ^D case 4: // ^D
input = "exit" input = "exit"
goto loop_exit goto loop_exit
case 65: // UPP case 27: // UPP
if history_index > 0 { if r, _, _ := reader.ReadRune(); r != 91 {
history_index-- break
input = env.History[history_index]
} }
case 66: // DOWN case 66: // DOWN
if history_index < len(env.History)-2 { if history_index < len(env.History)-2 {
@ -102,9 +101,21 @@ func input_str(env *environment.Env) string {
} else { } else {
history_index = len(env.History)-1 history_index = len(env.History)-1
input = "" input = ""
if r, _, _ := reader.ReadRune(); r == 65 { // UPP
if history_index > 0 {
history_index--
input = env.History[history_index]
}
}
if r, _, _ := reader.ReadRune(); r != 66 { //DOWN
if history_index < len(env.History)-1 {
history_index++
input = env.History[history_index]
} else {
input = ""
}
}
} }
case 67: // LEFT
case 68: // RIGHT
case 127: //packspace case 127: //packspace
if len(input) > 0 { if len(input) > 0 {
input = input[:len(input)-1] input = input[:len(input)-1]
@ -120,7 +131,7 @@ func input_str(env *environment.Env) string {
fmt.Print(" > ") fmt.Print(" > ")
fmt.Print(input) fmt.Print(input)
} }
loop_exit: loop_exit:
term.Restore(int(std_fd), term_restore) term.Restore(int(std_fd), term_restore)
fmt.Println() fmt.Println()
return input return input