From cd492bea9e2752812b98c96bced969b9304b4ed1 Mon Sep 17 00:00:00 2001 From: yory8 <> Date: Thu, 4 Apr 2019 09:04:57 +0200 Subject: [PATCH] bugfix: respect dmenu's line length --- selector.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/selector.go b/selector.go index 524494b..487c15a 100644 --- a/selector.go +++ b/selector.go @@ -40,7 +40,11 @@ func dmenu(list []string, max int) (string, error) { reprList := []string{} for _, original := range list { repr := fmt.Sprintf("%#v", original) - repr = repr[1 : len(repr)-1] // drop quotes + max := len(repr) - 1 // drop right quote + if max > 800 { // dmenu will split lines longer than 1200 something; we cut at 800. + max = 800 + } + repr = repr[1:max] // drop left quote guide[repr] = original reprList = append(reprList, repr) } @@ -54,5 +58,10 @@ func dmenu(list []string, max int) (string, error) { } trimmed := selected[:len(selected)-1] // drop newline - return guide[string(trimmed)], nil + sel, ok := guide[string(trimmed)] + if !ok { + return "", fmt.Errorf("couldn't recover original string; please report this bug along with a copy of your clipman.json") + } + + return sel, nil }