added fritiofscommando och att man kan ha " " innan komandon
This commit is contained in:
parent
6c63fc7122
commit
2932f9bf43
@ -5,6 +5,7 @@ import (
|
|||||||
"bbash/command/cd"
|
"bbash/command/cd"
|
||||||
"bbash/command/cp"
|
"bbash/command/cp"
|
||||||
"bbash/command/echo"
|
"bbash/command/echo"
|
||||||
|
"bbash/command/fritiofcommand"
|
||||||
"bbash/command/head"
|
"bbash/command/head"
|
||||||
"bbash/command/help"
|
"bbash/command/help"
|
||||||
"bbash/command/ls"
|
"bbash/command/ls"
|
||||||
@ -37,6 +38,8 @@ func Run_command(in input_parser.Input, env *environment.Env) {
|
|||||||
pwd.Pwd(in, env)
|
pwd.Pwd(in, env)
|
||||||
case "echo":
|
case "echo":
|
||||||
echo.Echo(in, env)
|
echo.Echo(in, env)
|
||||||
|
case "fritiof":
|
||||||
|
fritiofcommand.Fritiof(in, env)
|
||||||
case "ls":
|
case "ls":
|
||||||
ls.Ls(in, env)
|
ls.Ls(in, env)
|
||||||
case "cd":
|
case "cd":
|
||||||
|
|||||||
@ -22,10 +22,10 @@ type Input struct {
|
|||||||
|
|
||||||
func Parse(env *environment.Env) Input {
|
func Parse(env *environment.Env) Input {
|
||||||
input := input_str(env)
|
input := input_str(env)
|
||||||
return parse_input(input)
|
return parse(input)
|
||||||
}
|
}
|
||||||
func parse_input(input string) Input {
|
func parse(input string) Input {
|
||||||
split := strings.Split(string(input), " ")
|
split := strings.Split(strings.TrimSpace(string(input)), " ")
|
||||||
instruction := strings.TrimSpace(split[0])
|
instruction := strings.TrimSpace(split[0])
|
||||||
|
|
||||||
args_raw := ""
|
args_raw := ""
|
||||||
@ -36,14 +36,11 @@ func parse_input(input string) Input {
|
|||||||
var flags []string
|
var flags []string
|
||||||
var args []string
|
var args []string
|
||||||
for _, arg := range split[1:] {
|
for _, arg := range split[1:] {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 1 {
|
||||||
continue
|
|
||||||
} else if len(arg) == 1 {
|
|
||||||
if arg[0] == '-' {
|
if arg[0] == '-' {
|
||||||
continue
|
continue
|
||||||
} else {
|
|
||||||
args = append(args, strings.TrimSpace(arg))
|
|
||||||
}
|
}
|
||||||
|
_ = append(args, string(arg[0]))
|
||||||
} else if arg[0:2] == "--" {
|
} else if arg[0:2] == "--" {
|
||||||
var result = strings.TrimSpace(arg)
|
var result = strings.TrimSpace(arg)
|
||||||
flags = append(flags, string(result[2:]))
|
flags = append(flags, string(result[2:]))
|
||||||
@ -87,7 +84,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
|
||||||
@ -96,27 +93,32 @@ func input_str(env *environment.Env) string {
|
|||||||
case 4: // ^D
|
case 4: // ^D
|
||||||
input = "exit"
|
input = "exit"
|
||||||
goto loop_exit
|
goto loop_exit
|
||||||
case 9: // Tab
|
case 27: // UPP
|
||||||
input = AutoComplete(input)
|
if r, _, _ := reader.ReadRune(); r != 91 {
|
||||||
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 = ""
|
|
||||||
}
|
|
||||||
break
|
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
|
case 127: //packspace
|
||||||
if len(input) > 0 {
|
if len(input) > 0 {
|
||||||
input = input[:len(input)-1]
|
input = input[:len(input)-1]
|
||||||
@ -127,11 +129,9 @@ func input_str(env *environment.Env) string {
|
|||||||
input = input + string(r_rune)
|
input = input + string(r_rune)
|
||||||
}
|
}
|
||||||
env.History[len(env.History)-1] = input
|
env.History[len(env.History)-1] = input
|
||||||
fmt.Print("\r")
|
|
||||||
fmt.Print("\r\033[K")
|
fmt.Print("\r\033[K")
|
||||||
fmt.Print(env.Path)
|
fmt.Print(env.Path)
|
||||||
fmt.Print(" > ")
|
fmt.Print(" > ")
|
||||||
fmt.Print("\033[K")
|
|
||||||
fmt.Print(input)
|
fmt.Print(input)
|
||||||
}
|
}
|
||||||
loop_exit:
|
loop_exit:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user