diff options
author | P. J. McDermott <pj@pehjota.net> | 2015-10-28 23:31:49 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2015-10-28 23:31:49 (EDT) |
commit | 89332994eb38982a8bd04ccc008bc5aba0c58908 (patch) | |
tree | 13e6c160f8ae49fe64625e71af0af424d05a0202 | |
parent | 8611199c5c9e6fa70cbd587e1dce79e85227cbd3 (diff) | |
download | firman.sh-89332994eb38982a8bd04ccc008bc5aba0c58908.zip firman.sh-89332994eb38982a8bd04ccc008bc5aba0c58908.tar.gz firman.sh-89332994eb38982a8bd04ccc008bc5aba0c58908.tar.bz2 |
tui_show_prompt(): Implement (line editing missing)
-rw-r--r-- | src/ui/tui.sh | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/src/ui/tui.sh b/src/ui/tui.sh index 6e8b4e1..40a2857 100644 --- a/src/ui/tui.sh +++ b/src/ui/tui.sh @@ -174,8 +174,91 @@ tui_show_menu() tui_show_prompt() { local title="${1}" + local len=${2} + shift 2 + local w= + local y= + local x= + local i= + local line='' local input='' - shift 1 + local curpos=0 + local focus=0 + local key= + + # Calculate width and draw the box. + w=$(expr ${#title} + 4) + if [ $(expr ${len} + 7) -gt ${w} ]; then + w=$(expr ${len} + 7) + fi + read -r y x <<-EOF + $(_tui_box ${w} 7) + EOF + + # Write the title. + term_cursor_down 1 + term_cursor_forward 2 + term_write "${title}" + + # Build blank input line. + i=0 + while [ ${i} -le ${len} ]; do + line="${line} " + i=$(($i + 1)) + done + + # Event loop. + while :; do + # Draw a button. + term_cursor_position $(($y + 5)) $(($x + $w - 6)) + if [ ${focus} -eq 1 ]; then + term_attr_on reverse + term_write '[OK]' + term_attr_off reverse + else + term_write '[OK]' + fi + + # Draw a textbox. + term_cursor_position $(($y + 3)) $(($x + 2)) + term_write '[' + term_attr_on underline + term_write "${line}" + term_attr_off underline + term_write ']' + term_cursor_position $(($y + 3)) $(($x + 3)) + term_attr_on underline + term_write "${input}" + term_attr_off underline + + # Put the cursor in the text box. + if [ ${focus} -eq 0 ]; then + term_show_cursor + term_cursor_position $(($y + 3)) $(($x + 3 + $curpos)) + else + term_hide_cursor + fi + + # Input. + key="$(term_getch)" + if [ "x${key}" = xKEY_TAB ]; then + focus=$(expr \( ${focus} + 1 \) % 2) + elif [ ${focus} -eq 0 ]; then + case "${key}" in + KEY_ENTER) break;; + # TODO: Line editing + *) + input="${input}${key}" + curpos=$(($curpos + 1)) + ;; + esac + elif [ ${focus} -eq 1 ]; then + case "${key}" in + KEY_ENTER | KEY_SPACE) break;; + esac + fi + done + printf '%s' "${input}" return 0 } |