Commit 43e6c50b authored by ibuler's avatar ibuler

[Update] 优化结构

parent 4fdac63b
......@@ -33,6 +33,14 @@
revision = "f55edac94c9bbba5d6182a4be46d86a2c9b5b50e"
version = "v1.0.2"
[[projects]]
digest = "1:47dc4f6ee8a7dda99b516b56cb7fcc4f53ca94756263bdcea55c918a60126062"
name = "github.com/kr/pty"
packages = ["."]
pruneopts = "UT"
revision = "521317be5ebc228a0f0ede099fa2a0b5ece22e49"
version = "v1.1.4"
[[projects]]
digest = "1:0356f3312c9bd1cbeda81505b7fd437501d8e778ab66998ef69f00d7f9b3a0d7"
name = "github.com/mattn/go-runewidth"
......@@ -116,6 +124,7 @@
input-imports = [
"github.com/gliderlabs/ssh",
"github.com/jarcoal/httpmock",
"github.com/kr/pty",
"github.com/olekukonko/tablewriter",
"github.com/satori/go.uuid",
"github.com/sirupsen/logrus",
......
......@@ -12,7 +12,7 @@ func init() {
customFormatter := &logrus.TextFormatter{
DisableColors: false,
FullTimestamp: true,
DisableLevelTruncation: true,
DisableLevelTruncation: false,
}
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
logger.SetFormatter(customFormatter)
......
......@@ -40,15 +40,15 @@ func (mi *MenuItem) Text() string {
type Menu []MenuItem
var menu = Menu{
{instruct: "ID", helpText: "directly login or enter."},
{instruct: "part IP, Hostname, Comment", helpText: "to search login if unique."},
{instruct: "/ + IP, Hostname, Comment", helpText: "to search, such as: /192.168"},
{instruct: "p", helpText: "display the host you have permission."},
{instruct: "g", helpText: "display the node that you have permission."},
{instruct: "r", helpText: "refresh your assets and nodes"},
{instruct: "s", helpText: "switch Chinese-english language."},
{instruct: "h", helpText: "print help"},
{instruct: "q", helpText: "exit"},
{id: 1, instruct: "ID", helpText: "directly login or enter"},
{id: 2, instruct: "part IP, Hostname, Comment", helpText: "to search login if unique"},
{id: 3, instruct: "/ + IP, Hostname, Comment", helpText: "to search, such as: /192.168"},
{id: 4, instruct: "p", helpText: "display the host you have permission"},
{id: 5, instruct: "g", helpText: "display the node that you have permission"},
{id: 6, instruct: "r", helpText: "refresh your assets and nodes"},
{id: 7, instruct: "s", helpText: "switch Chinese-english language"},
{id: 8, instruct: "h", helpText: "print help"},
{id: 9, instruct: "q", helpText: "exit"},
}
type ColorMeta struct {
......@@ -61,18 +61,12 @@ func displayBanner(sess ssh.Session, user string) {
if config.Conf.HeaderTitle != "" {
title = config.Conf.HeaderTitle
}
welcomeMsg := user + " " + title
welcomeMsg := CharClear + CharTab + user + " " + title + CharNewLine
_, err := io.WriteString(sess, welcomeMsg)
if err != nil {
logger.Error("Send to client error, %s", err)
}
cm := ColorMeta{GreenBoldColor: "\033[1;32m", ColorEnd: "\033[0m"}
for i, v := range menu {
line := fmt.Sprintf("\t%d) Enter {{.GreenBoldColor}}%s{{.ColorEnd}} to %s.\r\n", i+1, v.instruct, v.helpText)
tmpl := template.Must(template.New("item").Parse(line))
err := tmpl.Execute(sess, cm)
if err != nil {
logger.Error("Send to client error, %s", err)
}
for _, v := range menu {
_, _ = io.WriteString(sess, v.Text())
}
}
package handler
const (
GreenColorCode = "\033[32m"
)
const (
GreenColorCode = "\033[32m"
CharClear = "\x1b[H\x1b[2J"
CharTab = "\t"
CharNewLine = "\r\n"
AssetsMapKey = "AssetsMapKey"
AssetNodesMapKey = "AssetNodesKey"
)
......@@ -95,18 +95,18 @@ func (i *InteractiveHandler) Dispatch() {
switch len(line) {
case 0, 1:
switch line {
case "", "p", "P":
switch strings.ToLower(line) {
case "", "p":
i.displayAssets(i.assets)
case "g", "G":
case "g":
i.displayNodes(i.nodes)
case "s", "S":
case "s":
i.changeLanguage()
case "h", "H":
case "h":
i.displayBanner()
case "r", "R":
case "r":
i.refreshAssetsAndNodesData()
case "q", "Q":
case "q":
logger.Info("exit session")
return
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment