BurntSushi / wingo

A fully-featured window manager written in Go.
Do What The F*ck You Want To Public License
1k stars 86 forks source link

Easiest way to parse contents of a wini file #141

Closed Happy-Ferret closed 4 years ago

Happy-Ferret commented 4 years ago

I'm trying to re-use the wini parser. However, I can't figure out how to quickly and efficiently parse a wini file without too much boilerplate.

How may I retrieve the value of path, given the following wallpaper.wini file?

[Global]
path := somePath
BurntSushi commented 4 years ago

Not really sure what you're hoping for here.

First of all, don't use wini. Use something like TOML.

Second of all, it's pretty much what you see is what you get: https://godoc.org/github.com/BurntSushi/wingo/wini

If you need examples, then look in the Wingo source code for how the wini package is being used.

Happy-Ferret commented 4 years ago

My hope was to hook in my own (WIP) wallpaper application.

This was the basic code. I have no idea how to grab the value of "path" now.

func setWallpaper() {
    tdata, err := wini.Parse(misc.ConfigFile("wallpaper.wini"))
    if err != nil {
    }

    for _, section := range tdata.Sections() {
        switch section {
        case "global":
            for _, key := range tdata.Keys(section) {
                switch key.Name() {
                case "path":
                    fmt.Println("Test")
                }
            }
        }
    }
BurntSushi commented 4 years ago

key.Strings()

Happy-Ferret commented 4 years ago

That works! Thanks!