style: gofmt

This commit is contained in:
yory8 2019-09-15 09:34:04 +02:00
parent bcfcd493fc
commit 9f4d0dd044

View file

@ -31,7 +31,7 @@ func dmenu(list []string, max int, tool string) (string, error) {
} }
if tool == "-" { if tool == "-" {
escaped, _ := preprocess_history(list, false) escaped, _ := preprocessHistory(list, false)
os.Stdout.WriteString(strings.Join(escaped, "\n")) os.Stdout.WriteString(strings.Join(escaped, "\n"))
return "", nil return "", nil
} }
@ -57,7 +57,7 @@ func dmenu(list []string, max int, tool string) (string, error) {
return "", fmt.Errorf("Unsupported tool") return "", fmt.Errorf("Unsupported tool")
} }
escaped, guide := preprocess_history(list, true) escaped, guide := preprocessHistory(list, true)
input := strings.NewReader(strings.Join(escaped, "\n")) input := strings.NewReader(strings.Join(escaped, "\n"))
cmd := exec.Cmd{Path: bin, Args: args, Stdin: input} cmd := exec.Cmd{Path: bin, Args: args, Stdin: input}
@ -79,28 +79,28 @@ func dmenu(list []string, max int, tool string) (string, error) {
return sel, nil return sel, nil
} }
func preprocess_history(list []string, cutting bool) ([]string, map[string]string) { func preprocessHistory(list []string, cutting bool) ([]string, map[string]string) {
// 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 // however, when it sends them back, we need a way to restore them
var escaped []string var escaped []string
guide := make(map[string]string) guide := make(map[string]string)
for _, original := range list { for _, original := range list {
repr := fmt.Sprintf("%#v", original) repr := fmt.Sprintf("%#v", original)
max := len(repr) - 1 // drop right quote max := len(repr) - 1 // drop right quote
// dmenu will split lines longer than 1200 something; we cut at 400 to spare memory // dmenu will split lines longer than 1200 something; we cut at 400 to spare memory
if cutting { if cutting {
maxChars := 400 maxChars := 400
if max > maxChars { if max > maxChars {
max = maxChars max = maxChars
} }
} }
repr = repr[1:max] // drop left quote repr = repr[1:max] // drop left quote
guide[repr] = original guide[repr] = original
escaped = append(escaped, repr) escaped = append(escaped, repr)
} }
return escaped, guide return escaped, guide
} }