v1cont / yad

Yet Another Dialog
GNU General Public License v3.0
657 stars 58 forks source link

"&" character in list dialog #167

Open Mzed3D opened 2 years ago

Mzed3D commented 2 years ago

Hello! I really can't manage to use the character "&" for a string in a list dialog. I tryed backslashing it, double quoting it, nothing works. Everytime it is interpreted as an actual command. Is there a way to solve this? Is it a bug? Thanks!

cou645 commented 2 years ago

escape ampersand "&' this way without quotes '&'

On Thu, 7 Apr 2022, 13:05 Mzed3D, @.***> wrote:

Hello! I really can't manage to use the character "&" for a string in a list dialog. I tryed backslashing it, double quoting it, nothing works. Everytime it is interpreted as an actual command. Is there a way to solve this? Is it a bug? Thanks!

— Reply to this email directly, view it on GitHub https://github.com/v1cont/yad/issues/167, or unsubscribe https://github.com/notifications/unsubscribe-auth/APRODEQ4ZAHYWXIZSZCBCSDVD3FOTANCNFSM5SZEQ5PQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Mzed3D commented 2 years ago

It worked! Thanks!

v1cont commented 2 years ago

or use --no-markup option

Misko-2083 commented 2 years ago

Remember to escape "<>" characters too.

#!/usr/bin/env bash

pangoEscape() {
    local string="${1//&/&amp;}"
    string="${string//</&lt;}"
    string="${string//>/&gt;}"
    printf '%s' "$string"
}

declare -i index=0

for f in ./*
do
    [[ -d "$f" ]] && continue # files only
    filelist+=("$(readlink -f "$f")")
    f="${f##*/}"
    yadlist+=(FALSE "$(pangoEscape "${f}")" "${index}")
    let index=index+1
done

choice=$(yad --list --text="Choose some files" --search-column=2 \
             --center --borders=20 --width=400 --height=500 \
             --checklist --column="Select:CHK" --column="Name:TEXT" \
             --column=path:HD "${yadlist[@]}" --separator=' ' \
             --print-column=3 --button=OK:0 --button=Cancel:1 )

for key in ${choice}
do
    echo "${filelist[${key}]}"
done