initial work - making config file
This commit is contained in:
parent
aa195431d6
commit
6fd330f221
|
@ -0,0 +1,94 @@
|
|||
package main
|
||||
|
||||
// this file will handle configuration file reading
|
||||
// and also some database functions
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"strings"
|
||||
"github.com/spf13/viper"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
//"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ircVersion string = "sh0rtbus 0.5"
|
||||
var verShort string = "0.5"
|
||||
|
||||
var hlf io.Writer
|
||||
|
||||
func readConfig() {
|
||||
|
||||
//////////////////// defaults //////
|
||||
|
||||
defSizes := map[string]interface{}{
|
||||
"activewindows": 80,
|
||||
"workspace": 50,
|
||||
}
|
||||
|
||||
defColors := map[string]interface{}{
|
||||
"activewindows": 80,
|
||||
"workspace": 50,
|
||||
}
|
||||
|
||||
viper.SetDefault("sizes", defSizes)
|
||||
viper.SetDefault("colors", defColors)
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to determine the users home directory!?")
|
||||
}
|
||||
|
||||
viper.SetConfigType("toml")
|
||||
|
||||
// -c command line flag to override conig file
|
||||
// to override config file location
|
||||
if len(os.Args) > 2 && os.Args[1] == "-c" {
|
||||
log.Info().Str("config", os.Args[2]).Msg("overriding default config file location...")
|
||||
f, err := os.Open(os.Args[2])
|
||||
if err != nil {
|
||||
log.Fatal().Str("config", os.Args[2]).Msg("failed to read config file")
|
||||
}
|
||||
defer f.Close()
|
||||
buf, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
log.Fatal().Str("config", os.Args[2]).Msg("failed to read config file")
|
||||
}
|
||||
err = viper.ReadConfig(bytes.NewBuffer(buf))
|
||||
} else {
|
||||
viper.SetConfigName("5bar5")
|
||||
viper.AddConfigPath(".")
|
||||
viper.AddConfigPath(home + "/.5bar5/")
|
||||
viper.AddConfigPath(home + "/.config/5bar5/")
|
||||
// read config filr and check for errors
|
||||
log.Info().Msg("reading configuration file...")
|
||||
err = viper.ReadInConfig()
|
||||
}
|
||||
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
log.Warn().Msg("Config file not found! Wrting new config to config.toml")
|
||||
err = viper.SafeWriteConfigAs(home + "/.5bar5/5bar5.toml")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Error writing new configuration file")
|
||||
}
|
||||
|
||||
} else if err != nil {
|
||||
log.Fatal().Err(err).Msg("Fatal error when loading configuration file")
|
||||
}
|
||||
|
||||
/////////
|
||||
// Sizes
|
||||
activeWinSize = viper.GetInt("sizes.activewindow")
|
||||
workspaceWidth = viper.GetInt("sizes.workspace")
|
||||
/////////
|
||||
// Colors
|
||||
var err error
|
||||
activeWinBG, err = Hex2RGB(viper.GetString("colors.activewindowbg"))
|
||||
if err != nil {
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
var activeWinSize int
|
||||
var workspaceWidth int
|
||||
var activeWinBG RGB
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
module github.com/onodera-punpun/melonbar
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/AndreKR/multiface v0.0.0-20190725194701-b414aa6424a8
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect
|
||||
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect
|
||||
github.com/BurntSushi/xgb v0.0.0-20201008132610-5f9e7b3c49cd
|
||||
github.com/BurntSushi/xgbutil v0.0.0-20190907113008-ad855c713046
|
||||
github.com/IvanMenshykov/MoonPhase v0.0.0-20180124195458-2a9432a62575
|
||||
github.com/RadhiFadlillah/go-prayer v0.0.0-20200904044351-80665274d4b5
|
||||
github.com/elliotchance/orderedmap v1.3.0
|
||||
github.com/fhs/gompd v1.0.1
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/rkoesters/xdg v0.0.0-20181125232953-edd15b846f9b
|
||||
github.com/shopspring/decimal v1.2.0 // indirect
|
||||
github.com/zachomedia/go-bdf v0.0.0-20200707041239-4d208bb116e0
|
||||
golang.org/x/image v0.0.0-20201208152932-35266b937fa6
|
||||
)
|
|
@ -0,0 +1,40 @@
|
|||
github.com/AndreKR/multiface v0.0.0-20190725194701-b414aa6424a8 h1:Hqhi94Vh24pMnPXH4NkH7N7JNxxiSlV5ANo3227RVDY=
|
||||
github.com/AndreKR/multiface v0.0.0-20190725194701-b414aa6424a8/go.mod h1:F4/sRjlOnpYMDwGUhf9wFxPeM69ZsJw8q4x8258R6LE=
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA=
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
|
||||
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=
|
||||
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
|
||||
github.com/BurntSushi/xgb v0.0.0-20201008132610-5f9e7b3c49cd h1:u7K2oMFMd8APDV3fM1j2rO3U/XJf1g1qC3DDTKou8iM=
|
||||
github.com/BurntSushi/xgb v0.0.0-20201008132610-5f9e7b3c49cd/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/BurntSushi/xgbutil v0.0.0-20190907113008-ad855c713046 h1:O/r2Sj+8QcMF7V5IcmiE2sMFV2q3J47BEirxbXJAdzA=
|
||||
github.com/BurntSushi/xgbutil v0.0.0-20190907113008-ad855c713046/go.mod h1:uw9h2sd4WWHOPdJ13MQpwK5qYWKYDumDqxWWIknEQ+k=
|
||||
github.com/IvanMenshykov/MoonPhase v0.0.0-20180124195458-2a9432a62575 h1:tpM+HaT9ie4OP2UYyZesbehvjXgiWNzBTO1uYUabav0=
|
||||
github.com/IvanMenshykov/MoonPhase v0.0.0-20180124195458-2a9432a62575/go.mod h1:KEFZMBRDCunBlP5n9fXcPt27aXXLsnAq6WUmAl0DA0E=
|
||||
github.com/RadhiFadlillah/go-prayer v0.0.0-20200904044351-80665274d4b5 h1:O8qJ/h85SCrk4roi/ufPNALC9tURB80ErsatkjbCyEw=
|
||||
github.com/RadhiFadlillah/go-prayer v0.0.0-20200904044351-80665274d4b5/go.mod h1:Rbe4Ro4JL1q+pDbkKylPlxuSTNSZP1wG3n2A2BkAD6A=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/elliotchance/orderedmap v1.3.0 h1:k6m77/d0zCXTjsk12nX40TkEBkSICq8T4s6R6bpCqU0=
|
||||
github.com/elliotchance/orderedmap v1.3.0/go.mod h1:8hdSl6jmveQw8ScByd3AaNHNk51RhbTazdqtTty+NFw=
|
||||
github.com/fhs/gompd v1.0.1 h1:kBcAhjnAPJQAylZXR0TeH+d2vpjawXlTtKYguqNlF4A=
|
||||
github.com/fhs/gompd v1.0.1/go.mod h1:b219/mNa9PvRqvkUip51b23hGL3iX4d4q3gNXdtrD04=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rkoesters/xdg v0.0.0-20181125232953-edd15b846f9b h1:8NiY6v9/IlFU8osj1L7kqzRbrG6e3izRQQjGze1Q1R0=
|
||||
github.com/rkoesters/xdg v0.0.0-20181125232953-edd15b846f9b/go.mod h1:T1HolqzmdHnJIH6p7A9LDuvYGQgEHx9ijX3vKgDKU60=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/zachomedia/go-bdf v0.0.0-20200707041239-4d208bb116e0 h1:HtC3N4T2oHU2JjY/kPMZvinP52mWqRxFJVTg8DfZ8qA=
|
||||
github.com/zachomedia/go-bdf v0.0.0-20200707041239-4d208bb116e0/go.mod h1:7j8rs/cA4DZNLcIyjSNpeg5kYy0i9Md+bp6t4PnfPPA=
|
||||
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 h1:nfeHNc1nAqecKCy2FCy4HY+soOOe5sDLJ/gZLbx6GYI=
|
||||
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 241 B |
Loading…
Reference in New Issue