mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-28 10:15:32 -05:00
This adds the user-facing surface for configuring the side panels: their order, which ones are visible, and how tabs are grouped into panels. Each entry is either a single panel name or a list of names sharing one panel as tabs, mirroring how the Keybinding type accepts a scalar or a sequence; the JSON schema restricts the names to the known set so editors can offer completion and catch typos. The default reproduces today's layout exactly. Validation rejects unknown or duplicated names, and requires the files, branches, and commits panels to always be present: a lot of code focuses those directly (e.g. after resolving a conflict or popping a stash), so allowing them to be hidden would let that code focus a hidden panel. Nothing reads the option yet; the layout still uses the hard-coded order. Wiring follows in a later commit so the inert surface (and its generated docs and schema) can be reviewed on its own. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"github.com/karimkhaleel/jsonschema"
|
|
"github.com/samber/lo"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// SidePanel is one entry in gui.sidePanels: a side panel made up of one or more
|
|
// tabs, written in YAML as a list of tab names (e.g. [files, worktrees]).
|
|
type SidePanel []string
|
|
|
|
// ValidSidePanelTabs lists every name that may appear in gui.sidePanels. Each
|
|
// names a list that can stand alone as a panel or be grouped with others as the
|
|
// tabs of one panel. The resolver in the gui package must handle every entry
|
|
// here; a test enforces that the two stay in sync.
|
|
var ValidSidePanelTabs = []string{
|
|
"status",
|
|
"files",
|
|
"worktrees",
|
|
"submodules",
|
|
"branches",
|
|
"remotes",
|
|
"tags",
|
|
"commits",
|
|
"reflog",
|
|
"stash",
|
|
}
|
|
|
|
func (p SidePanel) MarshalYAML() (any, error) {
|
|
// Render in flow style (`[a, b]`) rather than the default block style, which
|
|
// is more compact and reads better in the generated docs.
|
|
node := &yaml.Node{
|
|
Kind: yaml.SequenceNode,
|
|
Style: yaml.FlowStyle,
|
|
}
|
|
for _, s := range p {
|
|
node.Content = append(node.Content, &yaml.Node{
|
|
Kind: yaml.ScalarNode,
|
|
Value: s,
|
|
})
|
|
}
|
|
return node, nil
|
|
}
|
|
|
|
// JSONSchema describes a side panel as a list of tab names, restricted to the
|
|
// known names.
|
|
func (SidePanel) JSONSchema() *jsonschema.Schema {
|
|
names := lo.Map(ValidSidePanelTabs, func(name string, _ int) any { return name })
|
|
return &jsonschema.Schema{
|
|
Type: "array",
|
|
Items: &jsonschema.Schema{Type: "string", Enum: names},
|
|
}
|
|
}
|