Skip to content

Commit 0e324a1

Browse files
committed
update
1 parent 665ecbb commit 0e324a1

File tree

6 files changed

+34
-38
lines changed

6 files changed

+34
-38
lines changed

common/color.go

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func RenderedText(str, strcolor string) string {
3434
return color.New(color.Bold, color.FgHiBlue).SprintfFunc()(str)
3535
case "white":
3636
return color.New(color.Bold, color.FgHiWhite).SprintFunc()(str)
37+
case "red":
38+
return color.New(color.Bold, color.FgHiRed).SprintFunc()(str)
3739
}
3840
return str
3941
}

myssh/keymg.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package myssh
22

33
import (
44
"fmt"
5-
"github.com/cnlubo/myssh/common"
65
"github.com/cnlubo/myssh/confirmation"
76
"github.com/cnlubo/myssh/prompt"
87
"github.com/cnlubo/myssh/selection"
@@ -168,19 +167,19 @@ func createDefaultSSHKey(env *Environment) error {
168167
selection.Choices(sshKeyType))
169168
sp.PageSize = 5
170169
sp.Filter = nil
171-
sp.SelectedChoiceStyle = func(c *selection.Choice) string {
172-
a, _ := c.Value.(KeyType)
173-
174-
return common.RenderedText(a.Name, "blue")
175-
}
176-
sp.UnselectedChoiceStyle = func(c *selection.Choice) string {
177-
a, _ := c.Value.(KeyType)
178-
179-
return common.RenderedText(a.Name, "white")
180-
}
181-
sp.ExtendedTemplateFuncs = map[string]interface{}{
182-
"name": func(c *selection.Choice) string { return c.Value.(KeyType).Name },
183-
}
170+
//sp.SelectedChoiceStyle = func(c *selection.Choice) string {
171+
// a, _ := c.Value.(KeyType)
172+
//
173+
// return common.RenderedText(a.Name, "blue")
174+
//}
175+
//sp.UnselectedChoiceStyle = func(c *selection.Choice) string {
176+
// a, _ := c.Value.(KeyType)
177+
//
178+
// return common.RenderedText(a.Name, "white")
179+
//}
180+
//sp.ExtendedTemplateFuncs = map[string]interface{}{
181+
// "name": func(c *selection.Choice) string { return c.Value.(KeyType).Name },
182+
//}
184183

185184
choice, err := sp.RunPrompt()
186185
if err != nil {

selection/keymap.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ func NewDefaultKeyMap() *KeyMap {
1717
ClearFilter: []string{"esc"},
1818
ScrollDown: []string{"pgdown"},
1919
ScrollUp: []string{"pgup"},
20+
Left: []string{"left"},
21+
Right: []string{"right"},
2022
}
2123
}
2224

@@ -29,6 +31,8 @@ type KeyMap struct {
2931
ClearFilter []string
3032
ScrollDown []string
3133
ScrollUp []string
34+
Left []string
35+
Right []string
3236
}
3337

3438
func keyMatches(key tea.KeyMsg, mapping []string) bool {
@@ -62,4 +66,4 @@ func validateKeyMap(km *KeyMap) error {
6266
}
6367

6468
return nil
65-
}
69+
}

selection/model.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
206206
m.scrollDown()
207207
case keyMatches(msg, m.KeyMap.ScrollUp):
208208
m.scrollUp()
209+
case keyMatches(msg, m.KeyMap.Left):
210+
m.scrollUp()
211+
case keyMatches(msg, m.KeyMap.Right):
212+
m.scrollDown()
209213
default:
210214
return m.updateFilter(msg)
211215
}
@@ -291,8 +295,7 @@ func (m *Model) View() string {
291295
}
292296

293297
err := m.tmpl.Execute(viewBuffer, map[string]interface{}{
294-
"HeadPrompt": m.HeadPrompt,
295-
"Prompt": m.Prompt,
298+
"Prompt": defaultHeader + "\n" + m.Prompt,
296299
"IsFiltered": m.Filter != nil,
297300
"FilterPrompt": m.FilterPrompt,
298301
"FilterInput": m.filterInput.View(),

selection/prompt.go

+5-16
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,24 @@ const (
3030

3131
accentColor = termenv.ANSI256Color(32)
3232

33-
DefaultHeader = "Use the arrow keys to navigate: ↓ ↑ → ←"
33+
defaultHeader = "Use the arrow keys to navigate: ↓ ↑ → ←"
34+
//DefaultCursor = "»"
3435
)
3536

3637
// DefaultSelectedChoiceStyle is the default style for selected choices.
3738
func DefaultSelectedChoiceStyle(c *Choice) string {
38-
return termenv.String(c.String).Foreground(accentColor).Bold().String()
39+
//return termenv.String(c.String).Foreground(accentColor).Bold().String()
40+
//return common.RenderedText(c.String, "red")
41+
return c.String
3942
}
4043

4144
// DefaultFinalChoiceStyle is the default style for final choices.
4245
func DefaultFinalChoiceStyle(c *Choice) string {
4346
return termenv.String(c.String).Foreground(accentColor).String()
4447
}
4548

46-
// DefaultHeaderFuncWithAppend return the default HeaderFunc and append
47-
// the given string to the next line of the default header
48-
func DefaultHeaderFuncWithAppend(append string) func(m Model, obj interface{}, gdIndex int) string {
49-
return func(m Model, obj interface{}, gdIndex int) string {
50-
//return common.FontColor(DefaultHeader+"\n"+append, ColorHeader)
51-
return DefaultHeader + "\n" + append
52-
}
53-
}
54-
5549
// Selection represents a configurable selection prompt.
5650
type Selection struct {
57-
HeadPrompt string
58-
59-
// HeaderFunc Header rendering function
60-
HeaderFunc func(m Model, obj interface{}, gdIndex int) string
6151

6252
// Choices represent all selectable choices of the selection. Slices of
6353
// arbitrary types can be converted to a slice of choices using the helper
@@ -194,7 +184,6 @@ func New(prompt string, choices []*Choice) *Selection {
194184

195185
return &Selection{
196186
Choices: choices,
197-
HeadPrompt: DefaultHeader,
198187
Prompt: prompt,
199188
FilterPrompt: DefaultFilterPrompt,
200189
Template: DefaultTemplate,

selection/templates.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ package selection
44
// be copied as a starting point for a custom template.
55
//{{ .HeadPrompt | bold | cyan }}
66
const DefaultTemplate = `
7-
{{- if .HeadPrompt -}}
8-
{{- print | faint | cyan .HeadPrompt "\n" -}}
9-
{{ end -}}
107
{{- if .Prompt -}}
11-
{{ .Prompt | bold | cyan }}
8+
{{ .Prompt | bold | yellow }}
129
{{ end -}}
1310
{{ if .IsFiltered }}
1411
{{- print .FilterPrompt " " .FilterInput }}
@@ -24,12 +21,14 @@ const DefaultTemplate = `
2421
{{- end -}}
2522
2623
{{- if eq $.SelectedIndex $i }}
27-
{{- print (Foreground "32" (Bold "▸ ")) (Selected $choice) "\n" }}
24+
{{- print (red (bold "» ")) (Selected $choice) "\n" }}
2825
{{- else }}
2926
{{- print " " (Unselected $choice) "\n" }}
3027
{{- end }}
3128
{{- end}}`
3229

30+
// {{- print (red (bold "▸ ")) (Selected $choice) "\n" }}
31+
3332
// DefaultResultTemplate defines the default appearance with which the
3433
// finale result of the selection is presented.
3534
const DefaultResultTemplate = `

0 commit comments

Comments
 (0)