From 2932f9bf431ba6f677d7d2f1651f2984cb09df45 Mon Sep 17 00:00:00 2001 From: Laukka Date: Mon, 13 Jan 2025 14:28:15 +0100 Subject: [PATCH] added fritiofscommando och att man kan ha " " innan komandon --- command/command.go | 3 ++ hello | 18 +++++++++++ input_parser/input_parser.go | 60 ++++++++++++++++++------------------ 3 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 hello diff --git a/command/command.go b/command/command.go index ef4b76d..77b1f80 100644 --- a/command/command.go +++ b/command/command.go @@ -5,6 +5,7 @@ import ( "bbash/command/cd" "bbash/command/cp" "bbash/command/echo" + "bbash/command/fritiofcommand" "bbash/command/head" "bbash/command/help" "bbash/command/ls" @@ -37,6 +38,8 @@ func Run_command(in input_parser.Input, env *environment.Env) { pwd.Pwd(in, env) case "echo": echo.Echo(in, env) + case "fritiof": + fritiofcommand.Fritiof(in, env) case "ls": ls.Ls(in, env) case "cd": diff --git a/hello b/hello new file mode 100644 index 0000000..84cb812 --- /dev/null +++ b/hello @@ -0,0 +1,18 @@ + a + b + c + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 9 + 9 + 9 + 9 + 9 + 9 diff --git a/input_parser/input_parser.go b/input_parser/input_parser.go index 876e5d6..44d3a47 100644 --- a/input_parser/input_parser.go +++ b/input_parser/input_parser.go @@ -22,10 +22,10 @@ type Input struct { func Parse(env *environment.Env) Input { input := input_str(env) - return parse_input(input) + return parse(input) } -func parse_input(input string) Input { - split := strings.Split(string(input), " ") +func parse(input string) Input { + split := strings.Split(strings.TrimSpace(string(input)), " ") instruction := strings.TrimSpace(split[0]) args_raw := "" @@ -36,14 +36,11 @@ func parse_input(input string) Input { var flags []string var args []string for _, arg := range split[1:] { - if len(arg) == 0 { - continue - } else if len(arg) == 1 { + if len(arg) == 1 { if arg[0] == '-' { continue - } else { - args = append(args, strings.TrimSpace(arg)) } + _ = append(args, string(arg[0])) } else if arg[0:2] == "--" { var result = strings.TrimSpace(arg) flags = append(flags, string(result[2:])) @@ -87,7 +84,7 @@ func input_str(env *environment.Env) string { for { r_rune, _, err := reader.ReadRune() 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 { case 3: // ^C @@ -96,27 +93,32 @@ func input_str(env *environment.Env) string { case 4: // ^D input = "exit" goto loop_exit - case 9: // Tab - input = AutoComplete(input) - case 91: - if r, _, _ := reader.ReadRune(); r == 65 { // UPP - if history_index > 0 { - history_index-- - input = env.History[history_index] - } - break - - } - if r, _, _ := reader.ReadRune(); r != 66 { //DOWN - if history_index < len(env.History)-2 { - history_index++ - input = env.History[history_index] - } else { - input = "" - } + case 27: // UPP + if r, _, _ := reader.ReadRune(); r != 91 { break } - + case 66: // DOWN + if history_index < len(env.History)-2 { + history_index++ + input = env.History[history_index] + } else { + history_index = len(env.History) - 1 + 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 127: //packspace if len(input) > 0 { input = input[:len(input)-1] @@ -127,11 +129,9 @@ func input_str(env *environment.Env) string { input = input + string(r_rune) } env.History[len(env.History)-1] = input - fmt.Print("\r") fmt.Print("\r\033[K") fmt.Print(env.Path) fmt.Print(" > ") - fmt.Print("\033[K") fmt.Print(input) } loop_exit: