Skip to content

Commit

Permalink
support config PromptPageSize
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnywong committed Nov 25, 2023
1 parent 5028bf6 commit d4e8703
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 19 additions & 0 deletions tssh/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -71,6 +72,7 @@ type tsshConfig struct {
exConfigPath string
defaultUploadPath string
defaultDownloadPath string
promptPageSize uint8
loadConfig sync.Once
loadExConfig sync.Once
loadHosts sync.Once
Expand Down Expand Up @@ -123,6 +125,13 @@ func parseTsshConfig() {
userConfig.defaultUploadPath = resolveHomeDir(value)
case name == "defaultdownloadpath" && userConfig.defaultDownloadPath == "":
userConfig.defaultDownloadPath = resolveHomeDir(value)
case name == "promptpagesize" && userConfig.promptPageSize == 0:
pageSize, err := strconv.ParseUint(value, 10, 8)
if err != nil {
warning("PromptPageSize %s is invalid: %v", value, err)
} else {
userConfig.promptPageSize = uint8(pageSize)
}
}
}

Expand All @@ -138,6 +147,9 @@ func parseTsshConfig() {
if userConfig.defaultDownloadPath != "" {
debug("DefaultDownloadPath = %s", userConfig.defaultDownloadPath)
}
if userConfig.promptPageSize != 0 {
debug("PromptPageSize = %d", userConfig.promptPageSize)
}
}

func initUserConfig(configFile string) error {
Expand Down Expand Up @@ -467,3 +479,10 @@ func getSecretConfig(alias, key string) string {
}
return getExConfig(alias, key)
}

func getPromptPageSize() int {
if userConfig.promptPageSize != 0 {
return int(userConfig.promptPageSize)
}
return 10
}
6 changes: 2 additions & 4 deletions tssh/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import (
var promptCursorIcon = "🧨"
var promptSelectedIcon = "🍺"

const promptPageSize = 10

const (
keyCtrlA = '\x01'
keyCtrlB = '\x02'
Expand Down Expand Up @@ -148,7 +146,7 @@ func (p *sshPrompt) getShortcuts() []string {
}

func (p *sshPrompt) getPageCount() int {
return (len(p.hosts)-1)/promptPageSize + 1
return (len(p.hosts)-1)/getPromptPageSize() + 1
}

func (p *sshPrompt) hasSelected() bool {
Expand Down Expand Up @@ -603,7 +601,7 @@ func chooseAlias(keywords string) (string, bool, error) {
Label: "SSH Alias",
Items: hosts,
Templates: templates,
Size: promptPageSize,
Size: getPromptPageSize(),
Searcher: searcher,
Stdin: pipeIn,
Stdout: &bellFilter{os.Stderr},
Expand Down

0 comments on commit d4e8703

Please sign in to comment.