Skip to content

Commit

Permalink
Support for case insensitive prefix completion && fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
WangYihang committed Feb 29, 2020
1 parent 2dccd57 commit 1602f28
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/WangYihang/Platypus
go 1.14

require (
github.com/WangYihang/readline v0.0.0-20200229084751-518dcf4f57b3
github.com/chzyer/logex v1.1.10 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/WangYihang/readline v0.0.0-20200229084751-518dcf4f57b3 h1:vnLf9dGMiEb3kgfPpSUs9RCC3HjY+xmwh3EktxwBg3E=
github.com/WangYihang/readline v0.0.0-20200229084751-518dcf4f57b3/go.mod h1:S7Ulsa01ssaZKuWV9IRCrAdCtCdI4dQIt39FYOzAEa4=
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
Expand Down
8 changes: 4 additions & 4 deletions lib/cli/dispatcher/command_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/WangYihang/Platypus/lib/context"
"github.com/WangYihang/Platypus/lib/util/log"
"github.com/WangYihang/Platypus/lib/util/reflection"
"github.com/chzyer/readline"
"github.com/WangYihang/readline"
)

type Dispatcher struct{}
Expand All @@ -19,9 +19,9 @@ func parseInput(input string) (string, []string) {
return "", []string{}
}

args[0] = strings.Title(strings.ToLower(args[0]))
args[0] = strings.Title(args[0])

var validCommand = false
validCommand := false
for _, method := range methods {
if method == args[0] {
validCommand = true
Expand All @@ -46,7 +46,7 @@ func filterInput(r rune) (rune, bool) {

func Run() {
// Register all commands
var completer = readline.NewPrefixCompleter()
completer := readline.NewPrefixCompleter()
children := []readline.PrefixCompleterInterface{}
methods := reflection.GetAllMethods(Dispatcher{})
for _, method := range methods {
Expand Down
29 changes: 15 additions & 14 deletions lib/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package context

import (
"os"
"syscall"
"os/signal"
"syscall"

"github.com/WangYihang/Platypus/lib/util/log"
)

type Context struct {
Servers map[string](*TCPServer)
Current *TCPClient
CommandPrompt string
BlockSameIP int
Servers map[string](*TCPServer)
Current *TCPClient
CommandPrompt string
BlockSameIP int
AllowInterrupt bool
}

Expand All @@ -28,8 +29,8 @@ func Signal() {
// signal.Notify(c, syscall.SIGTSTP)

go func() {
for {
switch sig := <-c; sig {
for {
switch sig := <-c; sig {
case os.Interrupt:
if Ctx.AllowInterrupt {
// CTRL C
Expand All @@ -45,18 +46,18 @@ func Signal() {
i := Ctx.Current.Write([]byte("\x1A"))
log.Error("%d bytes written", i)
}
}
}
}()
}
}
}()
}

func CreateContext() {
if Ctx == nil {
Ctx = &Context{
Servers: make(map[string](*TCPServer)),
Current: nil,
CommandPrompt: ">> ",
BlockSameIP: 1,
Servers: make(map[string](*TCPServer)),
Current: nil,
CommandPrompt: ">> ",
BlockSameIP: 1,
AllowInterrupt: false,
}
}
Expand Down

0 comments on commit 1602f28

Please sign in to comment.