added fritiofscommando och att man kan ha " " innan komandon

This commit is contained in:
Laukka 2025-01-13 14:28:15 +01:00
parent 6c63fc7122
commit 2932f9bf43
3 changed files with 51 additions and 30 deletions

View File

@ -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":

18
hello Normal file
View File

@ -0,0 +1,18 @@
a
b
c
1
2
3
4
5
6
7
8
9
9
9
9
9
9
9

View File

@ -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: