From f80324659f85d3fbc004d36b69cd3dd6fb783e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Busse?= Date: Fri, 19 Feb 2021 20:08:04 +0100 Subject: [PATCH] tooltip: Use fold for line wraps in text --- xkcdlock | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/xkcdlock b/xkcdlock index e35e221..e9a01b1 100755 --- a/xkcdlock +++ b/xkcdlock @@ -46,7 +46,7 @@ IMG_DEFAULT="not_really_into_pokemon.png" # background colour BG_COLOUR="white" # Break tooltip every x char to prevent border overflow -TOOLTIP_MAX_LINE_LEN=120 +TOOLTIP_MAX_LINE_LEN=100 FONT="xkcd Script" FONT_FILE="xkcd-script.ttf" @@ -201,20 +201,8 @@ xkcd_get_img_tooltip() { } xkcd_format_tooltip() { - local ntext=${#text} - local nbreaks=$((ntext / TOOLTIP_MAX_LINE_LEN)) - local nbreak=$((ntext - TOOLTIP_MAX_LINE_LEN)) - local m=$((nbreaks * TOOLTIP_MAX_LINE_LEN)) - local nrest=$((ntext - m - 1)) - - if (( "$nbreak" > 0 )); then - local text_tok_start=${text:0:$nrest} - local text_tok_end=${text:ntok_end} - text_tok_end=`echo "$text_tok_end" | sed "s/.\{$TOOLTIP_MAX_LINE_LEN\}/&\\n/g"` - echo "${text_tok_start}\\n${text_tok_end}" - else - echo "$text" - fi + local text=$(echo $text | fold -s -w $TOOLTIP_MAX_LINE_LEN) + echo "$text" } get_nscreens() {