Compare commits
14 Commits
45f50a95ce
...
0216b72d65
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0216b72d65 | ||
|
|
35af0423a7 | ||
|
|
3c166dda98 | ||
|
|
e6e223b6a7 | ||
|
|
d4757c154b | ||
|
|
45cf77ed2a | ||
|
|
0525f346b4 | ||
|
|
15da22bc16 | ||
|
|
642d1780b6 | ||
|
|
2932f9bf43 | ||
|
|
6c63fc7122 | ||
|
|
a545c4cab3 | ||
| 2661860245 | |||
|
|
aad4da3077 |
@ -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"
|
||||
@ -14,6 +15,7 @@ import (
|
||||
"bbash/command/rm"
|
||||
"bbash/command/tail"
|
||||
"bbash/command/touch"
|
||||
"bbash/command/whereareyou"
|
||||
"bbash/environment"
|
||||
"bbash/input_parser"
|
||||
"fmt"
|
||||
@ -33,6 +35,8 @@ func Init(env *environment.Env) {
|
||||
|
||||
func Run_command(in input_parser.Input, env *environment.Env) {
|
||||
switch in.Instruction {
|
||||
case "fritiofcommand":
|
||||
fritiofcommand.Fritiof(in, env)
|
||||
case "pwd":
|
||||
pwd.Pwd(in, env)
|
||||
case "echo":
|
||||
@ -59,6 +63,8 @@ func Run_command(in input_parser.Input, env *environment.Env) {
|
||||
help.Help(in, env)
|
||||
case "tail":
|
||||
tail.Tail(in, env)
|
||||
case "whereareyou":
|
||||
whereareyou.Whereareyou(in, env)
|
||||
default:
|
||||
if !run_by_path(in, env) {
|
||||
fmt.Println(fmt.Sprintf("No such command! (%s)", in.Instruction))
|
||||
|
||||
12
command/fritiofcommand/fritiof.go
Normal file
12
command/fritiofcommand/fritiof.go
Normal file
@ -0,0 +1,12 @@
|
||||
package fritiofcommand
|
||||
|
||||
import (
|
||||
"bbash/environment"
|
||||
"bbash/input_parser"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Fritiof(in input_parser.Input, _ *environment.Env) {
|
||||
fmt.Print("Sannolikheten för läkarlinjen är mycket hög!")
|
||||
// fritiof
|
||||
}
|
||||
11
command/whereareyou/whereareyou.go
Normal file
11
command/whereareyou/whereareyou.go
Normal file
@ -0,0 +1,11 @@
|
||||
package whereareyou
|
||||
|
||||
import (
|
||||
"bbash/environment"
|
||||
"bbash/input_parser"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Whereareyou(in input_parser.Input, env *environment.Env) {
|
||||
fmt.Println("You're in the thick of it everybody knows!")
|
||||
}
|
||||
@ -27,7 +27,7 @@ func Parse(env *environment.Env) Input {
|
||||
return Parse_input(input)
|
||||
}
|
||||
func Parse_input(input string) Input {
|
||||
split := strings.Split(string(input), " ")
|
||||
split := strings.Split(strings.TrimSpace(string(input)), " ")
|
||||
instruction := strings.TrimSpace(split[0])
|
||||
|
||||
args_raw := ""
|
||||
@ -38,14 +38,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:]))
|
||||
@ -88,11 +85,8 @@ func input_str(env *environment.Env) string {
|
||||
|
||||
for {
|
||||
r_rune, _, err := reader.ReadRune()
|
||||
|
||||
// fmt.Printf("Rune: %d\n", r_rune)
|
||||
|
||||
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
|
||||
@ -101,36 +95,36 @@ func input_str(env *environment.Env) string {
|
||||
case 4: // ^D
|
||||
input = "exit"
|
||||
goto loop_exit
|
||||
|
||||
case 9: // Tab
|
||||
// fmt.Println("test tab")
|
||||
case 9: // TAB
|
||||
input = AutoComplete(input)
|
||||
// fmt.Println(input)
|
||||
|
||||
case 27: // arrow?
|
||||
case 27: // UPP
|
||||
if r, _, _ := reader.ReadRune(); r != 91 {
|
||||
break
|
||||
}
|
||||
if r, _, _ := reader.ReadRune(); r == 65 { // UPP
|
||||
if history_index > 0 {
|
||||
history_index--
|
||||
input = env.History[history_index]
|
||||
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]
|
||||
}
|
||||
}
|
||||
break
|
||||
|
||||
}
|
||||
if r, _, _ := reader.ReadRune(); r != 66 { //DOWN
|
||||
if history_index < len(env.History)-1 {
|
||||
history_index++
|
||||
input = env.History[history_index]
|
||||
} else {
|
||||
input = ""
|
||||
if r, _, _ := reader.ReadRune(); r != 66 { //DOWN
|
||||
if history_index < len(env.History)-1 {
|
||||
history_index++
|
||||
input = env.History[history_index]
|
||||
} else {
|
||||
input = ""
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 62:
|
||||
input = input + prevGhostString
|
||||
|
||||
case 127: //packspace
|
||||
if len(input) > 0 {
|
||||
input = input[:len(input)-1]
|
||||
@ -140,17 +134,12 @@ func input_str(env *environment.Env) string {
|
||||
default:
|
||||
input = input + string(r_rune)
|
||||
}
|
||||
|
||||
ghost_input := AutoCompleteHistory(input, *env)
|
||||
|
||||
env.History[len(env.History)-1] = input
|
||||
//fmt.Println(r_rune)
|
||||
fmt.Print("\r")
|
||||
// fmt.Print("\r\033[K")
|
||||
|
||||
fmt.Print(env.Path)
|
||||
fmt.Print(" > ")
|
||||
fmt.Print("\033[K")
|
||||
fmt.Print(" > \033[K")
|
||||
fmt.Print(input)
|
||||
fmt.Print("\033[2m", ghost_input, "\033[0m")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user