packages feed

sindre-0.1: sinmenu

#!/bin/sh
gui=$(cat <<EOF
GUI {
Horizontally@bottom?"bot":"top" {
    prompt=Label(label=pstring,highlight=1, fg=ffg, bg=fbg);
    input=Input(minwidth=200, font=font, fg=fg, bg=bg, ffg=ffg, fbg=fbg);
    list=HList(i=ins, font=font, fg=fg, bg=bg, ffg=ffg, fbg=fbg);
  }
}
EOF
)
for arg in "$@"; do
    if [ "$arg" = '-l' ]; then
        gui=$(cat <<EOF
GUI {
Horizontally@bottom?"bot":"top" {
  Vertically {
    prompt=Label(label=pstring,highlight=1, fg=ffg, bg=fbg);
    Blank(fg=fg, bg=bg, ffg=ffg, fbg=fbg);
  }
  Vertically {
    input=Input(minwidth=0, font=font, fg=fg, bg=bg, ffg=ffg, fbg=fbg);
    list=VList(lines=lines, i=ins, font=font, fg=fg, bg=bg, ffg=ffg, fbg=fbg);
  }
}
}
option lines (-l,,"List items vertically, with the given number of lines.", "INTEGER", 10)
EOF
        )
    fi
done
code=$(cat <<EOF
BEGIN { input.value = contents }
option pstring (-p,--prompt,"Set the input prompt", "prompt", "")
option bottom (-b,,"Appear at bottom of screen")
option contents(-c,,"Starting contents of buffer", "text", "")
option ins(-i,,"Case-insensitive list matching")
option font(,--font,"Font used for text", "font")
option fg(,--nf,"Normal foreground colour", "colour")
option bg(,--nb,"Normal background colour", "colour")
option ffg(,--sf,"Selected element foreground colour", "colour")
option fbg(,--sb,"Selected element background colour", "colour")
function complete() { if (list.selected) { input.value = list.selected } }
function filter() { list.filter(input.value) }
function select() { print input.value; exit }
function quit() { exit 1 }
stdin->lines(lines) { list.insert(lines) }
BEGIN { focus input }
<C-g> || <Escape> || <C-c> { quit() }
<Up> || <C-p> || <C-r> { list.prev() }
<Down> || <C-n> || <C-s> { list.next() }
<Return> || <C-j> { complete(); select(); }
<Shift-Return> || <C-J> { select(); }
<C-i> || <Tab> { complete() }
<C-y> { input.value = sub("\n.*", "", osystem("sselp")) }
<C-e> { list.last() }
<C-a> { list.first() }
input.value->changed(from, to) { filter() }
EOF
)
sindre -e "$gui" -e "$code" "$@"