TUI functions library in Bash
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Blau Araujo 66ed9ec701 Function input_bar 9 months ago
LICENSE Initial commit 9 months ago
README.md Function input_bar 9 months ago
bashui Function input_bar 9 months ago

README.md

bashui

Bash functions library to build terminal user interfaces.

1. Globals

To keep track of cursor position, bashui uses two globals:

Global Description
UI_CROW Current row.
UI_CCOL Current column.

2. Terminal size and cursor info

Function: term_size()

Print terminal rows and columns.

Usage

term_size [OPTION]
Argument Return
none Number of rows and columns.
c Number of columns.
l Number of rows.

Function: cursor_position()

Print current cursor row and column.

Usage

cursor_position
Argument Return
none Current UI_CROW and UI_CCOL values.

Function: cursor_line()

Print current line.

Usage

cursor_line
Argument Return
none Current UI_CROW value.

Function: cursor_col()

Print cursor current column.

Usage

cursor_col
Argument Return
none Current UI_CCOL value.

3. Set cursor position

Function: cursor_set()

Move cursor to position and update UI_CROW and UI_CCOL globals.

Usage

cursor_set ROW COLUMN
Argument Description
ROW (Required) Destination row.
COL (Required) Destination column.

Function: cmove_top()

Move cursor to first line at optional given column.

Usage

cmove_top [COLUMN]
Argument Description
COLUMN (Optional) Destination column (default=0).

Function: cmove_bottom()

Move cursor to last line at optional given column.

Usage

cmove_bottom [COLUMN]
Argument Description
COLUMN (Optional) Destination column (default=0).

Function: cmove_row()

Move cursor to given line at current column.

Usage

cmove_row ROW
Argument Description
ROW (Required) Destination row.

Function: cmove_col()

Move cursor to given column at current line.

Usage

cmove_col COLUMN
Argument Description
COLUMN (Required) Destination column.

Function: cmove_up()

Move cursor up.

Usage

cmove_up [STEPS]
Argument Description
STEPS (Optional) Number of steps (default=1).

Function: cmove_down()

Move cursor down.

Usage

cmove_down [STEPS]
Argument Description
STEPS (Optional) Number of steps (default=1).

Function: cmove_left()

Move cursor left.

Usage

cmove_left [STEPS]
Argument Description
STEPS (Optional) Number of steps (default=1).

Function: cmove_right()

Move cursor right.

Usage:

cmove_right [STEPS]
Argument Description
STEPS (Optional) Number of steps (default=1).

Function: cmove_home()

Move cursor to the first column of current line.

Usage:

cmove_home 
Argument Description
none Move cursor to column 0.

Function: cmove_end()

Move cursor to the last column of current line.

Usage

cmove_home 
Argument Description
none Move cursor to column 0.

4. Clear terminal, lines and region

Function: clear_terminal()

Clear terminal and move cursor to home position.

Usage

clear_terminal
Argument Description
none Clear terminal and move cursor to home (0,0).

Function: clear_line()

Clear current or specified row.

Usage

clear_line [ROW]
Argument Description
ROW Row to be cleared (default=current).

Function: clear_region()

Clear rectangular region.

Usage

clear_region ROW COLUMN WIDTH HEIGHT
Argument Description
ROW Starting row.
COLUMN Starting column.
WIDTH Box width in columns.
HEIGHT Box hight in lines.

5. Frames and windows

Function: draw_frame()

Draw a frame border.

Usage

draw_frame ROW COLUMN WIDTH HEIGHT
Argument Description
ROW Starting row.
COLUMN Starting column.
WIDTH Box width in columns.
HEIGHT Box hight in lines.

Function: draw_title_bar()

Draw horizontal line in the top portion of a frame.

Usage

draw_title_bar ROW COLUMN WIDTH
Argument Description
ROW Starting row.
COLUMN Starting column.
WIDTH Box width in columns.

Function: draw_status_bar()

Draw horizontal line in the bottom portion of a frame.

Usage

draw_status_bar ROW COLUMN WIDTH HEIGHT
Argument Description
ROW Starting row.
COLUMN Starting column.
WIDTH Box width in columns.
HEIGHT Box hight in lines.

6. Strings

Function: print_label()

Print aligned text at current line.

Usage

print_label STRING
print_label STRING ALIGN
print_label STRING COL_START,COL_END
print_label STRING ALIGN COL_START,COL_END
Argument Description
STRING (Required) String to be printed.
ALIGN (Optional) Alignment (default=left).
COL_START (Optional) Left margin position (default=0).
COL_END (Optional) Right margin position (default=last column).

Function: str_len()

Print string lenght.

Usage

str_len STRING
Argument Description
STRING (Required) The string.

Function: in_string()

Exit with success if NEEDLE is in HAYSTACK.

Usage

in_string HAYSTACK NEEDLE
Argument Description
HAYSTACK (Required) String to search in.
NEEDLE (Required) String to be searched.

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)