package xrandr import ( "bytes" "encoding/json" "os/exec" "git.milar.in/milarin/bufr" ) type Config struct { Displays []DisplayConfig } func GetCurrentConfig() (*Config, error) { output, err := exec.Command("xrandr").Output() if err != nil { return nil, err } r := bufr.New(bytes.NewReader(output)) r.StringUntil(isNewLine) configs := make([]DisplayConfig, 0) for config, err := parseDisplayConfig(r); err == nil; config, err = parseDisplayConfig(r) { configs = append(configs, *config) } if err != nil { return nil, err } return &Config{configs}, nil } func (c *Config) String() string { data, _ := json.MarshalIndent(c, "", "\t") return string(data) }