本文整理匯總了Golang中github.com/BurntSushi/wingo/wini.Data類的典型用法代碼示例。如果您正苦於以下問題:Golang Data類的具體用法?Golang Data怎麽用?Golang Data使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Data類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: loadOptionsConfigSection
func (conf *Configuration) loadOptionsConfigSection(
cdata *wini.Data, section string) {
for _, key := range cdata.Keys(section) {
option := key.Name()
switch option {
case "workspaces":
if workspaces, ok := getLastString(key); ok {
conf.Workspaces = strings.Split(workspaces, " ")
}
case "default_layout":
setString(key, &conf.DefaultLayout)
case "focus_follows_mouse":
setBool(key, &conf.Ffm)
case "focus_follows_mouse_focus":
setBool(key, &conf.FfmFocus)
case "focus_follows_mouse_raise":
setBool(key, &conf.FfmRaise)
case "focus_follows_mouse_startup_focus":
setBool(key, &conf.FfmStartupFocus)
case "popup_time":
setInt(key, &conf.PopupTime)
case "show_popup_fyi":
setBool(key, &conf.ShowFyi)
case "show_popup_errors":
setBool(key, &conf.ShowErrors)
case "cancel":
setString(key, &conf.CancelKey)
case "confirm":
setString(key, &conf.ConfirmKey)
case "audio_play_cmd":
setString(key, &conf.AudioProgram)
}
}
}
示例2: loadKeyConfigSection
func (conf *Configuration) loadKeyConfigSection(
cdata *wini.Data, section string) {
for _, key := range cdata.Keys(section) {
keyStr := key.Name()
for _, cmd := range key.Strings() {
if _, ok := conf.key[section]; !ok {
conf.key[section] = make([]keyCommand, 0)
}
if err := gribbleEnv.Check(cmd); err != nil {
logger.Warning.Printf(
"Could not parse command '%s' because: %s", cmd, err)
} else {
down, justKeyStr := isDown(keyStr)
kcmd := keyCommand{
cmdStr: cmd,
cmdName: gribbleEnv.CommandName(cmd),
down: down,
keyStr: justKeyStr,
}
conf.key[section] = append(conf.key[section], kcmd)
}
}
}
}
示例3: loadKeyConfigSection
func (conf *conf) loadKeyConfigSection(cdata *wini.Data, section string) {
for _, key := range cdata.Keys(section) {
keyStr := key.Name()
for _, cmd := range key.Strings() {
if _, ok := conf.key[section]; !ok {
conf.key[section] = make([]keyCommand, 0)
}
// "keyStr" is actually made up of a key string
// and a toggle of "down" or "up" corresponding to a key press
// or a key release, respectively. Look for that.
// If it isn't there, assume 'down'
spacei := strings.Index(keyStr, " ")
down := true
if spacei > -1 {
if keyStr[spacei+1:] == "up" {
down = false
}
keyStr = keyStr[:spacei]
}
// 'cmd' might have space separated parameters
cmdName, args := commandParse(cmd)
kcmd := keyCommand{
cmd: cmdName,
args: args,
down: down,
keyStr: keyStr,
}
conf.key[section] = append(conf.key[section], kcmd)
}
}
}
示例4: loadMouseConfigSection
// loadMouseConfigSection does two things:
// 1) Inspects the section name to infer the identifier. In general, the
// "mouse" prefix is removed, and whatever remains is the identifier. There
// are two special cases: "MouseBorders*" turns into "borders_*" and
// "MouseFull*" turns into "full_*".
// 2) Constructs a "mouseCommand" for *every* value.
func (conf *conf) loadMouseConfigSection(cdata *wini.Data, section string) {
ident := ""
switch {
case len(section) > 7 && section[:7] == "borders":
ident = "borders_" + section[7:]
case len(section) > 4 && section[:4] == "full":
ident = "full_" + section[4:]
default:
ident = section
}
for _, key := range cdata.Keys(section) {
mouseStr := key.Name()
for _, cmd := range key.Strings() {
if _, ok := conf.mouse[ident]; !ok {
conf.mouse[ident] = make([]mouseCommand, 0)
}
// "mouseStr" is actually made up of a button string
// and a toggle of "down" or "up" corresponding to a button press
// or a button release, respectively. Look for that.
// If it isn't there, assume 'down'
spacei := strings.Index(mouseStr, " ")
down := true
buttonStr := mouseStr
if spacei > -1 {
buttonStr = mouseStr[:spacei]
if mouseStr[spacei+1:] == "up" {
down = false
}
}
// 'cmd' can sometimes take parameters. For mouse commands,
// only one such command does so: Resize. Check for that.
// (The parameter is which way to resize. If it's absent, default
// to "Infer".)
var direction uint32 = ewmh.Infer
if len(cmd) > 6 && strings.ToLower(cmd[:6]) == "resize" {
spacei := strings.Index(cmd, " ")
if spacei > -1 {
direction = strToDirection(cmd[spacei+1:])
cmd = cmd[:spacei]
}
}
mcmd := mouseCommand{
cmd: cmd,
down: down,
buttonStr: buttonStr,
direction: direction,
}
conf.mouse[ident] = append(conf.mouse[ident], mcmd)
}
}
}
示例5: loadFloat
func loadFloat(dat *wini.Data, name, key string, target *float64) {
k := dat.GetKey(name, key)
if k == nil {
utils.Fail("Missing key " + key + " in section " + name)
}
tmp, err := k.Floats()
utils.FailMeMaybe(err)
if len(tmp) > 0 {
*target = tmp[0]
} else {
utils.Fail("Missing key " + key + " in section " + name)
}
}
示例6: loadOptionsConfigSection
func (conf *conf) loadOptionsConfigSection(cdata *wini.Data, section string) {
for _, key := range cdata.Keys(section) {
option := key.Name()
switch option {
case "workspaces":
if workspaces, ok := getLastString(key); ok {
conf.workspaces = strings.Split(workspaces, " ")
}
case "always_floating":
if alwaysFloating, ok := getLastString(key); ok {
conf.alwaysFloating = strings.Split(alwaysFloating, " ")
}
case "focus_follows_mouse":
setBool(key, &conf.ffm)
case "cancel":
setString(key, &conf.cancelKey)
case "confirm":
setString(key, &conf.confirmKey)
}
}
}
示例7: loadString
func loadString(dat *wini.Data, name, key, def string, target *string) {
k := dat.GetKey(name, key)
if k == nil {
if def == "" {
utils.Fail("Missing key " + key + " in section " + name)
} else {
*target = def
return
}
}
tmp := k.Strings()
if len(tmp) > 0 {
*target = tmp[0]
} else {
if def == "" {
utils.Fail("Missing key " + key + " in section " + name)
} else {
*target = def
return
}
}
}
示例8: loadMouseConfigSection
// loadMouseConfigSection does two things:
// 1) Inspects the section name to infer the identifier. In general, the
// "mouse" prefix is removed, and whatever remains is the identifier. There
// are two special cases: "MouseBorders*" turns into "borders_*" and
// "MouseFull*" turns into "full_*".
// 2) Constructs a "mouseCommand" for *every* value.
//
// The idents are used for attaching mouse commands to the corresponding
// frames. (See the mouseCommand methods.)
func (conf *Configuration) loadMouseConfigSection(
cdata *wini.Data, section string) {
ident := ""
switch {
case len(section) > 7 && section[:7] == "borders":
ident = "borders_" + section[7:]
case len(section) > 4 && section[:4] == "full":
ident = "full_" + section[4:]
default:
ident = section
}
for _, key := range cdata.Keys(section) {
mouseStr := key.Name()
for _, cmd := range key.Strings() {
if _, ok := conf.mouse[ident]; !ok {
conf.mouse[ident] = make([]mouseCommand, 0)
}
if err := gribbleEnv.Check(cmd); err != nil {
logger.Warning.Printf(
"Could not parse command '%s' because: %s", cmd, err)
} else {
down, justMouseStr := isDown(mouseStr)
mcmd := mouseCommand{
cmdStr: cmd,
cmdName: gribbleEnv.CommandName(cmd),
down: down,
buttonStr: justMouseStr,
}
conf.mouse[ident] = append(conf.mouse[ident], mcmd)
}
}
}
}
示例9: readSection
// readSection loads a particular section from the configuration file into
// the hook groups. One section may result in the same hook being added to
// multiple groups.
func readSection(cdata *wini.Data, section string) error {
// First lets roll up the match conditions.
match := cdata.GetKey(section, "match")
if match == nil {
return fmt.Errorf("Could not find 'match' in the '%s' hook.", section)
}
satisfies := make([]string, len(match.Strings()))
copy(satisfies, match.Strings())
// Check each satisfies command to make sure it's a valid Gribble command.
if cmd, err := checkCommands(satisfies); err != nil {
return fmt.Errorf("The match command '%s' in the '%s' hook could "+
"not be parsed: %s", cmd, section, err)
}
// Now try to find whether it's a conjunction or not.
conjunction := true
conjunctionKey := cdata.GetKey(section, "conjunction")
if conjunctionKey != nil {
if vals, err := conjunctionKey.Bools(); err != nil {
logger.Warning.Println(err)
} else {
conjunction = vals[0]
}
}
// Now traverse all of the keys in the section. We'll skip "match" since
// we've already grabbed the data. Any other key should correspond to
// a hook group name.
addedOne := false
for _, key := range cdata.Keys(section) {
groupName := Type(key.Name())
if groupName == "match" || groupName == "conjunction" {
continue
}
if _, ok := groups[groupName]; !ok {
return fmt.Errorf("Unrecognized hook group '%s' in the '%s' hook.",
groupName, section)
}
consequences := make([]string, len(key.Strings()))
copy(consequences, key.Strings())
// Check each consequent command to make sure it's valid.
if cmd, err := checkCommands(consequences); err != nil {
return fmt.Errorf("The '%s' command '%s' in the '%s' hook could "+
"not be parsed: %s", groupName, cmd, section, err)
}
hook := hook{
name: section,
satisfies: satisfies,
conjunction: conjunction,
consequences: consequences,
}
groups[groupName] = append(groups[groupName], hook)
addedOne = true
}
if !addedOne {
return fmt.Errorf(
"No hook groups were detected in the '%s' hook.", section)
}
return nil
}