Merge branch 'column-width'

Fixes #33
This commit is contained in:
erroneousboat 2016-10-21 16:24:35 +02:00
commit 145241e31c
3 changed files with 22 additions and 9 deletions

View File

@ -23,8 +23,11 @@ Getting started
{
"slack_token": "yourslacktokenhere",
// add the following to use light theme, default is dark
"theme": "light"
// optional: add the following to use light theme, default is dark
"theme": "light",
// optional: set the width of the sidebar (between 1 and 11), default is 1
"sidebar_width": 3
}
```

View File

@ -10,14 +10,18 @@ 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"`
MainWidth int `json:"-"`
}
// NewConfig loads the config file and returns a Config struct
func NewConfig(filepath string) (*Config, error) {
cfg := Config{
Theme: "dark",
Theme: "dark",
SidebarWidth: 1,
MainWidth: 11,
}
file, err := os.Open(filepath)
@ -33,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,

View File

@ -71,12 +71,12 @@ func main() {
// 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(ctx.Config.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(ctx.Config.MainWidth, 0, ctx.View.Input),
),
)
termui.Body.Align()