mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02:00
consider whether the view has focus when rendering the contents of a view
This commit is contained in:
parent
198cbee498
commit
ad93b4c863
15 changed files with 72 additions and 26 deletions
|
@ -113,13 +113,13 @@ func Min(x, y int) int {
|
|||
}
|
||||
|
||||
type Displayable interface {
|
||||
GetDisplayStrings() []string
|
||||
GetDisplayStrings(bool) []string
|
||||
}
|
||||
|
||||
// RenderList takes a slice of items, confirms they implement the Displayable
|
||||
// interface, then generates a list of their displaystrings to write to a panel's
|
||||
// buffer
|
||||
func RenderList(slice interface{}) (string, error) {
|
||||
func RenderList(slice interface{}, isFocused bool) (string, error) {
|
||||
s := reflect.ValueOf(slice)
|
||||
if s.Kind() != reflect.Slice {
|
||||
return "", errors.New("RenderList given a non-slice type")
|
||||
|
@ -135,19 +135,19 @@ func RenderList(slice interface{}) (string, error) {
|
|||
displayables[i] = value
|
||||
}
|
||||
|
||||
return renderDisplayableList(displayables)
|
||||
return renderDisplayableList(displayables, isFocused)
|
||||
}
|
||||
|
||||
// renderDisplayableList takes a list of displayable items, obtains their display
|
||||
// strings via GetDisplayStrings() and then returns a single string containing
|
||||
// each item's string representation on its own line, with appropriate horizontal
|
||||
// padding between the item's own strings
|
||||
func renderDisplayableList(items []Displayable) (string, error) {
|
||||
func renderDisplayableList(items []Displayable, isFocused bool) (string, error) {
|
||||
if len(items) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
stringArrays := getDisplayStringArrays(items)
|
||||
stringArrays := getDisplayStringArrays(items, isFocused)
|
||||
|
||||
if !displayArraysAligned(stringArrays) {
|
||||
return "", errors.New("Each item must return the same number of strings to display")
|
||||
|
@ -199,10 +199,10 @@ func displayArraysAligned(stringArrays [][]string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func getDisplayStringArrays(displayables []Displayable) [][]string {
|
||||
func getDisplayStringArrays(displayables []Displayable, isFocused bool) [][]string {
|
||||
stringArrays := make([][]string, len(displayables))
|
||||
for i, item := range displayables {
|
||||
stringArrays[i] = item.GetDisplayStrings()
|
||||
stringArrays[i] = item.GetDisplayStrings(isFocused)
|
||||
}
|
||||
return stringArrays
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue