tooltip: Use fold for line wraps in text
This commit is contained in:
parent
207ae059b5
commit
f80324659f
16
xkcdlock
16
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
|
||||
local text=$(echo $text | fold -s -w $TOOLTIP_MAX_LINE_LEN)
|
||||
echo "$text"
|
||||
fi
|
||||
}
|
||||
|
||||
get_nscreens() {
|
||||
|
|
Loading…
Reference in New Issue