From 7fb5e8fdf7b6659f14dd90a18ace8662fe386ce6 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Sun, 20 Sep 2026 11:34:15 -0400 Subject: [PATCH] feat(config): add sidebar.visible field to hide sidebar (guilds tree) on startup (#839) --- internal/config/config.go | 3 +++ internal/config/config.toml | 3 +++ internal/ui/chat/model.go | 38 ++++++++++++++++++++++++++----------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 566e47b..ad1dd0f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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"` diff --git a/internal/config/config.toml b/internal/config/config.toml index e216858..d0693ae 100644 --- a/internal/config/config.toml +++ b/internal/config/config.toml @@ -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 diff --git a/internal/ui/chat/model.go b/internal/ui/chat/model.go index d6aa42e..a0fc9e9 100644 --- a/internal/ui/chat/model.go +++ b/internal/ui/chat/model.go @@ -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)