feat(config): add sidebar.visible field to hide sidebar (guilds tree) on startup (#839)

This commit is contained in:
ayn2op 2026-09-20 11:34:15 -04:00 • committed by GitHub
parent e87645a180
commit 7fb5e8fdf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 11 deletions

View file

@ -95,6 +95,9 @@ type (
}
SidebarConfig struct {
// Visible controls whether the guilds tree (sidebar) is shown by default at start-up.
// It can still be toggled at runtime with the toggle_guilds_tree keybind.
Visible bool `toml:"visible"`
// WidthPercent is the percentage of the total window width that the guilds tree (sidebar) occupies.
WidthPercent int `toml:"width_percent"`
Markers SidebarMarkersConfig `toml:"markers"`

View file

@ -71,6 +71,9 @@ send = true
receive = true
[sidebar]
# Whether the guilds tree sidebar is visible by default at start-up.
# It can still be toggled at runtime with the `toggle_guilds_tree` keybind.
visible = true
# Percentage (%) of the available width used by the guilds tree sidebar.
# Valid values are 1-99. Invalid values fall back to 20.
width_percent = 20

View file

@ -131,6 +131,10 @@ func (m *Model) isMe(id discord.UserID) bool {
return me != nil && id == me.ID
}
func (m *Model) isGuildsTreeVisible() bool {
return m.mainFlex.GetItemCount() == 2
}
func (m *Model) buildLayout() {
m.Clear()
m.rightFlex.Clear()
@ -140,10 +144,15 @@ func (m *Model) buildLayout() {
SetDirection(flex.DirectionRow).
AddItem(m.messagesList, 0, 1, false).
AddItem(m.composer, 3, 1, false)
// The guilds tree is always focused first at start-up.
m.mainFlex.
AddItem(m.guildsTree, 0, m.cfg.Sidebar.WidthPercent, true).
AddItem(m.rightFlex, 0, 100-m.cfg.Sidebar.WidthPercent, false)
if m.cfg.Sidebar.Visible {
// The guilds tree is focused first at start-up when visible.
m.mainFlex.
AddItem(m.guildsTree, 0, m.cfg.Sidebar.WidthPercent, true).
AddItem(m.rightFlex, 0, 100-m.cfg.Sidebar.WidthPercent, false)
} else {
m.mainFlex.AddItem(m.rightFlex, 0, 100, true)
m.rightFlex.SetFocus(0)
}
m.AddLayer(m.mainFlex, layers.WithName(flexLayerName), layers.WithResize(true), layers.WithVisible(true))
m.AddLayer(
@ -193,24 +202,28 @@ func (m *Model) navigateToChannel(channelID discord.ChannelID) tview.Cmd {
}
func (m *Model) toggleGuildsTree() tview.Cmd {
if m.mainFlex.GetItemCount() == 2 {
if m.isGuildsTreeVisible() {
if m.focusedModel() == m.guildsTree {
m.setFocus(m.messagesList)
}
m.mainFlex.RemoveItem(m.guildsTree)
} else {
m.buildLayout()
m.showGuildsTree()
m.setFocus(m.guildsTree)
}
return nil
}
func (m *Model) showGuildsTree() {
m.mainFlex.Clear()
m.mainFlex.
AddItem(m.guildsTree, 0, m.cfg.Sidebar.WidthPercent, true).
AddItem(m.rightFlex, 0, 100-m.cfg.Sidebar.WidthPercent, false)
}
func (m *Model) focusGuildsTree() bool {
if m.mainFlex.GetItemCount() == 2 {
m.setFocus(m.guildsTree)
return true
}
return false
m.setFocus(m.guildsTree)
return m.focusedModel() == m.guildsTree
}
func (m *Model) focusComposer() bool {
@ -394,6 +407,9 @@ func (m *Model) setFocus(target tview.Model) {
}
switch target {
case m.guildsTree:
if !m.isGuildsTreeVisible() {
return
}
m.mainFlex.SetFocus(0)
case m.messagesList:
m.rightFlex.SetFocus(0)