Commit a9e4d5f4 authored by Eric's avatar Eric

Merge branch 'master' of https://github.com/LeeEirc/cocogo

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