MCPcopy
hub / github.com/jesseduffield/lazygit / formatBindingInfos

Method formatBindingInfos

pkg/gui/options_map.go:108–137  ·  view source on GitHub ↗
(bindingInfos []bindingInfo)

Source from the content-addressed store, hash-verified

106}
107
108func (self *OptionsMapMgr) formatBindingInfos(bindingInfos []bindingInfo) string {
109 width := self.c.Views().Options.InnerWidth() - 2 // -2 for some padding
110 var builder strings.Builder
111 ellipsis := "…"
112 separator := " | "
113
114 length := 0
115
116 for i, info := range bindingInfos {
117 plainText := fmt.Sprintf("%s: %s", info.description, info.key)
118
119 // Check if adding the next formatted string exceeds the available width
120 textLen := utils.StringWidth(plainText)
121 if i > 0 && length+len(separator)+textLen > width {
122 builder.WriteString(theme.OptionsFgColor.Sprint(separator + ellipsis))
123 break
124 }
125
126 formatted := info.style.Sprintf(plainText)
127
128 if i > 0 {
129 builder.WriteString(theme.OptionsFgColor.Sprint(separator))
130 length += len(separator)
131 }
132 builder.WriteString(formatted)
133 length += textLen
134 }
135
136 return builder.String()
137}
138
139func (self *OptionsMapMgr) renderOptions(options string) {
140 self.c.SetViewContent(self.c.Views().Options, options)

Callers 1

Calls 7

StringWidthFunction · 0.92
InnerWidthMethod · 0.80
WriteStringMethod · 0.80
ViewsMethod · 0.65
SprintfMethod · 0.65
SprintMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected