diff --git a/config/config.go b/config/config.go index a375198..433224f 100644 --- a/config/config.go +++ b/config/config.go @@ -34,13 +34,13 @@ func Load() (Config, Options) { return *cfg, opt } -func Update(settings []ComponentSettings) { - cfg := readFile(os.Args[1]) +func Update(settings []ComponentSettings, options Options) { + cfg := readFile(options.ConfigFile) for _, s := range settings { componentConfig := cfg.findComponent(s.Type, s.Title) componentConfig.Position = getPosition(s.Location, s.Size) } - saveFile(cfg) + saveFile(cfg, options.ConfigFile) } func (c *Config) findComponent(componentType ComponentType, componentTitle string) *ComponentConfig { @@ -93,13 +93,13 @@ func readFile(location string) *Config { return cfg } -func saveFile(config *Config) { +func saveFile(config *Config, fileName string) { file, err := yaml.Marshal(config) if err != nil { log.Fatalf("Can't marshal config file: %v", err) } - err = ioutil.WriteFile(os.Args[1], file, 0644) + err = ioutil.WriteFile(fileName, file, 0644) if err != nil { log.Fatalf("Can't save config file: %v", err) } diff --git a/event/handler.go b/event/handler.go index deeb8e8..2af02cb 100644 --- a/event/handler.go +++ b/event/handler.go @@ -17,15 +17,17 @@ type Handler struct { renderTicker *time.Ticker consoleEvents <-chan ui.Event renderRate time.Duration + options config.Options } -func NewHandler(layout *layout.Layout) *Handler { +func NewHandler(layout *layout.Layout, options config.Options) *Handler { renderRate := calcMinRenderRate(layout) return &Handler{ layout: layout, consoleEvents: ui.PollEvents(), renderTicker: time.NewTicker(renderRate), renderRate: renderRate, + options: options, } } @@ -77,7 +79,7 @@ func (h *Handler) handleExit() { settings = append(settings, config.ComponentSettings{Type: c.Type, Title: c.Title, Size: c.Size, Location: c.Location}) } - config.Update(settings) + config.Update(settings, h.options) } func calcMinRenderRate(layout *layout.Layout) time.Duration { diff --git a/main.go b/main.go index 0b1231d..69534ff 100644 --- a/main.go +++ b/main.go @@ -63,6 +63,6 @@ func main() { starter.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers) } - handler := event.NewHandler(lout) + handler := event.NewHandler(lout, opt) handler.HandleEvents() }