file save with options
This commit is contained in:
parent
0a0dc6df91
commit
9f0856466e
|
@ -34,13 +34,13 @@ func Load() (Config, Options) {
|
||||||
return *cfg, opt
|
return *cfg, opt
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(settings []ComponentSettings) {
|
func Update(settings []ComponentSettings, options Options) {
|
||||||
cfg := readFile(os.Args[1])
|
cfg := readFile(options.ConfigFile)
|
||||||
for _, s := range settings {
|
for _, s := range settings {
|
||||||
componentConfig := cfg.findComponent(s.Type, s.Title)
|
componentConfig := cfg.findComponent(s.Type, s.Title)
|
||||||
componentConfig.Position = getPosition(s.Location, s.Size)
|
componentConfig.Position = getPosition(s.Location, s.Size)
|
||||||
}
|
}
|
||||||
saveFile(cfg)
|
saveFile(cfg, options.ConfigFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) findComponent(componentType ComponentType, componentTitle string) *ComponentConfig {
|
func (c *Config) findComponent(componentType ComponentType, componentTitle string) *ComponentConfig {
|
||||||
|
@ -93,13 +93,13 @@ func readFile(location string) *Config {
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveFile(config *Config) {
|
func saveFile(config *Config, fileName string) {
|
||||||
file, err := yaml.Marshal(config)
|
file, err := yaml.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Can't marshal config file: %v", err)
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("Can't save config file: %v", err)
|
log.Fatalf("Can't save config file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,15 +17,17 @@ type Handler struct {
|
||||||
renderTicker *time.Ticker
|
renderTicker *time.Ticker
|
||||||
consoleEvents <-chan ui.Event
|
consoleEvents <-chan ui.Event
|
||||||
renderRate time.Duration
|
renderRate time.Duration
|
||||||
|
options config.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(layout *layout.Layout) *Handler {
|
func NewHandler(layout *layout.Layout, options config.Options) *Handler {
|
||||||
renderRate := calcMinRenderRate(layout)
|
renderRate := calcMinRenderRate(layout)
|
||||||
return &Handler{
|
return &Handler{
|
||||||
layout: layout,
|
layout: layout,
|
||||||
consoleEvents: ui.PollEvents(),
|
consoleEvents: ui.PollEvents(),
|
||||||
renderTicker: time.NewTicker(renderRate),
|
renderTicker: time.NewTicker(renderRate),
|
||||||
renderRate: renderRate,
|
renderRate: renderRate,
|
||||||
|
options: options,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +79,7 @@ func (h *Handler) handleExit() {
|
||||||
settings = append(settings,
|
settings = append(settings,
|
||||||
config.ComponentSettings{Type: c.Type, Title: c.Title, Size: c.Size, Location: c.Location})
|
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 {
|
func calcMinRenderRate(layout *layout.Layout) time.Duration {
|
||||||
|
|
2
main.go
2
main.go
|
@ -63,6 +63,6 @@ func main() {
|
||||||
starter.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers)
|
starter.start(cpt, cpt.Consumer, c.ComponentConfig, c.Items, c.Triggers)
|
||||||
}
|
}
|
||||||
|
|
||||||
handler := event.NewHandler(lout)
|
handler := event.NewHandler(lout, opt)
|
||||||
handler.HandleEvents()
|
handler.HandleEvents()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue