Make columns render correctly
This commit is contained in:
parent
ddf904870c
commit
c5e2d5d429
@ -22,6 +22,7 @@ type Config struct {
|
|||||||
Emoji bool `json:"emoji"`
|
Emoji bool `json:"emoji"`
|
||||||
SidebarWidth int `json:"sidebar_width"`
|
SidebarWidth int `json:"sidebar_width"`
|
||||||
MainWidth int `json:"-"`
|
MainWidth int `json:"-"`
|
||||||
|
ThreadsWidth int `json:"threads_width"`
|
||||||
KeyMap map[string]keyMapping `json:"key_map"`
|
KeyMap map[string]keyMapping `json:"key_map"`
|
||||||
Theme Theme `json:"theme"`
|
Theme Theme `json:"theme"`
|
||||||
}
|
}
|
||||||
@ -90,6 +91,7 @@ func getDefaultConfig() Config {
|
|||||||
return Config{
|
return Config{
|
||||||
SidebarWidth: 1,
|
SidebarWidth: 1,
|
||||||
MainWidth: 11,
|
MainWidth: 11,
|
||||||
|
ThreadsWidth: 1,
|
||||||
Notify: "",
|
Notify: "",
|
||||||
Emoji: false,
|
Emoji: false,
|
||||||
KeyMap: map[string]keyMapping{
|
KeyMap: map[string]keyMapping{
|
||||||
|
@ -87,13 +87,11 @@ func CreateAppContext(flgConfig string, flgToken string, flgDebug bool, version
|
|||||||
|
|
||||||
// Setup the interface
|
// Setup the interface
|
||||||
if flgDebug {
|
if flgDebug {
|
||||||
// FIXME: threads width configurable
|
|
||||||
termui.Body.AddRows(
|
termui.Body.AddRows(
|
||||||
termui.NewRow(
|
termui.NewRow(
|
||||||
termui.NewCol(config.SidebarWidth, 0, view.Channels),
|
termui.NewCol(config.SidebarWidth, 0, view.Channels),
|
||||||
termui.NewCol(config.MainWidth-5, 0, view.Chat),
|
termui.NewCol(config.MainWidth-5, 0, view.Chat),
|
||||||
termui.NewCol(config.MainWidth-10, 0, view.Threads),
|
termui.NewCol(config.MainWidth-6, 0, view.Debug),
|
||||||
termui.NewCol(config.MainWidth-7, 0, view.Debug),
|
|
||||||
),
|
),
|
||||||
termui.NewRow(
|
termui.NewRow(
|
||||||
termui.NewCol(config.SidebarWidth, 0, view.Mode),
|
termui.NewCol(config.SidebarWidth, 0, view.Mode),
|
||||||
@ -101,12 +99,10 @@ func CreateAppContext(flgConfig string, flgToken string, flgDebug bool, version
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// FIXME: threads width configurable
|
|
||||||
termui.Body.AddRows(
|
termui.Body.AddRows(
|
||||||
termui.NewRow(
|
termui.NewRow(
|
||||||
termui.NewCol(config.SidebarWidth, 0, view.Channels),
|
termui.NewCol(config.SidebarWidth, 0, view.Channels),
|
||||||
termui.NewCol(config.MainWidth-1, 0, view.Chat),
|
termui.NewCol(config.MainWidth-1, 0, view.Chat),
|
||||||
termui.NewCol(config.MainWidth-10, 0, view.Threads),
|
|
||||||
),
|
),
|
||||||
termui.NewRow(
|
termui.NewRow(
|
||||||
termui.NewCol(config.SidebarWidth, 0, view.Mode),
|
termui.NewCol(config.SidebarWidth, 0, view.Mode),
|
||||||
|
@ -135,6 +135,8 @@ func messageHandler(ctx *context.AppContext) {
|
|||||||
// When timestamp isn't set this is a thread reply,
|
// When timestamp isn't set this is a thread reply,
|
||||||
// handle as such
|
// handle as such
|
||||||
if ev.ThreadTimestamp != "" {
|
if ev.ThreadTimestamp != "" {
|
||||||
|
// FIXME: render in correctly, this will cause
|
||||||
|
// panic
|
||||||
ctx.View.Chat.AddReply(ev.ThreadTimestamp, msg)
|
ctx.View.Chat.AddReply(ev.ThreadTimestamp, msg)
|
||||||
} else {
|
} else {
|
||||||
ctx.View.Chat.AddMessage(msg)
|
ctx.View.Chat.AddMessage(msg)
|
||||||
@ -207,6 +209,71 @@ func actionResizeEvent(ctx *context.AppContext, ev termbox.Event) {
|
|||||||
termui.Render(termui.Body)
|
termui.Render(termui.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func actionRedrawGrid(ctx *context.AppContext, threads bool, debug bool) {
|
||||||
|
termui.Clear()
|
||||||
|
termui.Body = termui.NewGrid()
|
||||||
|
termui.Body.X = 0
|
||||||
|
termui.Body.Y = 0
|
||||||
|
termui.Body.BgColor = termui.ThemeAttr("bg")
|
||||||
|
termui.Body.Width = termui.TermWidth()
|
||||||
|
|
||||||
|
columns := []*termui.Row{
|
||||||
|
termui.NewCol(ctx.Config.SidebarWidth, 0, ctx.View.Channels),
|
||||||
|
}
|
||||||
|
|
||||||
|
if threads && debug {
|
||||||
|
ctx.View.Debug.Println(
|
||||||
|
"threads && debug",
|
||||||
|
)
|
||||||
|
|
||||||
|
columns = append(
|
||||||
|
columns,
|
||||||
|
[]*termui.Row{
|
||||||
|
termui.NewCol(ctx.Config.MainWidth-ctx.Config.ThreadsWidth-3, 0, ctx.View.Chat),
|
||||||
|
termui.NewCol(ctx.Config.ThreadsWidth, 0, ctx.View.Threads),
|
||||||
|
termui.NewCol(3, 0, ctx.View.Debug),
|
||||||
|
}...,
|
||||||
|
)
|
||||||
|
|
||||||
|
} else if threads {
|
||||||
|
ctx.View.Debug.Println(
|
||||||
|
"threads",
|
||||||
|
)
|
||||||
|
|
||||||
|
columns = append(
|
||||||
|
columns,
|
||||||
|
[]*termui.Row{
|
||||||
|
termui.NewCol(ctx.Config.MainWidth-ctx.Config.ThreadsWidth, 0, ctx.View.Chat),
|
||||||
|
termui.NewCol(ctx.Config.ThreadsWidth, 0, ctx.View.Threads),
|
||||||
|
}...,
|
||||||
|
)
|
||||||
|
} else if debug {
|
||||||
|
ctx.View.Debug.Println(
|
||||||
|
"debug",
|
||||||
|
)
|
||||||
|
columns = append(
|
||||||
|
columns,
|
||||||
|
[]*termui.Row{
|
||||||
|
termui.NewCol(ctx.Config.MainWidth-5, 0, ctx.View.Chat),
|
||||||
|
termui.NewCol(ctx.Config.MainWidth-6, 0, ctx.View.Debug),
|
||||||
|
}...,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
termui.Body.AddRows(
|
||||||
|
termui.NewRow(columns...),
|
||||||
|
termui.NewRow(
|
||||||
|
termui.NewCol(ctx.Config.SidebarWidth, 0, ctx.View.Mode),
|
||||||
|
termui.NewCol(ctx.Config.MainWidth, 0, ctx.View.Input),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
// ctx.Body.Align()
|
||||||
|
// termui.Render(ctx.Body)
|
||||||
|
termui.Body.Align()
|
||||||
|
termui.Render(termui.Body)
|
||||||
|
}
|
||||||
|
|
||||||
func actionInput(view *views.View, key rune) {
|
func actionInput(view *views.View, key rune) {
|
||||||
view.Input.Insert(key)
|
view.Input.Insert(key)
|
||||||
termui.Render(view.Input)
|
termui.Render(view.Input)
|
||||||
@ -438,9 +505,6 @@ func actionChangeChannel(ctx *context.AppContext) {
|
|||||||
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].GetChannelName(),
|
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].GetChannelName(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Set threads
|
|
||||||
ctx.View.Threads.SetChannels(threads)
|
|
||||||
|
|
||||||
// Clear notification icon if there is any
|
// Clear notification icon if there is any
|
||||||
channelItem := ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel]
|
channelItem := ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel]
|
||||||
if channelItem.Notification {
|
if channelItem.Notification {
|
||||||
@ -448,9 +512,18 @@ func actionChangeChannel(ctx *context.AppContext) {
|
|||||||
ctx.View.Channels.MarkAsRead(ctx.View.Channels.SelectedChannel)
|
ctx.View.Channels.MarkAsRead(ctx.View.Channels.SelectedChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
termui.Render(ctx.View.Channels)
|
// Set threads
|
||||||
termui.Render(ctx.View.Threads)
|
if len(threads) > 0 {
|
||||||
termui.Render(ctx.View.Chat)
|
ctx.View.Threads.SetChannels(threads)
|
||||||
|
actionRedrawGrid(ctx, true, ctx.Debug)
|
||||||
|
} else {
|
||||||
|
actionRedrawGrid(ctx, false, ctx.Debug)
|
||||||
|
}
|
||||||
|
|
||||||
|
// termui.Render(ctx.View.Debug)
|
||||||
|
// termui.Render(ctx.View.Channels)
|
||||||
|
// termui.Render(ctx.View.Threads)
|
||||||
|
// termui.Render(ctx.View.Chat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func actionChangeThread(ctx *context.AppContext) {
|
func actionChangeThread(ctx *context.AppContext) {
|
||||||
@ -459,6 +532,7 @@ func actionChangeThread(ctx *context.AppContext) {
|
|||||||
|
|
||||||
// TODO: err
|
// TODO: err
|
||||||
// TODO: change function name to match GetMessages
|
// TODO: change function name to match GetMessages
|
||||||
|
// TODO: get initial parent message
|
||||||
msgs := ctx.Service.CreateMessageFromReplies(
|
msgs := ctx.Service.CreateMessageFromReplies(
|
||||||
ctx.View.Threads.ChannelItems[ctx.View.Threads.SelectedChannel].ID,
|
ctx.View.Threads.ChannelItems[ctx.View.Threads.SelectedChannel].ID,
|
||||||
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].ID,
|
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].ID,
|
||||||
|
Loading…
Reference in New Issue
Block a user