Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight installed version when searching #155

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/commands/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/urfave/cli/v2"
"github.com/version-fox/vfox/internal"
"github.com/version-fox/vfox/internal/printer"
"github.com/version-fox/vfox/internal/util"
"golang.org/x/crypto/ssh/terminal"
"math"
"os"
Expand Down Expand Up @@ -75,10 +76,11 @@ func searchCmd(ctx *cli.Context) error {

_, height, _ := terminal.GetSize(int(os.Stdout.Fd()))
kvSelect := printer.PageKVSelect{
TopText: "Please select a version of " + sdkName,
Filter: true,
Size: int(math.Min(math.Max(float64(height-3), 1), 20)),
Options: options,
TopText: "Please select a version of " + sdkName,
Filter: true,
Size: int(math.Min(math.Max(float64(height-3), 1), 20)),
InstallVersions: util.NewSetWithSlice(source.List()),
Options: options,
SourceFunc: func(page, size int, options []*printer.KV) ([]*printer.KV, error) {
start := page * size
end := start + size
Expand Down
11 changes: 9 additions & 2 deletions internal/printer/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ import (
"fmt"
"github.com/lithammer/fuzzysearch/fuzzy"
"github.com/pterm/pterm"
"github.com/version-fox/vfox/internal"
"github.com/version-fox/vfox/internal/logger"
"github.com/version-fox/vfox/internal/util"
"sort"
"strings"
)

type PageKVSelect struct {
index int
InstallVersions util.Set[internal.Version]
Chance-fyi marked this conversation as resolved.
Show resolved Hide resolved
Options []*KV
searchOptions []*KV
pageOptions []*KV
Expand Down Expand Up @@ -96,10 +99,14 @@ func (s *PageKVSelect) renderSelect() string {
}

for i, option := range indexMapper {
value := option.Value
if s.InstallVersions.Contains(internal.Version(option.Key)) {
value = pterm.LightGreen(value)
}
if i == s.index {
content += pterm.Sprintln(pterm.LightGreen("-> "), option.Value)
content += pterm.Sprintln(pterm.LightGreen("-> "), value)
} else {
content += pterm.Sprintln(" ", option.Value)
content += pterm.Sprintln(" ", value)
}
}
content += pterm.Sprintln("Press ↑/↓ to select and press ←/→ to page, and press Enter to confirm")
Expand Down