diff --git a/context/context.go b/context/context.go index 007349b..a5be45a 100644 --- a/context/context.go +++ b/context/context.go @@ -89,32 +89,58 @@ func CreateAppContext(flgConfig string, flgToken string, flgDebug bool, version return nil, err } + columns := []*termui.Row{ + termui.NewCol(config.SidebarWidth, 0, view.Channels), + } + + threads := false + if len(view.Threads.ChannelItems) > 0 { + threads = true + } + // Setup the interface - if flgDebug { - termui.Body.AddRows( - termui.NewRow( - termui.NewCol(config.SidebarWidth, 0, view.Channels), + if threads && flgDebug { + columns = append( + columns, + []*termui.Row{ + termui.NewCol(config.MainWidth-config.ThreadsWidth-3, 0, view.Chat), + termui.NewCol(config.ThreadsWidth, 0, view.Threads), + termui.NewCol(3, 0, view.Debug), + }..., + ) + } else if threads { + columns = append( + columns, + []*termui.Row{ + termui.NewCol(config.MainWidth-config.ThreadsWidth, 0, view.Chat), + termui.NewCol(config.ThreadsWidth, 0, view.Threads), + }..., + ) + } else if flgDebug { + columns = append( + columns, + []*termui.Row{ termui.NewCol(config.MainWidth-5, 0, view.Chat), termui.NewCol(config.MainWidth-6, 0, view.Debug), - ), - termui.NewRow( - termui.NewCol(config.SidebarWidth, 0, view.Mode), - termui.NewCol(config.MainWidth, 0, view.Input), - ), + }..., ) } else { - termui.Body.AddRows( - termui.NewRow( - termui.NewCol(config.SidebarWidth, 0, view.Channels), + columns = append( + columns, + []*termui.Row{ termui.NewCol(config.MainWidth, 0, view.Chat), - ), - termui.NewRow( - termui.NewCol(config.SidebarWidth, 0, view.Mode), - termui.NewCol(config.MainWidth, 0, view.Input), - ), + }..., ) } + termui.Body.AddRows( + termui.NewRow(columns...), + termui.NewRow( + termui.NewCol(config.SidebarWidth, 0, view.Mode), + termui.NewCol(config.MainWidth, 0, view.Input), + ), + ) + termui.Body.Align() termui.Render(termui.Body) @@ -128,6 +154,7 @@ func CreateAppContext(flgConfig string, flgToken string, flgDebug bool, version Config: config, Debug: flgDebug, Mode: CommandMode, + Focus: ChatFocus, Notify: notify, }, nil } diff --git a/handlers/event.go b/handlers/event.go index 76cc5bc..a480c24 100644 --- a/handlers/event.go +++ b/handlers/event.go @@ -228,7 +228,6 @@ func actionRedrawGrid(ctx *context.AppContext, threads bool, debug bool) { termui.NewCol(3, 0, ctx.View.Debug), }..., ) - } else if threads { columns = append( columns, @@ -547,6 +546,7 @@ func actionChangeChannel(ctx *context.AppContext) { ctx.View.Threads.SetChannels([]components.ChannelItem{}) actionRedrawGrid(ctx, haveThreads, ctx.Debug) } else { + termui.Render(ctx.View.Threads) termui.Render(ctx.View.Channels) termui.Render(ctx.View.Chat) } @@ -592,8 +592,6 @@ func actionChangeThread(ctx *context.AppContext) { // Set messages for the channel ctx.View.Chat.SetMessages(msgs) - // Set focus, necessary to know when replying to thread or chat - termui.Render(ctx.View.Channels) termui.Render(ctx.View.Threads) termui.Render(ctx.View.Chat) diff --git a/views/view.go b/views/view.go index ec5d492..3029e63 100644 --- a/views/view.go +++ b/views/view.go @@ -58,7 +58,16 @@ func CreateView(config *config.Config, svc *service.SlackService) (*View, error) ) // Threads: set threads in component - threads.SetChannels(thr) + if len(thr) > 0 { + + // Make the first thread the current Channel + threads.SetChannels( + append( + []components.ChannelItem{channels.GetSelectedChannel()}, + thr..., + ), + ) + } // Debug: create the component debug := components.CreateDebugComponent(input.Par.Height)