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:
yukra
2023-03-31 02:12:37 +03:00
committed by GitHub
parent 47c7361bf1
commit a6359ac0d8
2 changed files with 43 additions and 0 deletions

View File

@@ -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:

View File

@@ -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