simplify code

This commit is contained in:
yory8 2019-03-22 22:05:37 +01:00
parent ad5f124288
commit 615d5d303a

View file

@ -36,11 +36,12 @@ func dmenu(list []string, max int) (string, error) {
// dmenu will break if items contain newlines, so we must pass them as literals. // dmenu will break if items contain newlines, so we must pass them as literals.
// however, when it sends them back, we need a way to restore them to non literals // however, when it sends them back, we need a way to restore them to non literals
guide := make(map[string]int) guide := make(map[string]string)
reprList := []string{} reprList := []string{}
for i, l := range list { for _, l := range list {
repr := fmt.Sprintf("%#v", l) repr := fmt.Sprintf("%#v", l)
guide[repr] = i repr = repr[1 : len(repr)-1] // drop quotes
guide[repr] = l
reprList = append(reprList, repr) reprList = append(reprList, repr)
} }
@ -52,7 +53,5 @@ func dmenu(list []string, max int) (string, error) {
return "", err return "", err
} }
unescaped := list[guide[string(selected)]] return guide[string(selected)], nil
return unescaped, nil
} }