Browse Source

Function input_bar

main
Blau Araujo 11 months ago
parent
commit
33118eb783
  1. 19
      README.md
  2. 35
      bashui

19
README.md

@ -393,3 +393,22 @@ in_string HAYSTACK NEEDLE
---
## 7. Widgets
### Function: `input_bar()`
Draw full width box or line for generic text input.
#### Usage
```
input_bar PROMPT [POSITION] [BORDER]
```
| Argument | Description |
|:----------:|---------------------------------------------------------|
| `PROMPT` | (Required) Prompt string |
| `POSITION` | (Optional) `top` or `bottom` (default) |
| `BORDER` | (Optional) `0=no border` ou `1 = draw border` (default) |
---

35
bashui

@ -1,5 +1,9 @@
#!/usr/bin/env bash
# GLOBALS
declare UI_CROW UI_CCOL USER_INPUT
# TERMINAL AND CURSOR INFO
term_size() case $1 in
@ -207,3 +211,34 @@ str_len() {
in_string() [[ "$1" == *"$2"* ]]
# WIDGETS
input_bar() {
local prompt position border line
prompt="$1"
position=bottom
border=1
line=$(($(term_size l) - 3))
case $# in
2) in_string 'top bottom' "$2" && position=$2 || border=$2;;
3) position=$2; border=$3;;
esac
if ((border)); then
[[ $position = top ]] && line=0
draw_frame $line 0 $(term_size c) 3
cmove_up
cmove_right 2
else
case $position in
top) cmove_top 1;;
bottom) cmove_bottom 1;;
esac
fi
read -rep "$prompt " USER_INPUT
}

Loading…
Cancel
Save