Add additional check for sidebar width
I've added the MainWidth to the context which may be used in the future for on the fly changing of the size of the sidebar.
This commit is contained in:
parent
5d483f313f
commit
7651156c27
@ -23,11 +23,10 @@ Getting started
|
||||
{
|
||||
"slack_token": "yourslacktokenhere",
|
||||
|
||||
// add the following to use light theme, default is dark
|
||||
// optional: add the following to use light theme, default is dark
|
||||
"theme": "light",
|
||||
|
||||
// Set the width of the channel list sidebar. Must be between 1 and 11
|
||||
// as the entire width of the screen is 12 columns.
|
||||
// optional: set the width of the sidebar (between 1 and 11), default is 1
|
||||
"sidebar_width": 3
|
||||
}
|
||||
```
|
||||
|
@ -13,6 +13,7 @@ type Config struct {
|
||||
SlackToken string `json:"slack_token"`
|
||||
Theme string `json:"theme"`
|
||||
SidebarWidth int `json:"sidebar_width"`
|
||||
MainWidth int `json:"-"`
|
||||
}
|
||||
|
||||
// NewConfig loads the config file and returns a Config struct
|
||||
@ -20,6 +21,7 @@ func NewConfig(filepath string) (*Config, error) {
|
||||
cfg := Config{
|
||||
Theme: "dark",
|
||||
SidebarWidth: 1,
|
||||
MainWidth: 11,
|
||||
}
|
||||
|
||||
file, err := os.Open(filepath)
|
||||
@ -35,6 +37,12 @@ func NewConfig(filepath string) (*Config, error) {
|
||||
return &cfg, errors.New("couldn't find 'slack_token' parameter")
|
||||
}
|
||||
|
||||
if cfg.SidebarWidth < 1 || cfg.SidebarWidth > 11 {
|
||||
return &cfg, errors.New("please specify the 'sidebar_width' between 1 and 11")
|
||||
}
|
||||
|
||||
cfg.MainWidth = 12 - cfg.SidebarWidth
|
||||
|
||||
if cfg.Theme == "light" {
|
||||
termui.ColorMap = map[string]termui.Attribute{
|
||||
"fg": termui.ColorBlack,
|
||||
|
6
main.go
6
main.go
@ -68,17 +68,15 @@ func main() {
|
||||
// Create context
|
||||
ctx := context.CreateAppContext(flgConfig)
|
||||
|
||||
mainWidth := 12 - ctx.Config.SidebarWidth
|
||||
|
||||
// Setup body
|
||||
termui.Body.AddRows(
|
||||
termui.NewRow(
|
||||
termui.NewCol(ctx.Config.SidebarWidth, 0, ctx.View.Channels),
|
||||
termui.NewCol(mainWidth, 0, ctx.View.Chat),
|
||||
termui.NewCol(ctx.Config.MainWidth, 0, ctx.View.Chat),
|
||||
),
|
||||
termui.NewRow(
|
||||
termui.NewCol(ctx.Config.SidebarWidth, 0, ctx.View.Mode),
|
||||
termui.NewCol(mainWidth, 0, ctx.View.Input),
|
||||
termui.NewCol(ctx.Config.MainWidth, 0, ctx.View.Input),
|
||||
),
|
||||
)
|
||||
termui.Body.Align()
|
||||
|
Loading…
Reference in New Issue
Block a user