Touch Friendly Selection

Experimental widget to select a color by name or RGB value using a key value datalist.

Notice: a namespace error occurs, when code is copy/pasted in tclsh console. When sourced from file this does not happen.

# Copyright (c) : 2026, Roland Frank
# License MIT
# fragile code, that literally <break>'s when touched, see catch cases
package require Tk
namespace eval zirkon {
    variable tpl3 "{0 1 2} {0 2 1} {1 0 2} {1 2 0} {2 0 1} {2 1 0}"
    proc lperm3 {var} {
        upvar $var parts
        set palen [llength $parts]
        if {$palen >= 3} {
            set tail [join [lrange $parts 2 end] _]
            set parts [lreplace $parts 2 end $tail]
        }
        if {$palen == 3} {
            set mymap {}
            set n 0
            foreach z $parts {
                lappend mymap $n $z
                incr n
            }
            set perms [string map $mymap $::zirkon::tpl3]
        } elseif {$palen == 2} {
            set perms {}
            foreach {a b} $parts {
                break
            }
            set extra [regexp ^\u26d4 $a]
            if {$extra} {
                lappend perms [list $a]
            }
            lappend perms [list $a $b]
            if {!$extra} {
                lappend perms [list $b $a]
            }
        } else {
            set perms $parts
        }
        return $perms
    }
    proc perm3 {var} {
        set parts [split $var " "]
        if {[llength $parts]>=3} {
            set tail [join [lrange $parts 2 end] _]
            set parts [lreplace $parts 2 end $tail]
        }
        if {[llength $parts]==3} {
            set mymap {}
            set n 0
            foreach z $parts {
                lappend mymap $n $z
                incr n
            }
            set perms [string map $mymap $::zirkon::tpl3]
        } elseif {[llength $parts]==2} {
            set perms {}
            foreach {a b} $parts {
                break
            }
            set extra [regexp ^\u26d4 $a]
            if {$extra} {
                lappend perms [list $a]
            }
            lappend perms [list $a $b]
            if {!$extra} {
                lappend perms [list $b $a]
            }
        } else {
            set perms [list $var]
        }
        return $perms
    }
    proc lredux {z} {
        upvar $z ll
        set tmp [lreverse $ll]
        set res [list]
        set v_h [lindex $tmp 0]
        set k_h [lindex $tmp 1]
        append v_h x
        foreach {v k} $tmp {
            if {[string equal $v $v_h]} {
                set hh [split $k_h {}]
                set cc [split $k {}]
                set hh0 [lindex $hh 0]
                set cc0 [lindex $cc 0]
                if {![string equal $hh0 $cc0]} {
                    lappend res $v $k
                    set k_h $k
                    continue
                }
            } else {
                lappend res $v $k
                set k_h $k
            }
        }
        lreverse $res
    }
    proc unify {res} {
        set uu 8320
        array set nodup {}
        set tmp [list]
        foreach {dname oid} $res {
            set ff [zirkon::perm3 $dname]
            foreach perm $ff {
                if {[catch {set idlist $nodup($perm)}]} {
                    set nodup($perm) [list $oid]
                } else {
                    if {[lsearch $idlist $oid]>-1} {
                        break
                    } else {
                        lappend idlist $oid
                        set nodup($perm) [lsort -unique $idlist]
                    }
                }
                lappend tmp $perm $oid
            }
        }
        set dest {}
        foreach {perm oid} $tmp {
            set pos [lsearch -exact $nodup($perm) $oid]
            incr pos -1
            if {$pos>-1} {
                set hex [expr {$uu + $pos}]
                set subscript [subst -nocommands -novariables [format \\u%x $hex]]
                lappend perm $subscript
            }
            lappend dest [join $perm " "] $oid
        }
        array unset nodup
        return [lsort -stride 2 $dest]
    }
    proc personal_name {name surname zz listname} {
        upvar 1 $listname dest
        set act ""
        if {[string length $name]} {
            append act $name
            if {[string length $surname]} {
                append act " " $surname
            }
        }
        set lk [split $act " "]
        if {[llength $lk]} {
            lappend dest $lk $zz
        }
    }
    proc k2v {key1 key2 value listname} {
        upvar 1 $listname dest
        set k1 [regsub -all { } $key1 \u00a0]
        set k2 [regsub -all { } $key2 \u00a0]
        lappend dest [list $k1 $k2] $value [list $k2 $k1] $value
    }
    proc lcp {a b} {
        set res ""
        foreach ac [split $a {}] bc [split $b {}] {
            if {$ac eq "" || $bc eq ""} {
                break
            }
            if {$ac eq $bc} {
                append res $ac
            } else {
                break
            }
        }
        set res
    }
    proc nextchar {act} {
        if {${act} eq ""} {
            return [format %c 0]
        } else {
            scan $act %c i
            incr i
            if {$i < 128} {
                return [format %c $i]
            } elseif {$i < 65536} {
                return [subst \\u[format %04x $i]]
            } else {
                return [subst \\U[format %llx $i]]
            }
        }
    }
    oo::class create zirkon {
        variable zr
        variable pnr
        variable head_range
        variable p_range
        variable cesta
        variable hashed
        variable coherent
        variable fix
        constructor {} {
            set record {}
            array set ubi {}
            my reset 1
        }
        method reset {{init 0}} {
            if {!$init} {
                array unset pnr
                array unset head_range
                array unset p_range
                array unset cesta
            }
            set fix ""
            set zr {}
            array set pnr {}
            array set head_range {}
            array set p_range {}
            set head_range() [list 0 -1]
            array set cesta {}
            set hashed {}
            set coherent 0
        }
        method clear {} {
            my reset 0
        }
        method list2 {l2} {
            upvar 1 $l2 tt
            set ph {}
            set max_lcount 0
            set coherent 0
            foreach pair $tt {
                foreach {k v} $pair break
                set lcount 0
                lappend ph $k
                array set pnr [list $k $v]
                incr lcount
                if {$lcount>$max_lcount} {
                    set max_lcount $lcount
                    set coherent $max_lcount
                }
            }
            set zr [lsort -unique -stride 2 $ph]
            #my max_sequence
        }
        method max_sequence {} {
                           set coherent 0
                           set k_h ""
                           set act 0
                           foreach x $zr {
                                   set k [lindex $x end]
                                   if {[string equal $k $k_h]} {
                                           incr act
                                   } else {
                                           set coherent [expr {$act>$coherent ? $act : $coherent}]
                                           set act 0
                                   }
                                   set k_h $k
                           }
                   }
        method opt {} {
            parray cesta
        }
        method head {} {
            parray head_range
        }
        method set_root {} {
            set el_left [lindex $zr 0]
            set zrlen [llength $zr]
            set last_index [expr {$zrlen-1}]
            if {$last_index>0} {
                set el_right [lindex $zr $last_index]
                set fix [zirkon::lcp $el_left $el_right]
            } else {
                set fix $el_left
            }
            return $fix
        }
        method get_root {} {
            return $fix
        }
        method hash_clear {} {
            array unset pnr
        }
        method hash {k v} {
            array set pnr [list $k $v]
        }
        method insertindex {x start index_afterlast} {
            set end $index_afterlast
            while {$start<$end} {
                set dist [expr {$end-$start}]
                set mid [expr {$dist/2}]
                incr mid $start
                set s [string compare [lindex $zr $mid] $x]
                if {$s<0} {
                    set start [expr {$mid+1}]
                } elseif {$s==0}  {
                    return $mid
                } else {
                    set end $mid
                }
            }
            return $start
        }
        method init {rawlist} {
            upvar $rawlist listready
            if {[llength $listready] > 1} {
                set tmpx [lsort -stride 2 -unique [zirkon::unify $listready]]
                set tmp [zirkon::lredux tmpx]
                set tmp $tmpx
            } else {
                set tmp [lindex $listready 0]
            }
            set zr {}
            set coherent 0
            set v_h ""
            set repeated 0
            foreach {k v} $tmp {
                lappend zr $k
                set pnr($k) $v
                if {[string equal $v $v_h]} {
                    incr repeated
                } else {
                    set coherent [expr {$repeated>$coherent ? $repeated : $coherent}]
                    set repeated 0
                }
                set v_h $v
            }
            return [my set_root]
        }
        method pnr_set {key value} {
            set pnr($key) $value
        }
        method pnr_get {key} {
            if {$key eq {}} {return {}}
            if {[llength $key]>4} {
                error hics
            }
            variable pnr
            if {[catch {set value $pnr($key)}]} {
                set px [string range $key 0 3]
                append px *
                return black
                return ""
            }
            return $value
        }
        method count {} {
            return [llength $zr]
        }
        method zr_range {from to} {
            for {set n $from} {$n<$to} {incr n} {
            }
        }
        method search {prefix} {
            set indices [lsearch -all -glob $zr ${prefix}*]
            set x 0
            foreach x $indices {
                set key [lindex $zr $x]
            }
            set sublist [lrange $zr [lindex $indices 0] $x]
            set tmp {}
            foreach key $sublist {
                lappend tmp [list $key $pnr($key)]
            }
            set sorted [lsort -unique -index 1 $tmp]
            set res [lsort -index 0 $sorted]
            set len_res [llength $res]
            set len_tmp [llength $tmp]
            if {$len_res < $len_tmp} {
                set tmp [lsort -index 0 $sorted]
                foreach x $tmp {
                }
            }
            set re $head_range($prefix)
            lassign $re a b
            if {$len_tmp == $len_res * 2} {
                set head_range($prefix) [list $a [expr {$a+$len_res}]]
                set start $a
                foreach x $tmp {
                    lset zr $start [lindex $x 0]
                    incr start
                }
                incr start -1
            }
        }
        method more {prefix {start 0} {end -1}} {
            if {$end<0} {
                set end [llength $zr]
                if {$end ==0} {
                    return {}
                }
            }
            set res [list]
            set plen [llength [split $prefix {}]]
            if {[catch {
                    set elco [expr {$end-$start}]
                } err]} {
                error "$err"
            }
            set el_left [lindex $zr $start]
            set l_left [split $el_left {}]
            if {$elco==1} {
                lappend res [list $el_left 1 0 1]
            } elseif {$elco==2} {
                set head_range($prefix) [list $start $end]
                lappend res [list $el_left 1 $start [incr start]]
                set second [lindex $zr $start]
                lappend res [list $second 1 $start [incr start]]
            } else {
                set el_next [lindex $zr [expr {$start+1}]]
                set lnext [split $el_next {}]
                set l_left [split $el_left {}]
                set left_len [llength $l_left]
                set el_next_prefix [join [lrange $lnext 0 $left_len] {}]
                if {[string equal $el_left $el_next_prefix]} {
                    lappend res [list $el_left 1 $start [expr {$start+1}]]
                    incr start
                    set el_left [lindex $zr $start]
                    set l_left [split $el_left {}]
                }
                set total [expr {$end-$start}]
                while {$start <$end} {
                    set current [lindex $l_left $plen]
                    set next [zirkon::nextchar $current]
                    set pos [my insertindex $prefix$next $start $end]
                    set elco [expr {$pos-$start}]
                    if {$elco==1} {
                        lappend res [list $el_left 1 $start $pos]
                    } elseif {$elco==2 && $total==2} {
                        lappend res [list $el_left 1 $start [incr start]]
                        set el_left [lindex $zr $start]
                        set l_left [split $el_left {}]
                        lappend res [list $el_left 1 $start [incr start]]
                    } else {
                        set last [expr {$pos-1}]
                        set el_right [lindex $zr $last]
                        set common [zirkon::lcp $el_left $el_right]
                        if {$elco<=$coherent} {
                            set jitem [lindex $zr $start]
                            set last_v $pnr($jitem)
                            for {set j [expr {$start+1}]} {$j<$pos} {incr j} {
                                set jitem [lindex $zr $j]
                                set act_v $pnr($jitem)
                                if {![string equal $act_v $last_v]} {
                                    set skip_seq 1
                                    break
                                }
                            }
                            lappend res [list $common $elco $start $pos]
                        } else {
                            lappend res [list $common $elco $start $pos]
                        }
                        if {$plen && ![string length $common]} {
                            set exact ^
                            append exact [string map { . \\. * \\* ? \\? \{ \\\{ \} \\\} \[ \\\[ \] \\\] \$ \\\$} $prefix]
                            if {0} {
                                if {![regexp $exact $el_left] } {
                                    error "$el_left @ index $start does not start with $prefix"
                                } elseif {![regexp $exact $el_right]} {
                                    error "$el_right @ index $last does not start with $prefix"
                                } else {
                                    error "empty common prefix"
                                }
                            }
                        }
                    }
                    if {$pos >= $end} {
                        break
                    }
                    if {$pos==$start} {
                        break
                    }
                    set el_left [lindex $zr $pos]
                    set l_left [split $el_left {}]
                    set start $pos
                }
            }
            set cesta($prefix) $res
            set ::xx $res
            set exact ^
            append exact [string map { . \\. * \\* ? \\? \{ \\\{ \} \\\} \[ \\\[ \] \\\] \$ \\\$} $prefix]
            set ::tmp [lsearch -all -inline -index 0 -regexp $res $exact]
            set i0 [lindex $::tmp 0]
            set iend [lindex $::tmp end]
            set end [lindex $iend 3]
            set head_range($prefix) [list [lindex $i0 2] $end]
            set cesta($prefix) $::tmp
            return $::tmp
            set res
        }
        method uncesta {key} {
            array unset cesta
            array unset head_range
            return
            if {[catch {unset cesta($key)} err]} {
            }
            if {[catch {unset head_range($key)} err]} {
            }
        }
        method cesta {} {
            parray cesta
        }
        method subcounter {prefix {alt_space {\u2423}}} {
            if {$prefix eq {}} {return 0}
            set prefix [regsub {\r$} $prefix {}]
            set known {}
            if {[catch {
                    set known $head_range($prefix)
                } err]} {
                return 1
            }
            lassign $known start end
            return [expr {$end - $start}]
        }
        method unique_subcounter {prefix} {
            if {[catch {set known $head_range($prefix)}]} {
                return 0
            }
            lassign $known start end
            set values {}
            for {set i $start} {$i<$end} {incr i} {
                lappend values [my pnr_get [lindex $zr $i]]
            }
            return [llength [lsort -unique $values]]
        }
        method first_value {prefix} {
            set prefix [regsub {\ *[\\u8320-\\u8309]+$} $prefix {}]
            if {[catch {set known $head_range($prefix)}]} {
                return white
            }
            set first {}
            lassign $known vfirst vlast
            set key [lindex $zr $vfirst]
            my pnr_get $key
        }
        method index {prefix} {
            if {[catch {
                    set known $head_range($prefix)
                } err]} {
                set known {}
            }
            set known
        }
        method range {prefix} {
            if {[catch {
                    set known $head_range($prefix)
                    set end 0
                    lassign $known start end
                    incr end -1
                } err]} {
                error "subcounter: missing range"
                return 0
            }
            return [lrange $zr $start $end]
        }
        method set_head {prefix prefix_previous continuation_first continuation_last} {
#puts set_head:<$prefix><$prefix_previous><$continuation_first><$continuation_last>
            lassign $head_range($prefix_previous) start end
#puts start=$start
#puts searchstr=$prefix_previous$continuation_first
                                lassign [lsort [list $prefix_previous$continuation_first $prefix_previous$continuation_last]] el_lo el_hi
            set start [lsearch -start $start -exact $zr $el_lo]
#puts start=$start
#puts searchstr=$prefix_previous$continuation_last
            set end [lsearch -start $start -exact $zr $el_hi]
#puts end=$end
                                if {$start==$end} {
#puts final-value-does-not-need..
                                        error "wrong assumption"
                                } 
            incr end
            set head_range($prefix) [list $start $end]
#puts $head_range($prefix)
        }
        method spisok {head {maxfinal {0}} {start 0} {end -1}} {
            if {$head eq {}} {
                set head [my get_root]
            }
            if {![catch {set hashed $cesta($head)} err]} {
                return $hashed
            } else {
                set tuple [array get head_range [string map {* \\* ? \\? \[ \\\[ \] \\\] \\ \\\\]}  $head]]
                set range {}
                lassign $tuple key range
                set h_start 0
                set h_end -1
                if {![llength $range]} {
                    set shorter $head
                    while {[regsub \.$ $shorter {} head_s]} {
                        set tuple [array get head_range $head_s]
                        lassign $tuple key range
                        if {[llength $range]} {
                            lassign $range h_start h_end
                            break
                        }
                        set shorter $head_s
                    }
                } else {
                    lassign $range h_start h_end
                }
                if {![string is integer $h_start] || ![string is integer $h_end]} {
                    parray head_range
                    error stop
                }
                if {$maxfinal} {
                    set skip 0
                    if {[catch {
                            set rows [expr {$h_end-$h_start}]
                        } err]} {
                        my uncesta dummy
                        return [my more $head 0]
                    }
                    if {$rows>0 && $rows<=$maxfinal} {
                        set full [lrange $zr $h_start [expr {$h_end-1}]]
                        set tmp {}
                        foreach x $full {
                            if {[catch {
                                    lappend tmp [list $pnr($x) $x]
                                } err]} {} ;#{parray pnr;update;error "$err"}
                        }
                        set tmp_u [lsort -index 0 -unique $tmp]
                        if {[llength $tmp_u] < $rows} {
                            set full {}
                            foreach x $tmp {
                                lappend full [lindex $x 1]
                            }
                        }
                        set head_range($head) [list $h_start $h_end]
                        set tmp {}
                        set plen [llength [split $head {}]]
                        foreach x $full {
                            set rest [join [lrange [split $x {}] $plen end] {}]
                            lappend tmp $rest
                        }
                        set n $tmp
                        set tmp {}
                        set included {}
                        foreach continuation $n {
                            set x $head
                            append x $continuation
                            if {[catch {set value $pnr($x)}]} {
                                break
                            }
                            if {[lsearch $included $value]==-1} {
                                lappend tmp [list 1 $continuation]
                                lappend included $value
                            }
                        }
                        return $tmp
                    }
                }
            }
            set n [my more $head $h_start $h_end]
            set nn {}
            foreach tmp $n {
                lassign $tmp prefix nx h_start h_end
                if {[catch {set dummy $head_range($prefix)}]} {
                    set head_range($prefix) [list $h_start $h_end]
                }
                set skip 0
                if {$nx<3} {}
                if {$nx<=6} {
                    set kv {}
                    foreach x [lrange $zr $h_start [expr {$h_end-1}]] {
                        lappend kv $x $pnr($x)
                    }
                    set tmp [lsort -stride 2 -index 1 -unique $kv]
                    lappend nn $tmp
                } else {
                    lappend nn $tmp
                }
            }
            set head_len [llength [split $head {}]]
            set res [list]
            foreach el $n {
                foreach {fulltext count h_start h_end} $el break
                if {[string length $fulltext]} {
                    set final [expr {$count==1}]
                    set l_fulltext [split $fulltext {}]
                    lappend res [list $final [join [lrange $l_fulltext $head_len "end"] {}]]
                }
            }
            set cesta($head) $res
            return $res
        }
    }
}
namespace eval ::corolatus {
    variable TB
    proc traverse {w} {
        foreach x [winfo children $w] {
            woron::traverse $x
        }
    }
    proc dummy_cb {args} {}
    set android [expr {[catch {package require Borg}]==0}]
    if {$android} {
        set adb_debug 0
        set adb_debug 0
        if {$adb_debug} {
            if {[catch {package require http} err]} {
                tk_messageBox -message $err -title error
                exit
            } else {
                if {[catch {package require tkconclient} err]} {
                    tk_messageBox -message "tkconclient: err=<$err>"
                } else {
                    proc sbin {} {
                        fconfigure [set tkconclient::socket] -translation binary
                    }
                    tkconclient::start 4488
                    tk_messageBox -message "vwait vv"
                    vwait vv
                }
            }
        }
    } else {
        proc ::borg args {
            set a [lindex $args 0]
            if {$a eq "osbuildinfo"} {
                return {version.sdk none}
            }
            return 0
        }
        proc ::sdltk args {}
    }
    if {$android} {} else {
        catch { package require Tk }
    }
    proc check_utf_max {} {
        scan {\U10000} %c i
        if {$i == 65533} {
            error TCL_UTF_MAX
        }
    }
    if 0 {
        if {[catch check_utf_max]} {
            exit
        }
    }
    oo::class create coex_vybor {
        variable otbor
        method option_defaults {} {
            set otbor [list -android 1 -show_input 1 -zr_size 1 -list_size 0]
            return $otbor
        }
        method option_keys {} {
            return [lsort [dict keys $otbor]]
        }
    }
    oo::class create corolatus {
        superclass coex_vybor
        variable top_info
        variable tltext
        variable listcolors
        variable splash1
        variable focus_index
        variable windows_once
        variable bc_valid
        variable R
        variable lr
        variable rl
        variable an
        variable ran
        variable frame_ahead
        variable choices
        variable bottom_frames
        variable delta
        variable prefix_frame
        variable input
        variable back_lr
        variable magnify
        variable homelabel homesymbol
        variable suffix
        variable aftersuffix
        variable textrow
        variable textrow_width
        variable textrow_height
        variable logo
        variable textpath
        variable ltr ltr_h portrait portrait_old erase padx_dir
        variable home {}
        variable nav
        variable keyboard
        variable istouch
        variable breadcrumbs
        variable mlang
        variable current_suffix
        variable bcidx
        variable pnr
        variable vis_hash
        variable odds
        variable ellipsis
        variable color_back_bg
        variable color_prefix_bg
        variable color_back_fg
        variable color_fw_bg
        variable color_fw_fg
        variable color_home_bg
        variable uni_fg
        variable color_active_fg
        variable color_d_fg
        variable color_d_final_fg
        variable color_d_bg
        variable color_fill_fg
        variable color_fill_bg
        variable color_amount_fg
        variable color_hi_bg
        variable color_hi_co
        variable color_select_bg
        variable color_select_fg
        variable hltness
        variable options
        variable sdk_version
        variable osinfo
        variable lang
        variable andratop
        variable R
        variable topframe
        variable taipudex
        variable xfont topfont lfont
        variable suffix_is_wrapped
        variable startscreen
        variable wait
        variable elements
        variable element_start
        variable element_end
        variable daba
        variable focus_from
        variable selected_value
        variable event_target
        variable btag_back
        variable btag_forward
        variable root
        variable flexcol
        variable flexrow
        variable flexcolor
        variable flex_check
        variable robyv
        variable row_max
        variable col_max
        variable suffix_widgets
        variable newletter
        variable dows
        variable first_time
        variable cwid {}
        variable refocus
        variable wsa
        variable android
        variable deco
        variable llp
        variable ll0
        variable ll0c
        variable lls
        variable lbc
        variable lfill
        variable llam
        variable dab
        variable lhlt
        variable zr_size
        variable show_input
        variable hkf
        variable hkf_
        variable listmode
        constructor {theframe andra {ddd_list {}} {ddd_error 0} args} {
            set top_info ""
            set tltext ""
            bind $theframe <FocusOut> [list event generate $theframe <Unmap>]
            bind $theframe <FocusIn> [list event generate $theframe <Map>]
            set listmode 0
            set listcolors {LavenderBlush2 "powder blue" LightSteelBlue1 thistle1 azure plum1}
            my set_options $args
            set choices ""
            set bottom_frames {}
            array set osinfo [borg osbuildinfo]
            set sdk_version $osinfo(version.sdk)
            array unset osinfo
            set hltness 2
            set llp {}
            set ll0 {}
            set ll0c {}
            set lls {}
            set lbc {}
            set lfill {}
            set llam {}
            set lhlt {}
                                set deco [list \u56da \u2621 \u2588 \u2623]
            set android $andra
            set refocus ""
            if {!$android} {
                set dows [string equal $::tcl_platform(platform) windows]
                set wsa [expr {$dows || ![string length [info nameofexecutable]]}]
            } else {
                set wsa 0
                set dows 0
            }
            set dab 1
            set first_time 1
            set btag_back ""
            set btag_forward ""
            set newletter x
            set suffix_widgets {}
            set flexcol ""
            set flex_check 0
            set root {}
            lappend ::oo $theframe
            set focus_index -1
            set event_target ""
            set focus_from ""
            set bc_valid 0
            set suffix ""
            set textrow ""
            set textrow_height 0
            set textrow_width 0
            set textpath ""
            set back_lr ""
            set magnify ""
            set homelabel ""
            set homesymbol x
            set logo ""
            set ltr_h ""
            set input ""
            my direction
            set prefix_frame ""
            set textpath ""
            if {[string length $ddd_list]} {
                upvar $ddd_list ddd
            } else {
                set ddd {}
            }
            if {[catch {
                    set daba [zirkon::zirkon new]
                } derr]} {
                tk_messageBox -icon error -title daba -message $derr -type ok
            }
            wm title . daba=$daba
            set startscreen 1
            set windows_once 1
            set frame_ahead ""
            set choices ""
            set elements {}
            set breadcrumbs {}
            if {[catch {set lang $::env(LANG)}]} {
                set lang en
            } else {
                set lang [regsub {[_\.].*$} $lang {}]
            }
            set lang [string tolower [regsub {[\-_0-9].*} $lang {}]]
            set suffix_is_wrapped 0
            set andratop $theframe
            my light
            bind $andratop <F1> [list [self] light]
            bind $andratop <F2> [list [self] cataract]
            bind $andratop <F3> [list [self] hlt 1]
            bind $andratop <F4> [list [self] hlt -1]
            bind $andratop <F5> [list [self] hltness]
            if {1} {
                bind $andratop <F6> [list [self] direction fa]
                bind $andratop <F7> [list [self] direction en]
                bind $andratop <F8> [list [self] newchar \b]
            }
            set btag_back [regsub -all {[\:]+} [self] {}]
            set btag_forward $btag_back
            append btag_forward _f
            if {[string equal [winfo class $andratop] Frame] && [$andratop cget -container]} {
                set name .
                append name $btag_back
                append name [regsub -all {\.} [string range $andratop 1 end] _]
                if {[winfo exists $name]} {
                    error "$name toplevel already exists"
                }
                set R [toplevel $name -use [winfo id $andratop] -bg {}]
                wm transient $R .
                set andratop $R
                set topframe $R
            } else {
                set R $andratop
                while 1 {
                    set topframe $R
                    if {[string equal Frame [winfo class $R]]} {
                        set R [winfo parent $R]
                    } else {
                        break
                    }
                }
                if {![string equal . $R] && ![string equal Toplevel [winfo class $R]]} {
                    error "no toplevel found for $andratop"
                }
            }
            if {$android} {
                wm attributes $R -fullscreen 1 -topmost 1
            }
            bind $R <Key-Escape> {sdltk withdraw}
            if {[winfo exists $andratop]} {
                set class [winfo class $andratop]
                if {[string equal . $andratop] || [regexp {(Toplevel|Tclkit|Undroid|T)} $class]} {
                    $andratop configure -bg {}
                    set tmp [regsub {^\.*} $andratop .]
                    append tmp .tx
                    if {![winfo exists $tmp]} {
                        set andratop [frame $tmp -bg {} -takefocus 0]
                    }
                } elseif {[string equal Frame $class]} {
                    pack forget $andratop
                    pack $andratop -fill both -expand 1
                }
            } else {
                error "unhandled case"
                set R [toplevel $andratop]
            }
            array set options {}
            set first_time 1
            set aftersuffix ""
            set back_lr ""
            set portrait false
            set portrait_old 2
            set istouch [string equal $::argv0 /assets/app/main.tcl]
            set nav {}
            set bcidx 0
            set uni_fg black
            set color_active_fg \#cefdb4
            set color_active_fg \#fbafca
            set color_fw_bg grey96
            set color_fw_bg \#afafaf
            set color_back_bg lavenderblush
            set color_prefix_bg \#ffd2c3
            set color_prefix_bg pink
            if {$hkf} {
                set color_d_bg white
                set color_back_fg \#007bff
            } else {
                set color_fw_bg white
            }
            if {$ddd_error} {
                set color_back_fg red
            }
            if {[string equal Frame [winfo class $andratop]]} {
                bind $R <FocusIn> [list pack $andratop -fill both -expand 1]
                set embedded 0
            } else {
                set embedded 1
            }
            if {[string equal Frame [winfo class $andratop]]} {
                set taipudex $andratop
                $taipudex configure -bg {}
            } else {
                set taipudex [frame $andratop.f -bg {} -takefocus 0]
            }
            set hiti [expr {$show_input ? 2 : 0}]
            set choices $taipudex.choices
            frame $taipudex.choices -bg {} -takefocus 0 -highlightthickness $hiti -highlightcolor $color_hi_co -highlightbackground $color_hi_bg
            pack $choices -side bottom -fill both -expand 1 -anchor s
            pack propagate $taipudex 0
            set affix [regsub -all : [self] {}]
            set xfont x
            append xfont $affix
            set topfont t
            append topfont $affix
            set lfont l
            append lfont $affix
            set splashfont s
            append splasfont $affix
            set fam {Noto Serif}
            set size -40
            font create $topfont -family $fam -size $size
            font create $xfont -family $fam -size $size
            set ellipsis .
            if {[lsearch -exact [font names] $splashfont]==-1} {
                font create $splashfont {*}[font configure $xfont]
            }
            set x \U01f426
            set twice [string repeat $x 2]
            set triple [string repeat $x 3]
            set v "T c l T k"
            append v \n $triple
            append v \n$twice \n $x
            append v \n woron \n widget
            set splash1 [label $choices.splash1 -text $v -justify center -bg skyblue -fg black -font $splashfont]
            set ::toast_asterisk 0
            set w [winfo width $andratop]
            if {$w == 1} {
                set w 30
            }
            set w [winfo width $R]
            option add *Dialog.msg.wrapLength [expr {int(.8*$w)}]
            set delta_info 0
            if {[string length $ddd]} {
                my datalist ddd
                if {$zr_size} {
                    set delta_info [$daba count]
                } else {
                    set delta_info "    "
                }
            }
            my light 0
            set lfont $topfont
            set textrow [frame $taipudex.textrow -bg {} -highlightthickness $hiti -highlightbackground $color_hi_bg -highlightcolor $color_hi_co -takefocus 0]
            lappend lhlt $textrow
            set logo [frame $textrow.l -bg {}]
            set delta [label $logo.d -font $topfont -text $delta_info -padx 3 -bg $color_home_bg -fg $color_back_fg -height 3]
            if {
                [catch {
                    set tmp [split $::env(LANG) .]
                    set mlang [lindex $tmp 0]
                }
                ]} {
                set mlang en
            }
            my direction $mlang
            set back_lr $textrow.back
            if {![winfo exists $back_lr]} {
                label $back_lr -text $erase -anchor $an -font $topfont -bg $color_back_bg -fg $color_back_fg
                lappend llp $back_lr
            }
            if {$hkf} {
                set magnify $textrow.magnify
                if {![winfo exists $magnify]} {
                    label $magnify -text " ≡ " -anchor $an -font $topfont -bg white -fg hotpink
                    bind $magnify <Button-1> [list [self] toggle]
                }
            }
            set homelabel [label $textrow.home -text $homesymbol -width 2 -padx 3 -anchor $ran -font $topfont -bg $color_home_bg -fg $color_back_fg]
            if {$dab} {
                bind ::woron::TB <<FingerDown>> [list [self] backstep %w]
            }
            bind ::woron::TB <Button-1> [list [self] backstep %w]
            foreach x $llp {
                my bind_back $x
            }
            pack $back_lr -side $rl -anchor $ran -fill both -expand 1
            if {$hkf} {
                pack $magnify -side $rl -anchor $ran -fill both
                bind $R <F11> [list [self] toggle]
                catch {bind $R <App> [list $magnify invoke]}
            }
            if {$show_input} {
                pack $homelabel $logo $delta -anchor $an -side $lr -fill y
            } else {
                pack $homelabel $logo $delta -anchor $an -side $lr -fill both
            }
            if {$dab} {
                bind $homelabel <<FingerDown>> [list [self] stx]
                bind $delta <<FingerDown>> [list [self] stx]
            }
            bind $homelabel <Button-1> [list [self] stx]
            bind $delta <Button-1> [list [self] stx]
            set frame_ahead [frame $textrow.ahead -bd 0 -bg {} -takefocus 0 -width 0]
            set textpath [frame $frame_ahead.t -bg {} -bd 0 -takefocus 0 -width 0]
            set suffix [label $textpath.suffix -font $topfont -text {} -bd 0 -bg \#eff0f0]
            lappend lls $suffix
            set aftersuffix $suffix
            append aftersuffix _as
            button $aftersuffix -font $topfont -text \u2398 -bg \#c2eeff -bd 0 -command [list [self] clip -takefocus 0]
            set prefix_frame [frame $textpath.px -bg {} -width 1]
            set iwi 5
            set input [entry $textpath.i -font $topfont -width 2 -justify center -borderwidth 0 -relief flat -insertwidth $iwi -insertborderwidth 0 -insertbackground lightskyblue -insertofftime 1400 -highlightthickness $hiti -highlightcolor $color_hi_co -highlightbackground $color_hi_bg -selectbackground $color_select_bg -selectforeground $color_select_fg -fg $color_d_fg -bg $color_d_bg]
            lappend lhlt $input
            my adjust_topfont [winfo width $R] 0 1
            focus $input
            my entry_bindings
            if {$dab} {
                bind $delta <<FingerDown>> [list [self] stx]
            }
            bind $delta <Button-1> [list [self] stx]
            pack $prefix_frame -side $lr -anchor $an -fill y
            if {$show_input} {
                pack $input -side $lr -anchor $an -ipadx 4 -fill y
            }
            pack $textpath -fill y -expand 1 -side $lr -anchor $an
            pack $frame_ahead -side $lr -anchor $an -fill y
            pack $textrow -side bottom -fill x -anchor s
            if {0} {
                pack $suffix $aftersuffix -side $lr -anchor $an -fill y -expand 1
                pack forget $suffix $aftersuffix
            }
            set tw [winfo width $R]
            set dd [pwd]
            set expand 1
            if {[string equal [winfo class $R] Toplevel]} {
                wm protocol $R WM_DELETE_WINDOW [list [self] cleanup]
            }
            bind $andratop <Configure> [list [self] hltness]
            bind $suffix <Configure> [list [self] suffix_wrap %W %w]
            bind $taipudex <Configure> [list [self] resized %w 0]
            bind $textrow <Configure> [list [self] adjust_topfont %w 0 1]
            my stx
            my fit
        }
        method set_options {pairs} {
            set opts [my option_defaults]
            set validkeys [my option_keys]
            foreach {k v} $pairs {
                if {[lsearch -exact $validkeys $k]<0} {
                    error [list "unknown option $k, use $validkeys"]
                }
                dict set opts $k $v
            }
            set show_input [dict get $opts -show_input]
            set zr_size [dict get $opts -zr_size]
            set hkf [dict get $opts -list_size]
            set hkf_ $hkf
            if {$hkf} {
            }
            unset opts
        }
        method hlt {i} {
            set current [[lindex $lhlt 0] cget -highlightthickness]
            incr current $i
            if {$current>0} {
                foreach w $lhlt {
                    $w configure -highlightthickness $current
                }
            }
        }
        method hltness {{w 0} {h 0}} {
            if {!$w} {
                set w [winfo width $andratop]
                set h [winfo height $andratop]
            }
            set new [expr {($w+$h)/600}]
            if {$new <1} {
                set new 1
            }
            if {$new != $hltness} {
                foreach w $lhlt {
                    $w configure -highlightthickness $new
                }
                set hltness $new
            }
        }
        method light {{reconfig 1}} {
            set color_d_fg royalblue
            set color_d_final_fg black
            set color_d_bg white
            set color_fw_fg black
            set color_fw_bg white
            set color_home_bg honeydew
            set color_home_bg \#4e312d ;#Espresso
            set color_back_bg linen
            set color_back_bg \#6f747b ;#Raven
            set color_back_bg \#fff8e7 ;#Cosmic Latte
            set color_back_bg \#7b002c ;#Bordeaux
            set color_prefix_bg pink
            set color_back_fg black
            if {$hkf} {
                set color_prefix_bg \#fafafa
            }
            set color_fill_fg black
            set color_fill_bg "light steel blue"
            set color_amount_fg tan4
            set color_amount_fg \#889dff
            set color_hi_bg silver
            set color_hi_co blue
            set color_select_fg black
            set color_select_bg white
            if {$reconfig} {
                my recolor
            }
        }
        method cataract {} {
            set color_d_fg white
            set color_d_final_fg skyblue
            set color_d_final_fg \#d1e1f2
            set color_d_final_fg \#fedcd3
            set color_d_bg \#1f2544
            set color_fw_bg \#81689d
            set color_fw_fg white
            set color_back_fg white
            set color_fill_fg lightgreen
            set color_fill_bg black
            set color_amount_fg \#cec4d9
            set color_hi_bg black
            set color_hi_co \#ffd0ec
            set color_select_fg white
            set color_select_bg black
            set color_prefix_bg maroon
            my recolor
        }
        method recolor {} {
            foreach w $ll0 {
                $w configure -bg $color_d_bg -fg $color_d_fg
            }
            foreach w $ll0c {
                $w configure -fg $color_d_final_fg
            }
            foreach w $lls {
                if {[string length $w]} {
                    $w configure -foreground $color_fw_fg -background $color_fw_bg
                }
            }
            foreach w $llp {
                $w configure -bg $color_prefix_bg -fg $color_back_fg
            }
            foreach w $lbc {
                $w configure -bg $color_d_bg -fg $color_d_fg
            }
            foreach w $lfill {
                $w configure -bg $color_fill_bg -fg $color_fill_fg
            }
            foreach w $llam {
                $w configure -bg $color_fw_bg -fg $color_amount_fg
            }
            foreach w [list $andratop $choices $textrow $input] {
                if {[string length $w]} {
                    $w configure -bg $color_hi_bg -highlightcolor $color_hi_co -highlightbackground $color_hi_bg
                }
            }
            if {[string length $input]} {
                $input configure -bg $color_d_bg -fg $color_d_fg -selectbackground $color_select_bg -selectforeground $color_select_fg
            }
            update idletasks
        }
        method delete_widget {w} {
            if {[winfo exists $w]} {
                bind $w <Configure> {}
                foreach x [winfo children $w] {
                    my delete_widget $x
                }
                destroy $w
            }
        }
        method cleanup {} {
            my delete_widget $R
            font delete $xfont $topfont
        }
        method forward {a} {
            set i 0
            scan $a %c i
            if {$i==0 || $i==13} {
                set key [my current_prefix]
                set k ""
                if {[catch {set word $vis_hash($k)}]} {
                    return
                }
                pack forget $choices
                set wc [winfo width $choices]
                set hc [winfo height $choices]
                my etx $key $key $wc $hc
            } else {
                my newchar $a
            }
            return -code break
        }
        method get_selection {} {
            set selected_value
        }
        method onselect_event {target} {
            set event_target $target
            return [self].selected
        }
        method message {title text} {
            if {[string equal [winfo class $R] Frame]} {
                tk_messageBox -message $text -title $title
            } else {
                tk_messageBox -message $text -title $title -parent $R
            }
        }
        method datalist {listname} {
            upvar $listname ll
            array unset vis_hash
            $daba reset
            set breadcrumbs {}
            set root [$daba init ll]
            my stx
        }
        method kv {res} {
            set breadcrumbs {}
            $daba hash_clear
            set local [list]
            foreach x $res {
                lassign $x k v
                $daba hash $k $v
                lappend local $x
            }
            set root [$daba init local]
        }
        method suffix_wrap {W w} {
            if {$suffix_is_wrapped} {
                return
            }
            set wx [winfo reqwidth $W]
            if {$w<$wx} {
                set w [expr {$w*0.8}]
                set z [expr {int($wx/$w)}]
                incr z
                set wn [expr {int($wx/$z)}]
                set min_wraplen [expr {int([winfo width $andratop]/3)}]
                if {$wn<$min_wraplen} {
                    set wn $min_wraplen
                }
                $W configure -wraplength $wn
                set suffix_is_wrapped 1
            } else {
                $W configure -wraplength 0
                set suffix_is_wrapped 0
            }
        }
        method enable_rotation {} {
            if {$sdk_version>=26} {
                bind $andratop <Configure> [list [self] resized]
                bind $R <<WillEnterForeground>> [list [self] resized 0]
            } else {
                after idle [list [self] lure callback]
            }
        }
        method info {title message outlist id {prefix {}}} {
            upvar $outlist res
            upvar $id z
            set header \U01f6c8
            append header $prefix
            append header [regsub -all " " $title \u00a0]
            lappend res $header [incr z]
            append header " " $message
            lappend res $header [incr z]
        }
        method test {title additional outlist id} {
            upvar $outlist res
            upvar $id z
            set common b
            append common [regsub -all " " $title \u00a0]
            append common -
            lappend res $common [incr z]
            append common [regsub -all " " $additional \u00a0]
            append common \u00b6\u261bexit
            lappend res $common [incr z]
        }
        method error {title message outlist id} {
            upvar $outlist res
            upvar $id z
            set header \u26d4
            append header [regsub -all " " $title \u00a0]
            lappend res $header [incr z]
            append header X
            append header [regsub -all " " $message \u00a0]
            append header \n\u261bexit
            lappend res $header [incr z]
        }
        method warning {title message outlist id} {
            upvar $outlist res
            upvar $id z
            set header \u26a0
            append header [regsub -all " " $title \u00a0]
            append header -
            lappend res $header [incr z]
            lappend res $header [incr z]
            append header [regsub -all " " $message \u00a0]
            lappend res $header [incr z]
        }
        method selected {value} {
            tk_messageBox -parent $R -title "dummy method selected" -message "selected value\n$value" -icon info
        }
        method geometry {{w {}} {h {}}} {
            if {[string length $w] && [string length $h]} {
                wm geometry $R [format %dx%d $w $h]
            } else {
                wm geometry $R
            }
        }
        method adjust_topfont {w h {refresh 0}} {
            if {$h==0} {
                set h [winfo height $R]
                set ff_h 0
            }
            if {$w} {
                if {[catch {set ff_h [font configure $topfont -size]}]} return
                set ff_h [expr {abs($ff_h)}]
                append w .
            } else {
                set ff_h 0
            }
            if {$textrow_width && $textrow_height} {
                if {$textrow_width == $w && $textrow_height == $h} {
                    return -code break
                }
            } else {
                set textrow_width $w
                set textrow_height $h
            }
            if {$h>0} {
                set aspect_ratio [expr {1.*$h/$w}]
            } else {
                set aspect_ratio 1.
            }
            set q [expr {1./(1.+$aspect_ratio)}]
            set base [expr {$h/5}]
            set lin [expr {[winfo height $R]/50.}]
            set n [expr {$lin+$base**$q}]
            set d [expr {round($n)}]
            if {$d != $ff_h} {
                font configure $topfont -size -$d
                if {[winfo exists $choices]} {
                    if {$refresh} {
                        my lure
                    }
                }
            }
        }
        method resized {w {init 0} args} {
            set w [winfo width $taipudex]
            set h [winfo height $taipudex]
            if {$w==1 && $h==1} {
                if {$init<1} {
                    incr init
                    my resized $init
                }
                return 0
            }
            set portrait [expr {$w<$h}]
            set change [expr {$portrait != $portrait_old}]
            if {$change} {
                set portrait_old $portrait
                if {$android} {
                    if {$sdk_version>=26} {
                        wm attributes $R -fullscreen 1 -topmost 1
                    } else {
                        wm withdraw $R
                        after idle {sdltk root 0 0}
                        after idle [list wm attributes $R -fullscreen 1 -topmost 1]
                        after idle [list wm deiconify $R]
                    }
                    my lure resized
                }
                option add *Dialog.msg.wrapLength [expr {int(.8*$w)}]
            }
            return $change
        }
        method direction {{lang {}}} {
            if {![string length $lang]} {
                if {[info exists ::env(LANG)]} {
                    set lang $::env(LANG)
                    set lang de
                }
            }
            if {![regexp {^[01]$} $lang]} {
                set lang [string tolower [regsub {[\-_0-9].*} $lang {}]]
                set ltr [expr {!([lsearch {0 ar ara fa per fas fars iw ur urd urdu ps pus pst pbu pbt wne pash yi arc syr sd snd lss sbn sind lasi khw khow} $lang]>-1)}]
            }
            if {$ltr} {
                set lr left
                set rl right
                set an w
                set ran e
                set erase \ \u27e8
                set homesymbol \u27ea
                set padx_dir {0 1}
            } else {
                set lr right
                set rl left
                set an e
                set ran w
                set erase "\u27e9 "
                set homesymbol \u27eb
                set padx_dir {1 0}
            }
            if {$ltr != $ltr_h} {
                set ltr_h $ltr
                if {[winfo exists $homelabel]} {
                    pack forget $homelabel
                    $homelabel configure -text $homesymbol
                    pack $homelabel -anchor $an -side $lr -fill y
                }
                if {[winfo exists $logo] && [winfo exists $frame_ahead]} {
                    pack forget $logo $frame_ahead
                    pack $logo $frame_ahead -anchor $an -side $lr -fill y
                }
                if {[winfo exists $textpath]} {
                    set pp [winfo children $textpath]
                    pack forget {*}$pp
                    foreach x [lreverse $pp] {
                        pack $x -side $lr -anchor $an -fill y
                    }
                }
                if {[winfo exists $back_lr]} {
                    pack forget $textrow
                    pack forget $back_lr
                    $back_lr configure -text $erase -anchor $an
                    pack $back_lr -side $rl -anchor $an -fill both -expand 1
                    pack $textrow -side bottom -fill x -anchor s
                    my bind_back $back_lr
                }
                if {[winfo exists $suffix]} {
                    pack forget $suffix
                }
                if {$ltr} {
                    bind $input <Key-Left> [list [self] backstep]
                    bind $input <Key-Right> {}
                } else {
                    bind $input <Key-Right> [list [self] backstep]
                    bind $input <Key-Left> {}
                }
            }
        }
        method ar {arrayname} {
            array get $arrayname
        }
        method var {varname} {
            my variable qiqi
            if {[catch {set res [set $varname]} err]} {
                if {[catch {set res [my varname $varname]} err]} {
                    return
                }
            }
            return $res
        }
        method parray {name} {
            parray $name
        }
        method set {name value} {
            set $name $value
        }
        method hash {array_name z} {
            array set $array_name $z
        }
        method entry_bindings {} {
            if {[string length $input]} {
                bind $input <Alt_L> [list [self] newchar \u2325]
                bind $input <Return> [list [self] selectfirst]
                bind $input <KP_Enter> [list [self] selectfirst]
                bind $input <Any-KeyPress> [list [self] newchar %A %k]
                bind $input <Key-Delete> [list [self] newchar "" %k]
                bind $input <Key-BackSpace> [list [self] backstep]
                bind $input <Key-Escape> {sdltk withdraw}
                if {$ltr} {
                    bind $input <Key-Left> [list [self] backstep]
                } else {
                    bind $input <Key-Right> [list [self] backstep]
                }
                bind $input <Key-Down> [list [self] first]
                bind $input <Key-Up> [list [self] last]
                bind $input <Next> [list [self] hilo 1]
                bind $input <Prior> [list [self] hilo 0]
                if {!$istouch} {
                    bind $input <Key-Escape> {sdltk withdraw}
                }
                bind $input <Key-Home> [list [self] stx]
                bind $input <Key-End> [list [self] stx]
                sdltk textinput off
            }
        }
        method selectfirst {} {
            my hide_suffix
            $input configure -fg black
            $input delete 0 end
            if {[catch {set word $vis_hash()}]} {
                return -code break
            }
            set x ""
            foreach {fin x} $word break
            if {!$fin} {
                return -code break
            }
            set wc [winfo width $choices]
            set hc [winfo height $choices]
            pack forget $choices
            $input delete 0 end
            update idletasks
            my append_suffix $fin $x
            set key [my current_prefix]
            set v [$daba pnr_get $key]
            my etx $key $v $wc $hc
                                #return -code break
        }
        method is_multiple {c} {
#puts is_multiple:c=$c
            set prefix_previous [my current_prefix]
            set last [array get vis_hash $c]
            if {$last == {}} {
                                        #. not contained
                                        return 0
#puts is_multiple:last=$last
                                         #. possible improvement, try letter with leading space
                                         #. should be applied after case toggle only
                                         #. f key pressed: try <f> <F> < f> < F>
                set flast [array get vis_hash " ."]
                if {$flast != {}} {
                    set first [array get vis_hash " "]
                    lassign $flast {} flast
                    lassign $first {} first
                    lassign $first f0 z0
                    lassign $flast f1 z1
                    set a [zirkon::lcp $z0 $z1]
                    if {[string equal $z0 $a]} {
                    }
                    my append_bc $a
                    set prefix [my current_prefix]
                    $daba spisok $prefix $hkf
                    catch {my lure "is_0" 0}
                    return 1
                } else {
                    return 1
                }
            } else {
                set last $vis_hash($c)
#puts is_multiple:last=$last
            }
            if {[info exists vis_hash($c.)]} {
                set first $vis_hash($c.)
#puts is_multiple:first=$first
                lassign $first is_cpl_first continuation_first
                lassign $last is_cpl_last continuation_last
                if {![string equal $continuation_first $continuation_last]} {
                    set prefix [my current_prefix]
                    set completion [zirkon::lcp $continuation_first $continuation_last]
#puts completion=$completion
                    my append_bc $completion
                    append prefix $completion
if {$first==$last} {
        error todo
        my etx
}
                    $daba set_head $prefix $prefix_previous $continuation_first $continuation_last
                    my append_suffix 0 ""
                    catch {my lure "is_1" 1}
                    return 1
                }
            }
            return 0
        }
        method newchar {singlechar {keycode 0} {recursive 0} {touch 0}} {
#puts newchar:singlechar=<$singlechar>,recursive=$recursive,touch=$touch
            if {[info exists ::suffix] && [winfo exists $::suffix]} {
                $suffix configure -text {} -wraplength 0
            }
            if {$recursive == 0} {
                if {$keycode != 0} {
                    $input delete 0 end
                }
            } else {
                $input delete 0 end
                $input insert end $singlechar
            }
            set fin 0
            my hide_suffix
            $input configure -fg red
            if {[string length $singlechar]} {
                if {$listmode} {
                    if {[catch {set multi [my is_multiple $singlechar]} err]} {
#puts err=$err
                                                                return
                    } else {
#puts multi=$multi
                                                                if {$multi} return
                    }
                }
                if {[catch {set word $vis_hash($singlechar)}]} {
                    if {!$recursive} {
                        $input configure -fg red
                        set toggled [string toupper $singlechar]
                        if {[string equal $toggled $singlechar]} {
                            set toggled [string tolower $singlechar]
                        }
                                                                if {$toggled == $singlechar} return
                        if {[catch {set word $vis_hash($toggled)}]} {
                            set tmp [array names vis_hash]
                            lappend tmp $singlechar
                            set where [lsearch -exact $tmp $singlechar]
                            incr where
                            if {$where < [llength $tmp]} {
                                set next [lindex $tmp $where]
                            } else {
                                set next [lindex $tmp 0]
                            }
                            $input delete 0 end
                            my newchar $next $keycode 1
                            return
                        }
                        if {![string equal $singlechar $toggled]} {
                            if {[catch {set word $vis_hash($toggled)}]} {
                                set tmp [array names vis_hash]
                                lappend tmp $singlechar
                                set tmp0 [lsort -dict $tmp]
                                set where [lsearch -exact $tmp0 $singlechar]
                                incr where
                                if {$where < [llength $tmp0]} {
                                    set next [lindex $tmp0 $where]
                                    $input delete 0 end
                                    $input insert end $next
                                    my newchar $next $keycode 1
                                    return
                                }
                                return
                            } else {
                                my newchar $toggled $keycode 1
                            }
                        } else {
                            $input selection range 0 end
                            return
                        }
                    }
                    return
                } else {
                    set key [my current_prefix]
                    $input configure -fg black
                    pack forget $input $suffix
                    if {![string length $key]} {
                        pack forget $prefix_frame
                    } else {
                        if {![winfo ismapped $prefix_frame]} {
                            pack $prefix_frame -side $lr -anchor $an -fill y
                        }
                    }
                    if {$show_input} {
                        pack $input -side $lr -anchor $an -ipadx 4 -fill y
                    }
                    set x ""
                    foreach {fin x} $word break
                    if {[string length $x]} {
                        if {$fin} {
                            set wc [winfo width $choices]
                            set hc [winfo height $choices]
                            my append_suffix $fin $x
                            set fullkey [my current_prefix]
                            append fullkey $x
                            set value [$daba pnr_get $fullkey]
                            my etx $fullkey $value $wc $hc
                            return
                        } else {
                            pack forget $input
                            my append_bc $x
                            if {[catch {
                                    my lure cc
                                } err]} {
                                tk_messageBox -type ok -message $err -title "newchar->lure cc"
                            }
                            my hide_suffix
                            $input delete 0 end
                            $input selection range 0 end
                        }
                    } else {
                        if {$fin} {
                            set wc [winfo width $choices]
                            set hc [winfo height $choices]
                            my append_suffix $fin $x
                            set v [$daba pnr_get $key]
                            my etx $key $v $wc $hc
                        } else {
                            tk_messageBox -title "unexpected condition" -message ups -type ok -parent $R
                        }
                    }
                    return
                }
            } else {
                if {$keycode == 40} {
                    my hide_suffix
                    if {$bc_valid} {
                        my append_suffix 1 ""
                    }
                } elseif {$keycode==76} {
                    my hide_suffix
                } elseif {$keycode==270} {
                    borg withdraw
                }
            }
        }
        method current_prefix {{x {}}} {
            return [join $breadcrumbs {}]
        }
        method set_prefix {x} {
            set mx [$daba search $x]
            my stx $mx
        }
        method hide_suffix {} {
            if {[string length $suffix]} {
                if {[info exists current_suffix] && [winfo exists $suffix]} {
                    $suffix configure -text {} -wraplength 0
                }
            }
            if {[string length $aftersuffix]} {
                if {[info exists aftersuffix]} {
                    pack forget $aftersuffix
                }
            }
        }
        method clear {parent} {
            foreach x [winfo children $parent] {
                set evbi [bind $x]
                foreach eb $evbi {
                    bind $x $eb {}
                }
                if {[winfo exists $x]} {
                    my clear $x
                    pack forget $x
                } else {
                    return -code break
                }
            }
        }
        method stx {{jump {}}} {
            if {[winfo exists $top_info]} {
                wm withdraw $top_info
            }
            if {![winfo exists $textrow]} {
                return
            }
            set hh {}
            set first_time 1
            my hide_suffix
            if {![string equal $prefix_frame ""]} {
                my clear $prefix_frame
            }
            set breadcrumbs {}
            if {[llength $jump]} {
                set root $jump
            }
            set bcidx 0
            my append_bc $root
            if {[winfo exists $suffix]} {
                $suffix configure -text "" -wraplength 0
                pack forget $aftersuffix
            }
            set focus_index -1
            if {[winfo exists $input]} {
                $input delete 0 end
            }
            my lure stx
            return
        }
        method clip {{value {}}} {
            clipboard clear
            set prefix [my current_prefix]
            append prefix $value
            set value [regsub {^.*://} $prefix https:// ]
            set prefix [regsub {\.$} $value {} ]
            set value [regsub {\n.*} $prefix {}]
            if {!$ltr} {
                append value \u200f
            }
            if {$dows} {
                clipboard append -type STRING $value
            } else {
                clipboard append -type UTF8_STRING $value
            }
        }
        method cesta {} {
            $daba cesta
        }
        method toggle {} {
            if {$hkf} {
                $magnify configure -text " \u2315 "
                set hkf_ $hkf
                set hkf 0
            } else {
                $magnify configure -text " ≡ "
                set hkf $hkf_
            }
            set prefix [my current_prefix]
            array unset vis_hash
            my stx
            my append_bc $prefix
            my append_suffix 0 ""
            my lure "" 0
        }
        method backstep {{w {}}} {
            event generate $choices <Unmap>
            event generate $textrow <Unmap>
            if {[winfo exists $top_info]} {
                wm withdraw $top_info
            }
            if {[winfo exists .vv]} {
                lower .vv
                destroy .vv
            }
            if {[string length $w]} {
                if {![winfo exists $w]} {
                    return
                }
                bind $w <<FingerDown>> {}
                bind $w <Button-1> {}
            }
            $input delete 0 end
            $suffix configure -text {} -wraplength 0
            my pop_nav
            pack forget $suffix $aftersuffix
            if {$bcidx==1 && [string length $root]} {
                return -code break
            }
            if {$bcidx >0} {
                set pp $prefix_frame.$bcidx
                pack forget [set pp]l [set pp]f
                set breadcrumbs [lrange $breadcrumbs 0 end-1]
                incr bcidx -1
                $input delete 0 end
                catch {
                    my lure back
                }
            }
            return -code break
        }
        method pos_increment {index d} {
            set l [llength $elements]
            set next $index
            incr next $d
            if {$next<0} {
                set next [expr {$l-1}]
            } elseif {$next>=$l} {
                set next 0
            }
            my actpos $next
        }
        method first {} {
            set nav {0}
            my actpos 0
        }
        method last {} {
            set endpos [llength $elements]
            set nav [list $endpos]
            incr endpos -1
            my actpos $endpos
        }
        method actpos {pos} {
            if {[llength $nav]} {
                lset nav end $pos
            } else {
                lappend nav $pos
            }
            set el [lindex $elements $pos]
            if {[winfo exists $el]} {
                focus $el
            }
        }
        method new_focus {w} {
            if {[winfo exists $w]} {
                focus $w
            }
        }
        method txhide {{start {}}} {
            variable packed
            if {![string length $start]} {
                set start $taipudex
                variable packed {}
                lappend packed $start
            }
            foreach x [winfo children $start] {
                if {![catch {set pfo [pack info $x]}]} {
                    if {![regexp textrow $x]} {
                        my txhide $x
                        lappend packed $x
                    }
                }
            }
            pack forget {*}$packed
        }
        method wrap_camelcase {txt} {
            set tmp [regsub -all {?:[^A-Z]([A-Z])} $txt {\n\1}]
        }
        method choices_forget {} {
            catch {pack forget $flexcol}
            pack forget $choices
        }
        method choices_pack {} {
            if {[winfo exists $flexcol]} {
                pack $flexcol -fill y -side right -anchor e
            }
            pack $choices -fill both -expand 1
        }
        method lure {{T {}} {break 1}} {
            set break 0
            set botton_frames {}
            my choices_forget
            variable prefixlen
            set prefix [my current_prefix]
            set disc_ ""
            set BG1 ""
            set FG1 black
            set BG black
            set hex 0
            set sub_correct 0
            set warn 0
            set prefixlen [string length $prefix]
            set key $portrait,.f,$prefix
            set keep_first [expr {![string length $prefix]}]
            set prefix_len [string length $prefix]
            set lp ""
            if {$prefix_len==0} {
                set lp_indent ""
            } elseif {$prefix_len<3} {
                set lp_indent " "
            } else {
                set lp_indent ""
            }
            if {![regexp \u2325 $prefix] && [regexp {[:\.\ _/]} $prefix]} {
                set tmp1 [regsub -all {(:|\.|\ |_/){1,}} $prefix \t]
                set tmp [regsub -all {(^[^A-Z]$|[A-Z]+)} $tmp1 \t&]
                set sp [split $tmp \t]
                set h [lrange $sp 0 end-1]
                set h [lsort -unique $h]
                if {[llength $h]>1} {
                    append lp \u2025 [lindex $sp end]
                } else {
                    set lp $prefix
                }
                if {[string length $lp] == 1} {
                    set lp [format %2s $lp]
                }
                set lp_indent ""
            } else {
                append lp $prefix
            }
            if {!$ltr} {
                set lp [string reverse $lp]
                append lp $lp_indent
            } else {
                append lp_indent $lp
                set lp $lp_indent
            }
            set startscreen [regexp {^\s*$} $prefix]
            set listmode 0
            set cpl [lsort -dictionary -index 1 [$daba spisok $prefix $hkf]]
            if {![string length $BG1]} {
                if {$hkf}  {
                    set ff [lsort -unique -index 0 $cpl]
                    set listmode [expr {[llength $ff]==1 && [lindex [lindex $ff 0] 0]==1}]
                    if {$listmode} {
                        set disc_ ""
                        set disco 0
                        set subw [winfo children $choices]
                        foreach subcol $subw {
                            foreach srow $subcol {
                                pack forget {*}[winfo children $srow] $srow
                            }
                            pack forget $subcol
                        }
                    }
                }
            }
            set element_count [llength $cpl]
            set longform 1
            set leader 0
            if {$element_count == 1} {
                if {$startscreen} {
                    set startscreen 0
                }
            } elseif {$element_count==0} {
                my backstep
            }
            set use_shortcut [expr {$startscreen}]
            catch {array unset vis_hash}
            set elements [list]
            set element_start -1
            set element_end $element_count
            set total 0
            set ldct {}
            set l_completion ""
            foreach c0 $cpl {
                foreach {final x} $c0 break
                set dct [lindex [split $x {}] 0]
                lappend ldct $dct
                if {$listmode} {
                    set first_key $dct
                    append first_key .
                    if {![info exists vis_hash($first_key)]} {
                        array set vis_hash [list $first_key [list 1 $x]]
                    }
                }
                array set vis_hash [list $dct $c0]
                incr total
            }
            if {$startscreen} {
                set ldctu [lsort -unique $ldct]
                if {[llength $ldctu] == 1} {
                    set startscreen 0
                }
            }
            if {$startscreen && $total==1} {
            }
            my clear $choices
            set colnum 1
            set xx [my column_wise $cpl]
            set row_max 0
            set tmp 1
            set ylen_before 0
            foreach y $xx {
                set ylen [llength $y]
                if {$ylen>=$row_max} {
                    set row_max $ylen
                    set col_max $tmp
                }
                incr tmp
            }
            set col_max [llength $xx]
            set wlen [winfo width $R]
            set wpx -1
            if {$wlen>1} {
                if {$col_max>1} {
                    set div [expr {1.5*$col_max}]
                    set wpx [expr {int($wlen/$div)}]
                }
            }
            set descent [lindex [font metrics $xfont] 3]
            set descent [expr {int($descent)}]
            set descent [expr {int($descent/2.)}]
            set bc_valid 0
            set lfin [list]
            set pat_tb {( +)$}
            set redux {}
            set reduced 0
            set label_wrappend {}
            set element_index -1
            set xx_len [llength $xx]
            set c_fg $color_d_fg
            set token_x [my current_prefix]
            set column_separator 0
            set column_separator 1
            set row_trim 0
            set suffix_widgets {}
            foreach col $xx {
                set flexcol $choices.c$colnum
                if {![winfo exists $flexcol]} {
                    set flexcol [frame $choices.c$colnum -bg {} -bd 0]
                }
                if {$longform && $column_separator} {
                    if {$colnum < $xx_len} {
                        set PADX {0 0}
                        if {0} {
                            set vsep $choices.vs$colnum
                            if {![winfo exists $vsep]} {
                                set vsep [frame $choices.vs$colnum -bg $color_back_bg -width 2]
                            }
                        } else {
                            set vsep ""
                            set PADX {0 0}
                        }
                    } else {
                        catch {destroy $vsep}
                        set vsep ""
                    }
                } else {
                    set vsep ""
                    set PADX {0 0}
                }
                set ylen [llength $col]
                if {$ylen==$ylen_before} {
                    if {![winfo exists $flexcol.fill]} {
                        label $flexcol.fill -text [lindex $deco [expr {int(rand()*[llength $deco])}]] -bg $color_fill_bg -fg $color_fill_fg -font $topfont -anchor $an
                        lappend lfill $flexcol.fill
                    }
                    set ylen_before -1
                    pack $flexcol.fill -side top -fill both
                } else {
                    set ylen_before $ylen
                }
                incr colnum
                set rownum 0
                set test 1
                set reduced 0
                set robyv {}
                foreach c0 $col {
                    incr element_index
                    set row_fill both
                    set c0 [lindex $cpl $c0]
                    set complete 0
                    set pele ""
                    lassign $c0 complete pele
                    set BG1 white
                    if {[string length $BG]} {
                        set color $prefix
                        append color $pele
                        if {$complete} {
                            set color [regsub {\u23ce$} $color {}]
                            set colorname [$daba pnr_get $color]
                            if {![string length $colorname]} {
                                lassign [winfo rgb . $color] r g b
                                set colorname \#[string range 0 1 [format %x $r]]
                                append colorname [string range 0 1 [format %x $g]]
                                append colorname [string range 0 1 [format %x $b]]
                            }
                            set BG1 $colorname
                        } else {
                            set color $prefix
                            append color $pele
                            set BG1 [$daba first_value $color]
                        }
                        if {[catch {winfo rgb . $BG1}]} {
                            set BG1 white
                        }
                        if {$complete} {
                            set FG1 [colors::contrasting $BG1 {#000000 gray white}]
                        } else {
                            set FG1 [colors::contrasting $BG1 {blue orange yellow}]
                        }
                    }
                    if {$pele == {}} {
                        set pele \u23ce
                    }
                    set token $token_x
                    append token $pele
                    regexp ^. $pele disc
                    set su_key [my current_prefix]
                    append su_key $pele
                    set obo [regsub ^. $pele {}]
                    set obo [regsub -all { } $obo {}]
                    set su $obo
                    if {$complete && $show_input} {
                        if {[regexp { } $su]} {
                            set su [regsub { .*} $su {}]
                            set reduced 1
                            lappend redux [list 1 $su]
                        } else {
                        }
                    } else {
                        set n_prefix $su_key
                        if {$element_count==2} {
                            lassign [lindex $cpl 0] n_f0 n_s0
                            lassign [lindex $cpl 1] n_f1 n_s1
                            if {$n_f0 && $n_f1} {
                                set n_0 $n_prefix
                                append n_0 $n_s0
                                set n_1 $n_prefix
                                append n_1 $n_s1
                                catch {
                                    if {[$daba pnr_get $n_0] == [$daba pnr_get $n_1]} {
                                        set s_end end
                                        if {$show_input} {
                                            if {[regexp { } $su]} {
                                                set su_end [string length $su]
                                                set su [regsub { [^ ]*} $su { }]
                                                set su_diff [expr {$su_end - [string length $su]}]
                                                append s_end -$su_diff
                                                set fin 1
                                                $daba pnr_set [string range $n_prefix 0 $s_end] [$daba pnr_get $n_0]
                                                set reduced 1
                                                lappend redux [list 1 $su]
                                            }
                                        }
                                    }
                                }
                            }
                        } ;#. if {$element_count==2}
                    }
                    if {!$reduced} {
                        lappend redux [list $complete $pele]
                    }
                    set xv $flexcol.r$rownum
                    if {![winfo exists $xv]} {
                        set row [frame $xv -takefocus 1 -bg {} -highlightthickness 1 -highlightcolor red -highlightbackground $color_d_bg]
                        lappend ::zz $row
                        lappend lhlt $row
                    } else {
                        set row $xv
                    }
                    if {$bcidx>0} {
                        if {$startscreen || !$longform} {
                            $row configure -highlightbackground $color_fw_bg -highlightcolor hotpink
                        } else {
                            $row configure -highlightbackground $color_d_bg -highlightcolor $color_hi_co
                        }
                    } else {
                        $row configure -highlightbackground $color_fw_bg -highlightcolor hotpink
                    }
                    incr rownum
                    set has_pic 0
                    if {[string length $lp]<3} {
                        set lpt "  "
                        append lpt $lp
                    } else {
                        set lpt $lp
                    }
                    set sps 0
                    set su [regsub {^ } $su \u2423]
                    if {$startscreen && ![string length $BG]} {
                        set sps 1
                    } else {
                        set lprefix $row.lp
                        if {![winfo exists $lprefix]} {
                            set lprefix [label $row.lp -cursor left_ptr -font $xfont -text $lpt -bg $color_prefix_bg -fg $color_back_fg]
                            lappend llp $lprefix
                        } else {
                            $lprefix configure -text $lpt
                        }
                        if {$warn} {
                            $lprefix configure -fg red
                        } else {
                            $lprefix configure -bg $color_prefix_bg
                            if {[string length $BG]} {
                                $lprefix configure -bg $BG
                            }
                        }
                        if {!$prefix_len} {
                            $lprefix configure -width 1 -text {}
                        }
                        set ficl [list [self] fipo_event $complete $pele %s]
                        if {$hkf} {
                            if {$complete} {
                                set color_back_fg black
                            } else {
                                set color_back_fg \#4040ee
                                set color_back_fg \#007bff
                            }
                            $lprefix configure -fg $color_back_fg
                            set ficl_form [format $ficl $lprefix]
                            if {$dab} {
                                bind $lprefix <<FingerDown>> $ficl_form
                            }
                            bind $lprefix <Button-1> $ficl_form
                        }
                    }
                    if {$complete} {
                        set c_fg $color_d_final_fg
                    } else {
                        set c_fg $color_d_fg
                    }
                    if {[string length $pele]} {
                        scan $disc %c other
                        set dd_name [format %x $other]
                        if {$warn} {set c_fg red}
                        set l0 $row.$dd_name
                        if {$leader} {
                            if {$ltr} {
                                set disc \u2e31$disc
                            } else {
                                append disc \u2e31
                            }
                        }
                        set disc [regsub { } $disc \u2324]
                        if {![winfo exists $l0]} {
                            set l0 [label $row.$dd_name -font $xfont -text $disc -justify center -bg $color_d_bg -fg $c_fg -takefocus 0 -width 2 -highlightthickness 0 -highlightbackground $color_back_bg -highlightcolor blue]
                            lappend ll0 $l0
                        } else {
                            $l0 configure -text $disc -bg $color_d_bg -fg $c_fg
                        }
                        set ficl [list [self] fipo_event $complete $pele %s]
                        set ficl_form [format $ficl $l0]
                        if {$dab} {
                            bind $l0 <<FingerDown>> $ficl_form
                        }
                        bind $l0 <Button-1> $ficl_form
                        if {$complete} {
                            lappend ll0c $l0
                        }
                    } else {
                        if {$ltr} {
                            set enter \u23ce
                        } else {
                            set enter \u2386
                        }
                        if {$leader} {
                            if {$ltr} {
                                set disc \u2e31$disc
                            } else {
                                append disc \u2e31
                            }
                        }
                        if {![winfo exists $row.lf]} {
                            set l0 [label $row.lf -height $sps -font $xfont -text $enter -width 2 -justify center -bg $color_d_bg -fg $c_fg -takefocus 0]
                        } else {
                            set l0 $row.lf
                            $l0 configure -text $enter -bg $color_d_bg -fg $c_fg
                        }
                        set bc_valid 1
                        set disc dummy
                        set dd_name x
                        set ficl [list [self] fipo_event $complete $pele %s]
                        set ficl_form [format $ficl $l0]
                        if {$dab} {
                            bind $l0 <<FingerDown>> $ficl_form
                        }
                        bind $l0 <Button-1> $ficl_form
                    }
                    lappend robyv $l0
                    lappend elements $l0
                    set lname $row
                    append lname .textpath$dd_name
                    set arabic ""
                    if {!$complete} {
                        if {$zr_size} {
                            set successor_count [$daba subcounter $su_key]
                            if {$successor_count==1} {
                                set final 1
                                set complete 1
                                set successor_count xx
                            }
                        }
                    }
                    if {$complete} {
                        if {!$startscreen} {
                            set kk $prefix
                            append kk $pele
                            foreach  {{} exval} [array get pnr [my xx_escape $kk]] break
                            if {[info exists exval]} {
                                lappend lfin [list $exval $lname]
                            }
                        }
                    } else {
                        if {$zr_size} {
                            if {!$complete && $successor_count==1} {
                                tk_messageBox -icon error -message "Incomplete & 1 successor" -type ok
                            }
                            if {$sub_correct} {
                                set successor_count [expr {$successor_count/2}]
                                if {$successor_count<=1} {
                                    set successor_count ""
                                }
                            }
                            if {!$ltr} {
                                append arabic -
                            }
                            set subscripted 1
                            if {$subscripted} {
                                foreach x [split $successor_count {}] {
                                    set y \\u208
                                    append y $x
                                    append arabic [subst -nocommands -novariables $y]
                                }
                            } else {
                                set arabic $successor_count
                            }
                            if {$ltr} {
                                append arabic -
                            }
                        } else {
                            set successor_count 0
                        }
                    }
                    set l_completion $row.con$dd_name
                    if {![winfo exists $l_completion]} {
                        set l_completion [label $row.con$dd_name -font $xfont -bg $color_fw_bg -fg $c_fg -wraplength -1 -takefocus 0]
                        lappend lls $l_completion
                    } else {
                        $l_completion configure -bg $color_fw_bg -fg $c_fg
                    }
                    if {$startscreen} {
                        pack $l0 -side $lr -anchor $an -fill both -expand 1
                        set wpx -1
                    } else {
                        set width [string length $su]
                        set su [regsub -all { } $su \u2423]
                        if {$longform} {
                            append su §
                            $l_completion configure -text $su -bg $color_fw_bg -justify $lr -anchor $an
                            set nl_count [regexp -all \\n $su]
                        } else {
                            $l_completion configure -text .. -bg white -justify $lr -anchor $an
                            set nl_count 0
                        }
                        if {$hkf} {
                            if {$complete} {
                                $l_completion configure -bg white
                            } else {
                                $l_completion configure -bg $color_fw_bg
                            }
                            lappend elements $l_completion
                        }
                        if {[string length $su]} {
                            lappend suffix_widgets [list $l_completion $su $l0 $lprefix]
                        }
                        set c_fg [$l0 cget -fg]
                        if {$listmode} {
                            pack forget $lprefix $l0
                            set listitem $lpt
                            append listitem $pele
                            set nowrap [regsub -all {^\s} $listitem \u2423]
                            set dica [lindex [split $pele {}] 0]
                            if {![string equal $dica $disc_]} {
                                incr disco
                                set disc_ $dica
                            }
                            set bgx [lindex $listcolors [expr {$disco%6}]]
                            $row configure -bg [$l_completion cget -bg]
                            pack $l_completion -side $lr -fill y
                            pack $row -fill both -expand 1
                            set ficl_form [format $ficl $l_completion]
                            if {$dab} {
                                bind $l_completion <<FingerDown>> $ficl_form
                                bind $row <<FingerDown>> $ficl_form
                            }
                            bind $l_completion <Button-1> $ficl_form
                            bind $row <Button-1> $ficl_form
                        } else {
                            pack $l_completion -side $lr -anchor $an -fill both -expand 1
                            set ficl_form [format $ficl $l_completion]
                            if {$dab} {
                                bind $l_completion <<FingerDown>> $ficl_form
                            }
                            bind $l_completion <Button-1> $ficl_form
                            set l_amount $row.a
                            if {$longform} {
                                if {[string length $arabic]} {
                                    if {![winfo exists $l_amount]} {
                                        set l_amount [label $l_amount -font $xfont -bg $color_fw_bg -fg $color_amount_fg]
                                        lappend llam $l_amount
                                    }
                                    if {$ltr} {
                                        $l_amount configure -text \u2264$arabic -justify $rl -bg $BG1 -fg $FG1
                                    } else {
                                        $l_amount configure -text $arabic\u2264 -justify $rl -bg $BG1 -fg $FG1
                                    }
                                    pack $l_amount -side $rl -anchor $ran -fill y
                                    set tmp [format $ficl $l_amount]
                                    if {$dab} {
                                        bind $l_amount <<FingerDown>> $tmp
                                    }
                                    bind $l_amount <Button-1> $tmp
                                }
                            } else {
                                if {[winfo exists $l_amount]} {
                                    pack forget $l_amount
                                }
                            }
                        }
                    }
                    pack $row -side top -fill $row_fill -expand 1
                    set row_trim 0
                    my arrow_bind $l0 $element_index $complete $pele
                    if {1 && [string length $BG1]} {
                        $row configure -bg $BG1
                        $l_completion configure -bg $BG1 -fg $FG1
                        set su [regsub -all -- { } $pele \u2423]
                        if {$col_max > 1} {
                            if {[regexp \# $su]} {
                                #. space not at distinctive positions in rgb code
                                set color_multiline [regsub -all \u2423 $su \n]
                                set su $color_multiline
                            } else {
                                if {[regexp {[A-Z]} $su]} {
                                    set cc [regsub -all {([a-z])([A-Z])} $su \\1\n\\2]
                                    set su $cc
                                } else {
                                    set color_multiline [regsub -all \u2423 $su \u2423\n]
                                    set su $color_multiline
                                }
                            }
                        }
                        $l_completion configure -text $su
                        $l0 configure -bg $BG1 -fg $FG1
                    }
                } ;#.foreach c0 $col {}
                set column_last_frame $flexcol.f$colnum
                if {![winfo exists $column_last_frame]} {
                    frame $column_last_frame -height 2 -bd 0 -bg magenta
                } else {
                    pack $column_last_frame -fill x
                    lappend bottom_frames $column_last_frame
                }
                pack $flexcol -side $lr -anchor $an -fill both -expand 1
                if {[winfo exists $vsep]} {
                    pack $vsep -side $lr -anchor $an -fill y
                }
            } ;#. foreach col $xx {}
            set flexcol $choices.vertical
            if {![winfo exists $flexcol]} {
                frame $flexcol -bg magenta -width 2
            } else {
                $flexcol configure -width 2 -bg magenta
            }
            pack $flexcol -side $rl -anchor $ran -fill y -expand 0
            if {![winfo exists $textrow]} {
                return
            }
            pack $textrow -side bottom -fill x -expand 0
            my choices_pack
            if {$reduced} {
                set options($prefix) $redux
            }
            sdltk touchtranslate 0
            set mupho [list]
            set prev ""
            foreach lact [lsort -ascii $lfin] {
                foreach {pnum lname} $lact {break}
                if {[string equal $prev $pnum]} {
                    lappend mupho $pnum
                }
                set prev $pnum
            }
            set lfn 0
            foreach p [lrange [lsort -unique $mupho] 0 9] {
                set lnames [lsearch -exact -index 0 -all $lfin $p]
                foreach muidx $lnames {
                    set mulabel [lindex $lfin $muidx]
                    set mulabel [lindex $mulabel 1]
                    $mulabel configure -text [subst \\u208[format %x $lfn]] -fg black
                }
                incr lfn
            }
            if {$startscreen} {
                set icol 0
                set cmax 0
                foreach col $xx {
                    incr icol
                    set max [llength $col]
                    if {$max>$cmax} {
                        set cmax $max
                    }
                }
                set aw [winfo width $andratop]
                set cell_width [expr {int($aw/$icol)}]
                if {$cell_width == 0} {
                    set cell_width [expr {int([winfo width $andratop]/$icol)}]
                    update idletasks
                }
                set ah [winfo height $andratop]
                if {$cmax==0} {
                    $input insert end \u2205
                    set cmax 1
                }
                set cell_height [expr {int($ah/$cmax)}]
                if {$cell_height<$cell_width} {
                    set cell_width $cell_height
                }
            }
            my fit
            my repack $startscreen
            wm maxsize $R 0 0
            if {$focus_index >-1} {
                if {$focus_index >= [llength $elements]} {
                    set el [lindex $elements end]
                } else {
                    set el [lindex $elements $focus_index]
                }
                set focus_index -1
                if {[winfo exists $el]} {
                    after idle [list ::corolatus::xfocus $el]
                }
            } else {
                set focus_index -1
                after idle [list ::corolatus::xfocus $input]
            }
            set this [self]
            foreach x $llp {
                my bind_back $x
            }
            if {[string equal $T back]} {
                pack $back_lr -fill both -expand 1
            }
            if {![winfo ismapped $choices]} {
                my choices_pack
            }
            if {![winfo ismapped $taipudex]} {
                pack $taipudex -fill both -expand 1
            }
        }
        method delayed_exit {} {
            pack forget {*}[winfo children $choices]
            pack forget {*}[winfo children $taipudex]
            pack $splash1 $choices $taipudex -fill both -expand 1
            after 3000 {exit}
        }
        method arrow_bind {lbl element_index complete pele} {
            bind $lbl <Key-Up> [list [self] pos_increment $element_index -1]
            bind $lbl <Key-Down> [list [self] pos_increment $element_index 1]
            if {$ltr} {
                bind $lbl <Key-Left> [list [self] backstep $lbl]
                if {!$complete} {
                    bind $lbl <Key-Right> [list [self] push_nav $element_index]
                    bind $lbl <Key-Right> +[list [self] key_event $complete $pele $lbl 1]
                } else {
                    bind $lbl <Key-Right> [list [self] key_event $complete $pele $lbl 1]
                }
            } else {
                bind $lbl <Key-Right> [list [self] backstep $lbl]
                if {!$complete} {
                    bind $lbl <Key-Left> [list [self] push_nav $element_index]
                    bind $lbl <Key-Left> +[list [self] key_event $complete $pele $lbl 1]
                } else {
                    bind $lbl <Key-Left> [list [self] key_event $complete $pele $lbl 1]
                }
            }
            bind $lbl <Key-Home> [list [self] stx]
            bind $lbl <Next> [list [self] hilo 1 $element_index]
            bind $lbl <Prior> [list [self] hilo 0 $element_index]
            bind $lbl <Any-Key> [list [self] forward %A]
            bind $lbl <Key-space> [list [self] fipo_event $complete $pele $lbl]
            bind $lbl <Key-BackSpace> [list [self] backstep $lbl]
            bind $lbl <Key-Escape> [list ::corolatus::xfocus $input]
        }
        method bind_back {x} {
            if {$dab} {
                bind $x <<FingerDown>> [list [self] backstep $x]
            }
            bind $x <Button-1> [list [self] backstep $x]
        }
        method setvar {x} {
            variable [set x]
            catch {unset [set x]}
            set [set x] 1
        }
        method push_nav {index} {
            lappend nav $index
            my hilo 1
        }
        method pop_nav {} {
            set x [lindex $nav end]
            set nav [lrange $nav 0 end-1]
            set l [llength $nav]
            if {$l>0} {
                set focus_index [lindex $nav end]
            } else {
                set focus_index -1
            }
        }
        method hilo {up {current -1}} {
            if {$current<0} {
                set element_start 0
                set element_end [llength $elements]
                if {$up} {
                    set element_start -1
                    set current 0
                } else {
                    set current $element_end
                }
                set mid [expr {$element_end/2}]
            } else {
                if {$up} {
                    set dist [expr {$element_end - $current}]
                    set mid [expr {$dist/2}]
                    incr mid $current
                    set element_start $current
                } else {
                    set mid [expr {$current - $element_start}]
                    set mid [expr {$mid/2}]
                    set mid [expr {$current - $mid}]
                    set element_end $current
                }
            }
            set eltab [lindex $elements $mid]
            if {[winfo exists $eltab]} {
                if {![catch {focus $eltab}]} {
                    after idle [list [self] actpos $mid]
                } else {
                }
            }
            if {$mid >=0 && $mid == $current} {
                my hilo -1
                return
            }
        }
        method append_suffix {final completion} {
            if {$final} {
                if {$ltr} {
                    $input icursor end
                } else {
                    $input icursor 0
                }
                after idle [list $input selection range 0 end]
            }
            if {$show_input} {
                set current_suffix [regsub ^. $completion {}]
                if {[string length $completion]} {
                    regexp {^.} $completion dd
                    $input delete 0 end
                    $input insert end $dd
                    $input selection range 0 end
                }
            } else {
                set current_suffix $completion
            }
            set suffix_is_wrapped 0
            set fullkey [my current_prefix]
            append fullkey $completion
            if {$final} {
                $aftersuffix configure -command [list [self] clip $completion]
                if {[string length $event_target] && [winfo exists $event_target]} {
                    set selected_value [my current_prefix]
                    append selected_value $completion
                }
            } else {
                set selected_value ""
                pack forget $aftersuffix
            }
            if {!$ltr} {
                if {$portrait} {
                    set mp [split $current_suffix { }]
                    set mplen [llength $mp]
                    if {$mplen} {
                        set first 1
                        set kk [list]
                        foreach el $mp {
                            if {$first} {
                                lappend kk $el
                                set first 0
                            } else {
                                lappend kk \ \ $el
                            }
                        }
                        set tmp [lreverse $kk]
                        set current_suffix [join $tmp \n]
                    }
                }
                set current_suffix [string reverse $current_suffix]
            } else {
                set mp [split $current_suffix { }]
                set mplen [llength $mp]
                if {$portrait} {
                    if {$mplen} {
                        set first 1
                        set kk [list]
                        foreach el $mp {
                            if {$first} {
                                lappend kk $el
                                set first 0
                            } else {
                                lappend kk \ \ $el
                            }
                        }
                        set current_suffix [join $kk \n]
                    }
                }
            }
            $suffix configure -text $current_suffix -justify $lr
            pack $suffix -side $lr -fill y -expand 1 -anchor $an
            if {$final} {
                pack $aftersuffix -side $lr -fill y -expand 1 -anchor $an
                set cbv [my current_prefix]
                append cbv $completion
            }
            if {$ltr} {
                $input icursor end
            } else {
                $input icursor 0
            }
        }
        method fontfam {name} {
            wm title $R $name-$R
            if {[lsearch [font families] $name]==-1} {
                tk_messageBox -parent $R -type ok -icon error -message "font $name does not exist"
                return
            }
            font configure $xfont -family $name
            font configure $topfont -family $name
            font configure $lfont -family $name
            raise [winfo toplevel $R]
        }
        method etx_hide {top} {
            destroy $top
            return
            focus $choices
            return
            pack $choices -fill both -expand 1
            pack propagate $taipudex 0
            if {[winfo exists $refocus]} {
                after idle [list focus $refocus]
            }
        }
        method etx {k v {width_available 0} {height_available 0}} {
            set refocus [focus -lastfor $R]
            if {[regexp {^\u23ea[\u2080-\u2089]+} $k]} {
                set k [regsub {^\u23ea.} $k {}]
                regsub -all \u00a0 $k " " k
                if {[catch {
                        set v [$daba pnr_get $k]
                    }]} {
                    set v black
                }
            }
            set top_info $R[self]etx
            if {$height_available<$width_available} {set width_available $height_available}
            set maxw [expr {int(0.5*$width_available)}]
            set margin [expr {$width_available/5}]
            set wchar_width [font measure $topfont 0]
            if {![winfo exists $top_info]} {
                toplevel $top_info -width $maxw -height $maxw
                wm overrideredirect $top_info 1
                wm withdraw $top_info
            }
            wm geometry $top_info [format %dx%d+%d+%d $maxw $maxw [expr {[winfo x $R]+$margin}] [expr {[winfo y $R]+$margin}]]
            after idle [wm deiconify $top_info]
            set tltext $top_info.ltext
            if {![winfo exists $tltext]} {
                label $tltext -bg white -takefocus 1 -font $lfont -highlightcolor white -highlightthickness 2 -highlightbackground yellow
                bind $tltext <Button-1> [list [self] etx_hide $top_info]
                bind $tltext <Any-Key> +[list [self] etx_hide $top_info]
                bind $tltext <FocusOut> +[list [self] etx_hide $top_info]
                bind $tltext <Leave> +[list [self] etx_hide $top_info]
            }
            $tltext configure -font $topfont -text $v
            if {[catch {
                    set colorname [$daba pnr_get [regsub {\u23ce$} $k {}]]
                    if {![string length $colorname]} {
                        set colorname [$daba pnr_get [regsub -all {\u2423} $k { }]]
                    }
                    set fg_contrast [colors::contrasting $colorname {white black}]
                    $tltext configure -text $colorname -bg $colorname -fg $fg_contrast -highlightbackground $fg_contrast -highlightcolor $fg_contrast
                    if {0} {
                        if {[regexp {^#} $colorname]} {
                            $tltext configure -text $colorname -bg $colorname -fg $fg_contrast -highlightbackground $fg_contrast -highlightcolor $fg_contrast
                        } else {
                            $tltext configure -bg $colorname -fg [colors::contrasting $colorname {white black}]
                        }
                    }
                } err]} {
                set bg white
                set fg_contrast black
                $tltext configure -bg white -fg black -highlightbackground black -highlightcolor black
            }
            pack $tltext -fill both -expand 1
        }
        method column_wise {inlist} {
            set n [llength $inlist]
            set per_column [my oddlist $n]
            set k 0
            set sum -1
            set res [list]
            foreach z $per_column {
                set sub [list]
                while {$k<$z} {
                    lappend sub [incr sum]
                    incr k
                }
                set k 0
                lappend res $sub
            }
            set res
        }
        method oddlist {{z 11}} {
            set w [winfo width $R]
            set h [winfo height $R]
            if {[winfo exists $textrow]} {
                set h [expr {$h - [winfo height $textrow]}]
            }
            if {$h>0} {
                set aspect_ratio [expr {1.*$h/$w}]
            } else {
                set aspect_ratio 1.
            }
            set min_in_col [expr {10*$aspect_ratio}]
            set q [expr {1./(1.+$aspect_ratio)}]
            set base [expr {$z-$min_in_col}]
            if {$base<0} {set base 0}
            set n [expr {1+round($base**$q +0.4)}]
            set rows_per_column [expr {$z/$n}]
            set prod [expr {$n*$rows_per_column}]
            set rest [expr {$z-$prod}]
            set res [list {*}[string repeat \ $rows_per_column $n]]
            if {$rest} {
                set max [expr {$rows_per_column+1}]
                set pos 0
                lset res $pos $max
                incr rest -1
                incr n -2
                set add 1
                incr pos
                while {$rest} {
                    incr pos $add
                    lset res $pos $max
                    set add [expr {$rest<$n ? 2 : 1}]
                    incr n -$add
                    incr rest -1
                }
            }
            return $res
        }
        method xx_escape i {
            return [string map {* \\* ? \\? \\ \\\\ \[ \\\[ \] \\\] ( . ) .} $i]
        }
        method fit {} {
            if {![winfo exists $choices]} {return}
            set ffmax [expr {int([winfo width $choices]/6)}]
            if {[catch {set ffint [font configure $xfont -size]}]} return
            set aw [winfo width $choices]
            set ah [winfo height $choices]
            if {$aw==1 || $ah==1} {
                if {$::corolatus::android} {
                    wm attributes . -fullscreen 1
                    return
                }
                pack $choices $taipudex -side top -fill both -expand 1
                set aw [winfo width $taipudex]
                set ah [winfo height $taipudex]
            }
            set ff [expr {double(abs($ffint))}]
            set rw [winfo reqwidth $choices]
            set rh [winfo reqheight $choices]
            set fak_w [expr {double($aw)/double($rw)}]
            set fak_h [expr {double($ah)/double($rh)}]
            if {$fak_w > $fak_h} {
                set fak_w $fak_h
            }
            set next [expr {int($ff*$fak_w)}]
            if {$next > $ffmax} {
                set next $ffmax
            } elseif {$next ==$ffint} {
                incr next 2
            } elseif {$next<10} {
                set next 10
            }
            font configure $xfont -size [expr {-$next}]
            update idletasks
            set vertical_unfit 0
            foreach x $bottom_frames {
                if {![winfo ismapped $x]} {
                    set vertical_unfit 1
                    break
                }
            }
            if {![winfo ismapped $flexcol] || $vertical_unfit} {
                incr flex_check
                if {$flex_check<3} {
                    set next [expr {int(0.9*$next)}]
                    font configure $xfont -size [expr {-$next}]
                    my fit
                    return
                }
            }
            set flex_check 0
            if {[string equal Frame [winfo class $andratop]]} {
                pack $andratop -fill both -expand 1
            }
            set y [winfo height $andratop]
            set yc [winfo reqheight $choices]
            set yt [winfo reqheight $textrow]
            set sum [expr {$yc + $yt}]
            set x [winfo width $andratop]
            set xc [winfo reqwidth $choices]
            if {0} {
                if {$sum>=$y || $xc > $x} {
                    pack forget $choices
                    set cf [$sf contentframe]
                    $sf configure -bg silver -width [winfo width $choices] -height [expr {$y -$yt}]
                    $cf configure -bg cyan
                    $sa configure -bg yellow
                    $cf configure -width [winfo reqwidth $choices] -height $yc
                    $sa configure -autohidescrollbars 0
                    pack $cf -fill both -expand 1
                    $sf autofilly 1
                    pack $choices -in $cf -fill both
                    pack $sa
                }
            }
        }
        method fipo_event {final {completion {}} {w {}} {arrow {0}}} {
            if {![winfo ismapped $w]} {
                return -code break
            }
            set wc [winfo width $choices]
            set hc [winfo height $choices]
            set completion [regsub -all -- {\u2423} $completion " "]
            if {$final} {
                set cc ""
                $input delete 0 end
                set fullkey [my current_prefix]
                my append_suffix $final $completion
                append fullkey $completion
                set value [$daba pnr_get $fullkey]
                my etx $fullkey $value $wc $hc
                if {$arrow} {break}
                return -code break
                #. before above break: sometimes label-text not visible
                #. return -code break
            } else {
                $suffix configure -text ""
                pack forget $suffix
                $input delete 0 end
                my append_bc $completion
                if {$arrow} {
                    my hilo -1
                }
                return [my lure touched]
            }
            return -code break
        }
        method key_event {final {completion {}} {w {}} {arrow 0}} {
            set suffix_is_wrapped 0
            if {$show_input} {
                $input delete 0 end
                set cc ""
                regexp -- ^. $completion cc
                $input insert end $cc
                $input selection range 0 end
            } else {
                set cc $completion
            }
            if {$final} {
                my append_suffix $final $completion
                set fullkey [my current_prefix]
                append fullkey $completion
                set value [$daba pnr_get $fullkey]
                set wc [winfo width $choices]
                set hc [winfo height $choices]
                my etx $fullkey $value $wc $hc
            } else {
                my newchar $cc 0 0 1
                if {$arrow} {
                    my hilo -1
                }
            }
        }
        method back {pos} {
            while {$bcidx > $pos} {
                set pp $prefix_frame.$bcidx
                pack forget [set pp]l [set pp]f
                incr bcidx -1
            }
            $input delete 0 end
            $aftersuffix configure -text ""
            pack forget $suffix $aftersuffix
            incr pos -1
            set breadcrumbs [lrange $breadcrumbs 0 $pos]
            my lure [my current_prefix]
        }
        method append_bc {infix} {
            set previous $bcidx
            lappend breadcrumbs $infix
            incr bcidx
            if {!$ltr} {
                set pp [split $infix {}]
                set infix [join [lreverse $pp] {}]
            }
            if {![winfo exists $prefix_frame]} {return}
            set w $prefix_frame.$bcidx
            set w0 $w
            append w0 l
            if {![string length $infix]} {return}
            if {![winfo exists $w0]} {
                label $w0 -font $topfont -text $infix -bg \#eff0f0
                lappend lbc $w0
            } else {
                $w0 configure -text $infix
            }
            if {$dab} {
                bind $w0 <<FingerDown>> [list [self] back $bcidx]
            }
            bind $w0 <Button-1> [list [self] back $bcidx]
            set w1 $w
            append w1 f
            if {![winfo exists $w1]} {
                frame $w1 -width 1 -bg silver
            }
            pack $w0 $w1 -side $lr -anchor $an -fill y
            if {[winfo exists $input]} {
                pack $prefix_frame -side $lr -anchor $an -fill y
            } else {
                pack $prefix_frame -side $lr -anchor $an -fill y
            }
            pack $frame_ahead -side $lr -anchor $an -fill y
            pack $textrow -side bottom -fill x -anchor $an
            if {$show_input} {
                $input selection range 0 end
                pack $input -side $lr -anchor $an -ipadx 4 -fill y
            }
        }
        method vis_filter {initial} {
            set res {}
            set srch [array startsearch vis_hash]
            while {[array anymore vis_hash $srch]} {
                set k [array nextelement vis_hash $srch]
                if {[regexp ^$initial $k]} {
                    lappend res $k $vis_hash($k)
                }
            }
            array donesearch vis_hash $srch
            array unset vis_hash
        }
        method repack {{startscreen 0}} {
            pack $choices -side top -fill both -expand 1
            pack $taipudex -fill both -expand 1
            pack propagate $taipudex 0
            update idletasks
            if {$startscreen} {
                if {$windows_once} {
                    if {$dows} {
                        set windows_once 0
                        set h [winfo reqheight $choices]
                        set gg [wm geometry $R]
                        scan $gg "%dx%d" x H
                        if {$H<$h} {
                            if {[catch {
                                    wm geometry $R [format %dx%d $x $h]
                                } err]} {}
                        }
                    }
                }
            }
        }
    }
    proc listOptions args {
        return {}
    }
    proc xfocus {w} {
        return
        if {[winfo exists $w]} {
            if {[catch {focus $w} err]} {
                tk_messageBox -parent . -message $err
            }
        }
    }
}
namespace eval colors {
    proc luminance rgb {
        if {[regexp -- {^#} $rgb]} {
            if {[string length $rgb] == 13} {
                regexp -- ^.(..)..(..)..(..) $rgb {} r g b
            } else {
                regexp -- ^.(..)(..)(..) $rgb {} r g b
            }
            scan $r %x rt
            scan $g %x gn
            scan $b %x bl
        } else {
            set rgb [winfo rgb . $rgb]
            lassign $rgb r g b
            set rt [expr {$r/255.}]
            set gn [expr {$g/255.}]
            set bl [expr {$b/255.}]
        }
        expr {($rt*0.2126 + $gn*0.7152 + $bl*0.0722)}
    }
    proc contrasting {color {colors {black gray50 white}}} {
        set y0 [colors::luminance $color]
        set best ""
        set diff 0
        foreach c $colors {
            set y [colors::luminance $c]
            set d [expr {abs($y - $y0)}]
            if {$diff < $d} {
                set best $c
                set diff $d
            }
        }
        return $best
    }
}
set COLORS { snow {ghost white} {white smoke} gainsboro {floral white}
    {old lace} linen {antique white} {papaya whip} {blanched almond}
    bisque {peach puff} {navajo white} navajowhite navajowhite2 navajowhite3 moccasin cornsilk ivory
    {lemon chiffon} seashell honeydew {mint cream} azure {alice blue}
    lavender {lavender blush} {misty rose} white black {dark slate gray}
    {dim gray} {slate gray} {light slate gray} gray {light grey}
    {midnight blue} navy {cornflower blue} {dark slate blue} {slate blue}
    {medium slate blue} {light slate blue} {medium blue} {royal blue}
    blue {dodger blue} {deep sky blue} {sky blue} {light sky blue}
    {steel blue} {light steel blue} {light blue} {powder blue}
    {pale turquoise} {dark turquoise} {medium turquoise} turquoise
    cyan {light cyan} {cadet blue} {medium aquamarine} aquamarine
    {dark green} {dark olive green} {dark sea green} {sea green}
    {medium sea green} {light sea green} {pale green} {spring green}
    {lawn green} green chartreuse {medium spring green} {green yellow}
    {lime green} {yellow green} {forest green} {olive drab} {dark khaki}
    khaki {pale goldenrod} {light goldenrod yellow} {light yellow} yellow
    gold {light goldenrod} goldenrod {dark goldenrod} {rosy brown}
    {indian red} {saddle brown} sienna peru burlywood beige wheat
    {sandy brown} tan chocolate firebrick brown {dark salmon} salmon
    {light salmon} orange {dark orange} coral {light coral} tomato
    {orange red} red {hot pink} {deep pink} pink {light pink}
    {pale violet red} maroon {medium violet red} {violet red}
    magenta violet plum orchid {medium orchid} {dark orchid} {dark violet}
    {blue violet} purple {medium purple} thistle snow2 snow3
    snow4 seashell2 seashell3 seashell4 AntiqueWhite1 AntiqueWhite2
    AntiqueWhite3 AntiqueWhite4 bisque2 bisque3 bisque4 PeachPuff2
    PeachPuff3 PeachPuff4 NavajoWhite NavajoWhite2 NavajoWhite3 NavajoWhite4
    LemonChiffon
    LemonChiffon2 LemonChiffon3 LemonChiffon4 cornsilk2 cornsilk3
    cornsilk4 ivory2 ivory3 ivory4 honeydew2 honeydew3 honeydew4
    LavenderBlush2 LavenderBlush3 LavenderBlush4 MistyRose2 MistyRose3
    MistyRose4 azure2 azure3 azure4 SlateBlue1 SlateBlue2 SlateBlue3
    SlateBlue4 RoyalBlue1 RoyalBlue2 RoyalBlue3 RoyalBlue4 blue2 blue3 blue4
    DodgerBlue2 DodgerBlue3 DodgerBlue4 SteelBlue1 SteelBlue2
    SteelBlue3 SteelBlue4 DeepSkyBlue2 DeepSkyBlue3 DeepSkyBlue4
    SkyBlue1 SkyBlue2 SkyBlue3 SkyBlue4 LightSkyBlue1 LightSkyBlue2
    LightSkyBlue3 LightSkyBlue4 SlateGray1 SlateGray2 SlateGray3
    SlateGray4 LightSteelBlue1 LightSteelBlue2 LightSteelBlue3
    LightSteelBlue4 LightBlue1 LightBlue2 LightBlue3 LightBlue4
    LightCyan2 LightCyan3 LightCyan4 PaleTurquoise1 PaleTurquoise2
    PaleTurquoise3 PaleTurquoise4 CadetBlue1 CadetBlue2 CadetBlue3
    CadetBlue4 turquoise1 turquoise2 turquoise3 turquoise4 cyan2 cyan3
    cyan4 DarkSlateGray1 DarkSlateGray2 DarkSlateGray3 DarkSlateGray4
    aquamarine2 aquamarine3 aquamarine4 DarkSeaGreen1 DarkSeaGreen2 DarkSeaGreen3
    DarkSeaGreen4 SeaGreen1 SeaGreen2 SeaGreen3 PaleGreen1 PaleGreen2
    PaleGreen3 PaleGreen4 SpringGreen2 SpringGreen3 SpringGreen4
    green2 green3 green4 chartreuse2 chartreuse3 chartreuse4
    OliveDrab1 OliveDrab2 OliveDrab4 DarkOliveGreen1 DarkOliveGreen2
    DarkOliveGreen3 DarkOliveGreen4 khaki1 khaki2 khaki3 khaki4
    LightGoldenrod1 LightGoldenrod2 LightGoldenrod3 LightGoldenrod4
    LightYellow2 LightYellow3 LightYellow4 yellow2 yellow3 yellow4
    gold2 gold3 gold4 goldenrod1 goldenrod2 goldenrod3 goldenrod4
    DarkGoldenrod1 DarkGoldenrod2 DarkGoldenrod3 DarkGoldenrod4
    RosyBrown1 RosyBrown2 RosyBrown3 RosyBrown4 IndianRed1 IndianRed2
    IndianRed3 IndianRed4 sienna1 sienna2 sienna3 sienna4 burlywood1
    burlywood2 burlywood3 burlywood4 wheat1 wheat2 wheat3 wheat4 tan1
    tan2 tan4 chocolate1 chocolate2 chocolate3 chocolate4 firebrick1 firebrick2
    firebrick3 firebrick4 brown1 brown2 brown3 brown4 salmon1 salmon2
    salmon3 salmon4 LightSalmon2 LightSalmon3 LightSalmon4 orange2
    orange3 orange4 DarkOrange1 DarkOrange2 DarkOrange3 DarkOrange4
    coral1 coral2 coral3 coral4 tomato2 tomato3 tomato4 OrangeRed2
    OrangeRed3 OrangeRed4 red2 red3 red4 DeepPink2 DeepPink3 DeepPink4
    HotPink1 HotPink2 HotPink3 HotPink4 pink1 pink2 pink3 pink4
    LightPink1 LightPink2 LightPink3 LightPink4 PaleVioletRed1
    PaleVioletRed2 PaleVioletRed3 PaleVioletRed4 maroon1 maroon2
    maroon3 maroon4 VioletRed1 VioletRed2 VioletRed3 VioletRed4
    magenta2 magenta3 magenta4 orchid1 orchid2 orchid3 orchid4 plum1
    plum2 plum3 plum4 MediumOrchid1 MediumOrchid2 MediumOrchid3
    MediumOrchid4 DarkOrchid1 DarkOrchid2 DarkOrchid3 DarkOrchid4
    purple1 purple2 purple3 purple4 MediumPurple1 MediumPurple2
    MediumPurple3 MediumPurple4 thistle1 thistle2 thistle3 thistle4
    gray1 gray2 gray3 gray4 gray5 gray6 gray7 gray8 gray9 gray10
    gray11 gray12 gray13 gray14 gray15 gray16 gray17 gray18 gray19
    gray20 gray21 gray22 gray23 gray24 gray25 gray26 gray27 gray28
    gray29 gray30 gray31 gray32 gray33 gray34 gray35 gray36 gray37
    gray38 gray39 gray40 gray42 gray43 gray44 gray45 gray46 gray47
    gray48 gray49 gray50 gray51 gray52 gray53 gray54 gray55 gray56
    gray57 gray58 gray59 gray60 gray61 gray62 gray63 gray64 gray65
    gray66 gray67 gray68 gray69 gray70 gray71 gray72 gray73 gray74
    gray75 gray76 gray77 gray78 gray79 gray80 gray81 gray82 gray83
    gray84 gray85 gray86 gray87 gray88 gray89 gray90 gray91 gray92
    gray93 gray94 gray95 gray97 gray98 gray99
}
proc main {} {
    package require Tk
    . configure -bg \#4e312d
    wm minsize . 500 200
    wm title . "Tk colors in nested views"
    label .l -text "\nTouch Friendly Selection\nSet ::factor to zero for strict mode.\n" -bg white
    pack .l -pady 30 -padx 30 -fill x
    set ::factor 2.
    scale .ls -from 0.0 -to 4.0 -label "Variable ::factor, maximal listsize is ::base multiplied by " -variable factor \
        -resolution 0.2 -showvalue 1 -orient horizontal
    pack .ls -fill x -expand 1
    set ::base 16
    set ::listsize [expr {$::base * $::factor}]
    radiobutton .b8 -value 8 -text "base  8" -variable ::base
    radiobutton .b4 -value 4 -text "base  4" -variable ::base
    radiobutton .b16 -value 16 -text "base 16" -variable ::base
    pack .b4 .b8 .b16
    button .x -text "Create selection widget\n with Tk colors" -command { new_selection_widget }
    pack .x -fill x -expand 1 -pady 4
}
proc dec_to_4 {i} {
    set res {}
    while {$i>0} {
        set res [expr {$i%4}]$res
        set i [expr {$i/4}]
    }
    if {$res eq {}} {
        set res 0
    }
    format %04d $res
}
proc baselist {} {
    set ::triple {}
    set prefix \#?
    set cor \
        White\u00a0Revealed\nWhite\u00a0light\u00a0now\u00a0reveals\nHidden\u00a0wrongs\u00a0emerge\u00a0in\u00a0view\nTruth\u00a0blooms\u00a0in\u00a0gold\u00a0dawn
    lappend ::triple \
        [list ${prefix}Behind\u00a0the\u00a0Veil\n\nVeils\u00a0lift\u00a0in\u00a0the\u00a0halls\nPower's\u00a0shadows\u00a0hide\u00a0the\u00a0truth\nJustice\u00a0wakes\u00a0at\u00a0dawn] \
        $cor
    set code ${prefix}\u00ac\u00a0\u2696\n
    lappend ::triple \
        [list ${code}\Touch\u00a0Friendly\u00a0Selection\nPolitical\u00a0Prisoner\u00a0Edition\u00a02026-11-12] white
    lappend ::triple [list ${code}2\nInternational\u00a0Crimes\nInvestigation\u00a0Commitee] \#d00000
    lappend ::triple [list ${code}1\nDr.\u2022Reiner\u2022Füllmich\n//icic.law] black
    lappend ::triple [list ${code}3\nsince\u00a02023-10-13\nfreeReinerFuellmich] \#ffce00
    foreach x $::COLORS {
        set rgb [winfo rgb . $x]
        lassign $rgb r g b
        set hex [format %4.4x%4.4x%4.4x $r $g $b]
        regexp {^(..)..(..)..(..)} $hex {} hr hg hb
        lappend ::triple $x \#$hr$hg$hb
        switch -- $::base {
            4 {
                scan $hr %x dr
                scan $hg %x dg
                scan $hb %x db
                set base_encoded [list \#R0q[dec_to_4 $dr] #G0q[dec_to_4 $dg] #B0q[dec_to_4 $db]]
            }
            8 {
                scan $hr %x or
                scan $hg %x og
                scan $hb %x ob
                set base_encoded [list [format "#R0o%3.3o" $or] [format "#G0o%3.3o" $og] [format "#B0o%3.3o" $ob]]
            }
            16 {
                set base_encoded [list  "#R0x$hr" "#G0x$hg" "#B0x$hb"]
            }
            default {
                set base_encoded [list [format #R0d%5.5d $r] [format #G0d%5.5d $g] [format #B0d%5.5d $b]]
            }
        }
        lappend ::triple $base_encoded $x
    }
    lappend ::triple Espresso {#4e312d}
    lappend ::triple {Ash Espresso} {#351003}
    lappend ::triple {Double Shot} {#2a1d1b}
    lappend ::triple {Espresso Black} {#342e21}
    lappend ::triple {Espresso Macchiato} {#c89d72}
    lappend ::triple {Midnight Espresso} {#181216}
    lappend ::triple {Espresso Crema} {#d09c43}
}
set ::colorobjects {}
set ::id 0
proc new_selection_widget {} {
    baselist
    set ::listsize [expr {int($::base*$::factor +.5)}]
    set top [toplevel .i$::id -bg {}]
    incr ::id
    wm minsize $top 200 400
    wm geometry $top 260x480
    if {![info exists ::corolatus::android]} {
    set ::corolatus::android 0
    }
    if {[info exists ::strict]} {
        set coloratus [::corolatus::corolatus new $top $::corolatus::android ::triple 1 -list_size 0]
    } else {
        set coloratus [::corolatus::corolatus new $top $::corolatus::android ::triple 1 -list_size $::listsize]
    }
    lappend ::colorobjects $coloratus
    wm title $top "$coloratus base $::base, listsize<=$::listsize"
    #. overwrite etx method
    oo::objdefine $coloratus method etx {k v args} {
        variable R
        variable xfont
        variable daba
        variable input
        set refocus [focus -lastfor $R]
        set counter 0
        regexp {([0-9]+)$} $daba {\1} counter
        set top .etx$counter
        set ltext $top.f.l
        if {![winfo exists $top]} {
            toplevel $top
            bind $top <Any-Key> [list wm withdraw $top]
            frame $top.f -bg {}
            pack $top.f -expand 1
            label $ltext -text dummy
        }
        if {[catch {
                set colorname [$daba pnr_get [regsub {\u23ce$} $k {}]]
                if {![string length $colorname]} {
                    set colorname [$daba pnr_get [regsub -all {\u2423} $k { }]]
                }
                set fg_contrast [colors::contrasting $colorname {white black}]
                $ltext configure -text $k\n$colorname -bg $colorname -fg $fg_contrast -highlightbackground $fg_contrast -highlightcolor $fg_contrast -takefocus 1 -font $xfont
            } err]} {
            $ltext configure -text $err -font $xfont
        }
        pack $ltext -fill both -expand 1
        #. hides changes in fontsize
        $top.f configure -width [winfo reqwidth $top.f] -height [winfo reqheight $top.f]
        after 300 [list pack forget $ltext]
        wm deiconify $top
        after idle [list focus -force $R ; focus $refocus]
    }
    oo::objdefine $coloratus method etx_hide {args} {}
}
main