Set column widths from sidebarWidth config value

Reads from config file or defaults to 1 column
This commit is contained in:
Chris Marshall 2016-10-19 12:21:00 -04:00
parent 10e4469bae
commit 5b7fabcabd
3 changed files with 16 additions and 8 deletions

View File

@ -24,7 +24,11 @@ Getting started
"slack_token": "yourslacktokenhere",
// add the following to use light theme, default is dark
"theme": "light"
"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.
"sidebar_width": 3
}
```

View File

@ -10,14 +10,16 @@ import (
// Config is the definition of a Config struct
type Config struct {
SlackToken string `json:"slack_token"`
Theme string `json:"theme"`
SlackToken string `json:"slack_token"`
Theme string `json:"theme"`
SidebarWidth int `json:"sidebar_width"`
}
// NewConfig loads the config file and returns a Config struct
func NewConfig(filepath string) (*Config, error) {
cfg := Config{
Theme: "dark",
Theme: "dark",
SidebarWidth: 1,
}
file, err := os.Open(filepath)

10
main.go
View File

@ -68,15 +68,17 @@ func main() {
// Create context
ctx := context.CreateAppContext(flgConfig)
mainWidth := 12 - ctx.Config.SidebarWidth
// Setup body
termui.Body.AddRows(
termui.NewRow(
termui.NewCol(1, 0, ctx.View.Channels),
termui.NewCol(11, 0, ctx.View.Chat),
termui.NewCol(ctx.Config.SidebarWidth, 0, ctx.View.Channels),
termui.NewCol(mainWidth, 0, ctx.View.Chat),
),
termui.NewRow(
termui.NewCol(1, 0, ctx.View.Mode),
termui.NewCol(11, 0, ctx.View.Input),
termui.NewCol(ctx.Config.SidebarWidth, 0, ctx.View.Mode),
termui.NewCol(mainWidth, 0, ctx.View.Input),
),
)
termui.Body.Align()