From a6359ac0d8f49314297bfe7dc04bf6bc48abf8ef Mon Sep 17 00:00:00 2001 From: yukra Date: Fri, 31 Mar 2023 02:12:37 +0300 Subject: [PATCH] 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 --- cli/cli.go | 16 ++++++++++++++++ config/config.go | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/cli/cli.go b/cli/cli.go index 727e1ff..072024a 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -43,6 +43,9 @@ type Cli struct { exitConfirm bool execConfirm bool + showSsh bool + showSshMin int + showSshMax int prependHostnames bool progressBar bool debug bool @@ -106,6 +109,9 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) { cli.exitConfirm = cfg.ExitConfirm cli.execConfirm = cfg.ExecConfirm + cli.showSsh = cfg.ShowSsh + cli.showSshMin = cfg.ShowSshMin + cli.showSshMax = cfg.ShowSshMax cli.delay = cfg.Delay cli.user = cfg.User cli.sshThreads = cfg.SSHThreads @@ -181,6 +187,16 @@ func (c *Cli) setPrompt() { 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) switch c.raiseType { case remote.RTSu: diff --git a/config/config.go b/config/config.go index ed3e5b2..7c7f8a8 100644 --- a/config/config.go +++ b/config/config.go @@ -23,6 +23,9 @@ raise = none exit_confirm = true exec_confirm = true distribute = tar +show_ssh_threads = true +show_ssh_threads_min = 5 +show_ssh_threads_max = 50 [executer] ssh_threads = 50 @@ -93,6 +96,9 @@ type XCConfig struct { LogFile string ExitConfirm bool ExecConfirm bool + ShowSsh bool + ShowSshMin int + ShowSshMax int SudoInterpreter string SuInterpreter string Interpreter string @@ -121,6 +127,9 @@ const ( defaultLogFile = "" defaultExitConfirm = true defaultExecConfirm = true + defaultShowSshThreads = true + defaultShowSshThreadsMin = 5 + defaultShowSshThreadsMax = 50 defaultInterpreter = "/bin/bash" defaultSudoInterpreter = "sudo /bin/bash" defaultSuInterpreter = "su -" @@ -296,6 +305,24 @@ func read(filename string, secondPass bool) (*XCConfig, error) { } 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") if err != nil { pbar = defaultProgressbar