mirror of
https://github.com/kemko/xc.git
synced 2026-01-01 15:55:43 +03:00
A little customization prompt (#9)
* Add new param in config: show_ssh_threads(bool), show_ssh_threads_min(int) and show_ssh_threads_max(int) for shows this in prompt * fix CamelCase to lowerCamelCase in cli/cli.go --------- Co-authored-by: Yuri Kurilkin <y.kurilkin@corp.mail.ru>
This commit is contained in:
16
cli/cli.go
16
cli/cli.go
@@ -43,6 +43,9 @@ type Cli struct {
|
|||||||
|
|
||||||
exitConfirm bool
|
exitConfirm bool
|
||||||
execConfirm bool
|
execConfirm bool
|
||||||
|
showSsh bool
|
||||||
|
showSshMin int
|
||||||
|
showSshMax int
|
||||||
prependHostnames bool
|
prependHostnames bool
|
||||||
progressBar bool
|
progressBar bool
|
||||||
debug bool
|
debug bool
|
||||||
@@ -106,6 +109,9 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) {
|
|||||||
|
|
||||||
cli.exitConfirm = cfg.ExitConfirm
|
cli.exitConfirm = cfg.ExitConfirm
|
||||||
cli.execConfirm = cfg.ExecConfirm
|
cli.execConfirm = cfg.ExecConfirm
|
||||||
|
cli.showSsh = cfg.ShowSsh
|
||||||
|
cli.showSshMin = cfg.ShowSshMin
|
||||||
|
cli.showSshMax = cfg.ShowSshMax
|
||||||
cli.delay = cfg.Delay
|
cli.delay = cfg.Delay
|
||||||
cli.user = cfg.User
|
cli.user = cfg.User
|
||||||
cli.sshThreads = cfg.SSHThreads
|
cli.sshThreads = cfg.SSHThreads
|
||||||
@@ -181,6 +187,16 @@ func (c *Cli) setPrompt() {
|
|||||||
pr = term.Green(pr)
|
pr = term.Green(pr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.showSsh {
|
||||||
|
if c.sshThreads > c.showSshMax {
|
||||||
|
pr += term.Colored(fmt.Sprintf("[%d]", c.sshThreads), term.CLightRed, false)
|
||||||
|
} else if c.sshThreads < c.showSshMin {
|
||||||
|
pr += term.Colored(fmt.Sprintf("[%d]", c.sshThreads), term.CLightYellow, false)
|
||||||
|
} else {
|
||||||
|
pr += term.Colored(fmt.Sprintf("[%d]", c.sshThreads), term.CLightBlue, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pr += " " + term.Colored(c.user, term.CLightBlue, true)
|
pr += " " + term.Colored(c.user, term.CLightBlue, true)
|
||||||
switch c.raiseType {
|
switch c.raiseType {
|
||||||
case remote.RTSu:
|
case remote.RTSu:
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ raise = none
|
|||||||
exit_confirm = true
|
exit_confirm = true
|
||||||
exec_confirm = true
|
exec_confirm = true
|
||||||
distribute = tar
|
distribute = tar
|
||||||
|
show_ssh_threads = true
|
||||||
|
show_ssh_threads_min = 5
|
||||||
|
show_ssh_threads_max = 50
|
||||||
|
|
||||||
[executer]
|
[executer]
|
||||||
ssh_threads = 50
|
ssh_threads = 50
|
||||||
@@ -93,6 +96,9 @@ type XCConfig struct {
|
|||||||
LogFile string
|
LogFile string
|
||||||
ExitConfirm bool
|
ExitConfirm bool
|
||||||
ExecConfirm bool
|
ExecConfirm bool
|
||||||
|
ShowSsh bool
|
||||||
|
ShowSshMin int
|
||||||
|
ShowSshMax int
|
||||||
SudoInterpreter string
|
SudoInterpreter string
|
||||||
SuInterpreter string
|
SuInterpreter string
|
||||||
Interpreter string
|
Interpreter string
|
||||||
@@ -121,6 +127,9 @@ const (
|
|||||||
defaultLogFile = ""
|
defaultLogFile = ""
|
||||||
defaultExitConfirm = true
|
defaultExitConfirm = true
|
||||||
defaultExecConfirm = true
|
defaultExecConfirm = true
|
||||||
|
defaultShowSshThreads = true
|
||||||
|
defaultShowSshThreadsMin = 5
|
||||||
|
defaultShowSshThreadsMax = 50
|
||||||
defaultInterpreter = "/bin/bash"
|
defaultInterpreter = "/bin/bash"
|
||||||
defaultSudoInterpreter = "sudo /bin/bash"
|
defaultSudoInterpreter = "sudo /bin/bash"
|
||||||
defaultSuInterpreter = "su -"
|
defaultSuInterpreter = "su -"
|
||||||
@@ -296,6 +305,24 @@ func read(filename string, secondPass bool) (*XCConfig, error) {
|
|||||||
}
|
}
|
||||||
cfg.ExecConfirm = execcnfrm
|
cfg.ExecConfirm = execcnfrm
|
||||||
|
|
||||||
|
shwsshthrds, err := props.GetBool("main.show_ssh_threads")
|
||||||
|
if err != nil {
|
||||||
|
shwsshthrds = defaultShowSshThreads
|
||||||
|
}
|
||||||
|
cfg.ShowSsh = shwsshthrds
|
||||||
|
|
||||||
|
shwsshthrdsmin, err := props.GetInt("main.show_ssh_threads_min")
|
||||||
|
if err != nil {
|
||||||
|
shwsshthrdsmin = defaultShowSshThreadsMin
|
||||||
|
}
|
||||||
|
cfg.ShowSshMin = shwsshthrdsmin
|
||||||
|
|
||||||
|
shwsshthrdsmax, err := props.GetInt("main.show_ssh_threads_max")
|
||||||
|
if err != nil {
|
||||||
|
shwsshthrdsmax = defaultShowSshThreadsMax
|
||||||
|
}
|
||||||
|
cfg.ShowSshMax = shwsshthrdsmax
|
||||||
|
|
||||||
pbar, err := props.GetBool("executer.progress_bar")
|
pbar, err := props.GetBool("executer.progress_bar")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pbar = defaultProgressbar
|
pbar = defaultProgressbar
|
||||||
|
|||||||
Reference in New Issue
Block a user