Created
September 2, 2015 22:14
-
-
Save maximsch2/729d1c6f39a42af548de to your computer and use it in GitHub Desktop.
String list picker in Escher.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function picker{T}(data::AbstractArray{T,1}, selected = T[]) | |
sinput = Input("") | |
inp = Input(nokey) | |
getvals = s -> begin | |
data = filter(x -> !(x in selected), data) | |
ldata = map(lowercase, data) | |
ls = lowercase(s) | |
vals = filter(x -> contains(lowercase(x), ls), data) | |
if length(s) == 0 | |
vals = UTF8String[] | |
end | |
vals | |
end | |
getoutput(s) = vbox(map(plaintext, getvals(s))) | |
dont_show = false | |
function showoutput(s, k) | |
if dont_show | |
dont_show = false | |
return getoutput("") | |
end | |
return getoutput(s) | |
end | |
input = subscribe(textinput(label="Add:", floatinglabel=false), sinput) | |
input = keypress("enter", input) >>> inp | |
f2 = i -> | |
begin | |
vals = getvals(sinput.value) | |
if length(vals) == 1 | |
push!(selected, vals[1]) | |
elseif sinput.value in vals | |
push!(selected, sinput.value) | |
end | |
dont_show = true | |
vbox(map(plaintext, selected)) | |
end | |
seloutput = consume(f2, inp) | |
output = consume(showoutput, sinput, inp) | |
cursel = lift(x->selected, inp) | |
tile = | |
vbox( | |
seloutput, | |
vskip(2em), | |
input, | |
output | |
) |> pad(0.5em) | |
tile, cursel | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment