Compare commits

...

10 Commits

Author SHA1 Message Date
Alex Clarke
08f92d7d73 Fixed a simple bug in the confirmation prompt 2025-04-28 18:35:15 -06:00
Alex Clarke
3b52deb010 Created a static bundle.bash for sourcing 2025-04-28 10:59:29 -06:00
renovate[bot]
03165f3f10 chore(deps): update dependency shellcheck to v3.4.0 2025-03-05 22:47:19 +01:00
renovate[bot]
670a67539b chore(deps): update golang docker tag to v1.24 2025-02-14 08:51:00 +01:00
renovate[bot]
0e76e0f129 chore(deps): update dependency shellcheck to v3.3.0 2025-01-14 16:16:37 +01:00
Timo Reymann
d2a81318f1 docs(readme): Fix docs links 2025-01-03 22:44:37 +01:00
Timo Reymann
002c7b4557 docs: Link to pages docs 2025-01-03 16:15:39 +01:00
Timo Reymann
0bf3f35515 chore(scripts): Clear docs before uploading 2025-01-03 15:28:12 +01:00
Timo Reymann
6a99464360 chore: Remove docs readme rewrite 2025-01-03 15:24:53 +01:00
semantic-release-bot
349b4bce2f chore(release): 1.9.0 [skip ci]
## [1.9.0](https://github.com/timo-reymann/bash-tui-toolkit/compare/1.8.4...1.9.0) (2025-01-03)

### Features

* **scripts:** Upload documentation for releases ([27e80da](27e80da224))
2025-01-03 14:22:31 +00:00
7 changed files with 404 additions and 6 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
version: "2.1" version: "2.1"
orbs: orbs:
shellcheck: circleci/shellcheck@3.2.0 shellcheck: circleci/shellcheck@3.4.0
semantic-release: trustedshops-public/semantic-release@6.0.0 semantic-release: trustedshops-public/semantic-release@6.0.0
jobs: jobs:
+1 -1
View File
@@ -1,4 +1,4 @@
FROM golang:1.23-alpine FROM golang:1.24-alpine
RUN apk add bash git && \ RUN apk add bash git && \
mkdir -p /opt && \ mkdir -p /opt && \
mkdir -p /workspace && \ mkdir -p /workspace && \
+7
View File
@@ -1,3 +1,10 @@
## [1.9.0](https://github.com/timo-reymann/bash-tui-toolkit/compare/1.8.4...1.9.0) (2025-01-03)
### Features
* **scripts:** Upload documentation for releases ([27e80da](https://github.com/timo-reymann/bash-tui-toolkit/commit/27e80da22421a0cf58e99b4ee24d9bf15c9546c5))
## [1.8.4](https://github.com/timo-reymann/bash-tui-toolkit/compare/1.8.3...1.8.4) (2024-08-22) ## [1.8.4](https://github.com/timo-reymann/bash-tui-toolkit/compare/1.8.3...1.8.4) (2024-08-22)
+3 -2
View File
@@ -41,7 +41,7 @@ Bash TUI Toolkit
> Note that this is not a recommended approach and only intended for quick testing or trying out another version. > Note that this is not a recommended approach and only intended for quick testing or trying out another version.
1. Choose the bundle in the version you want to use from the available releases on the [gh-pages branch](https://github.com/timo-reymann/bash-tui-toolkit/tree/gh-pages). 1. Choose the bundle in the version you want to use from the available releases in the [docs](https://bash-tui-toolkit.timo-reymann.de/).
2. Source it to your script on runtime: 2. Source it to your script on runtime:
1. Using `wget` 1. Using `wget`
```bash ```bash
@@ -54,7 +54,7 @@ Bash TUI Toolkit
## Usage ## Usage
For a list of available modules and their documentation please check the [docs/modules](./docs/modules) folder For a list of available modules and their documentation please check the [docs](https://bash-tui-toolkit.timo-reymann.de/).
For a complete playground demo check [test.sh](./test.sh). For a complete playground demo check [test.sh](./test.sh).
@@ -68,6 +68,7 @@ the target system.
## Documentation ## Documentation
- [GitHub Pages](https://bash-tui-toolkit.timo-reymann.de/) - Versioned releases, documentation and compability matrix
- [Modules](./docs/modules) - Modules available and their usage - [Modules](./docs/modules) - Modules available and their usage
- [Compability table](./docs/Compatibility) - Known combinations of OS/Bash Version/Terminal emulators that work guaranteed - [Compability table](./docs/Compatibility) - Known combinations of OS/Bash Version/Terminal emulators that work guaranteed
+390
View File
@@ -0,0 +1,390 @@
###############################################################################
# #
# Bash TUI Toolkit #
# by Timo Reymann #
# #
# version: 1.9.0 #
# bundle: bundle #
# github: https://github.com/timo-reymann/bash-tui-toolkit #
# #
# --------------------------------------------------------------------------- #
# #
# Copyright (C) 2023 Timo Reymann (mail@timo-reymann.de) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
###############################################################################
_read_stdin() {
read $@ </dev/tty
}
_get_cursor_row() {
local IFS=';'
_read_stdin -sdR -p $'\E[6n' ROW COL
echo "${ROW#*[}"
}
_cursor_blink_on() { echo -en "\033[?25h" >&2; }
_cursor_blink_off() { echo -en "\033[?25l" >&2; }
_cursor_to() { echo -en "\033[$1;$2H" >&2; }
_key_input() {
local ESC=$'\033'
local IFS=''
_read_stdin -rsn1 a
if [[ "$ESC" == "$a" ]]; then
_read_stdin -rsn2 b
fi
local input="${a}${b}"
case "$input" in
"$ESC[A" | "k") echo up ;;
"$ESC[B" | "j") echo down ;;
"$ESC[C" | "l") echo right ;;
"$ESC[D" | "h") echo left ;;
'') echo enter ;;
' ') echo space ;;
esac
}
_new_line_foreach_item() {
count=0
while [[ $count -lt $1 ]]; do
echo "" >&2
((count++))
done
}
_prompt_text() {
echo -en "\033[32m?\033[0m\033[1m ${1}\033[0m " >&2
}
_decrement_selected() {
local selected=$1
((selected--))
if [ "${selected}" -lt 0 ]; then
selected=$(($2 - 1))
fi
echo -n $selected
}
_increment_selected() {
local selected=$1
((selected++))
if [ "${selected}" -ge "${opts_count}" ]; then
selected=0
fi
echo -n $selected
}
input() {
_prompt_text "$1"
echo -en "\033[36m\c" >&2
_read_stdin -r text
echo -n "${text}"
}
confirm() {
trap "_cursor_blink_on; stty echo; exit" 2
_cursor_blink_off
_prompt_text "$1 (y/N)"
echo -en "\033[36m\c " >&2
local start_row
start_row=$(_get_cursor_row)
local current_row
current_row=$((start_row - 1))
local result=""
echo -n " " >&2
while true; do
echo -e "\033[1D\c " >&2
_read_stdin -n1 result
case "$result" in
y | Y)
echo -n 1
break
;;
n | N | *)
echo -n 0
break
;;
esac
done
echo -en "\033[0m" >&2
echo "" >&2
}
list() {
_prompt_text "$1 "
local opts=("${@:2}")
local opts_count=$(($# - 1))
_new_line_foreach_item "${#opts[@]}"
local lastrow
lastrow=$(_get_cursor_row)
local startrow
startrow=$((lastrow - opts_count + 1))
trap "_cursor_blink_on; stty echo; exit" 2
_cursor_blink_off
local selected=0
while true; do
local idx=0
for opt in "${opts[@]}"; do
_cursor_to $((startrow + idx))
if [ $idx -eq $selected ]; then
printf "\033[0m\033[36m\033[0m \033[36m%s\033[0m" "$opt" >&2
else
printf " %s" "$opt" >&2
fi
((idx++))
done
case $(_key_input) in
enter) break ;;
up) selected=$(_decrement_selected "${selected}" "${opts_count}") ;;
down) selected=$(_increment_selected "${selected}" "${opts_count}") ;;
esac
done
echo -en "\n" >&2
_cursor_to "${lastrow}"
_cursor_blink_on
echo -n "${selected}"
}
checkbox() {
_prompt_text "$1"
local opts
opts=("${@:2}")
local opts_count
opts_count=$(($# - 1))
_new_line_foreach_item "${#opts[@]}"
local lastrow
lastrow=$(_get_cursor_row)
local startrow
startrow=$((lastrow - opts_count + 1))
trap "_cursor_blink_on; stty echo; exit" 2
_cursor_blink_off
local selected=0
local checked=()
while true; do
local idx=0
for opt in "${opts[@]}"; do
_cursor_to $((startrow + idx))
local icon="◯"
for item in "${checked[@]}"; do
if [ "$item" == "$idx" ]; then
icon="◉"
break
fi
done
if [ $idx -eq $selected ]; then
printf "%s \e[0m\e[36m\e[0m \e[36m%-50s\e[0m" "$icon" "$opt" >&2
else
printf "%s %-50s" "$icon" "$opt" >&2
fi
((idx++))
done
case $(_key_input) in
enter) break ;;
space)
local found=0
for item in "${checked[@]}"; do
if [ "$item" == "$selected" ]; then
found=1
break
fi
done
if [ $found -eq 1 ]; then
checked=("${checked[@]/$selected/}")
else
checked+=("${selected}")
fi
;;
up) selected=$(_decrement_selected "${selected}" "${opts_count}") ;;
down) selected=$(_increment_selected "${selected}" "${opts_count}") ;;
esac
done
_cursor_to "${lastrow}"
_cursor_blink_on
IFS="" echo -n "${checked[@]}"
}
password() {
_prompt_text "$1"
echo -en "\033[36m" >&2
local password=''
local IFS=
while _read_stdin -r -s -n1 char; do
[[ -z "${char}" ]] && {
printf '\n' >&2
break
}
if [ "${char}" == $'\x7f' ]; then
if [ "${#password}" -gt 0 ]; then
password="${password%?}"
echo -en '\b \b' >&2
fi
else
password+=$char
echo -en '*' >&2
fi
done
echo -en "\e[0m" >&2
echo -n "${password}"
}
editor() {
tmpfile=$(mktemp)
_prompt_text "$1"
echo "" >&2
"${EDITOR:-vi}" "${tmpfile}" >/dev/tty
echo -en "\033[36m" >&2
cat "${tmpfile}" | sed -e 's/^/ /' >&2
echo -en "\033[0m" >&2
cat "${tmpfile}"
}
with_validate() {
while true; do
local val
val="$(eval "$1")"
if ($2 "$val" >/dev/null); then
echo "$val"
break
else
show_error "$($2 "$val")"
fi
done
}
range() {
local min="$2"
local current="$3"
local max="$4"
local selected="${current}"
local max_len_current
max_len_current=0
if [[ "${#min}" -gt "${#max}" ]]; then
max_len_current="${#min}"
else
max_len_current="${#max}"
fi
local padding
padding="$(printf "%-${max_len_current}s" "")"
local start_row
start_row=$(_get_cursor_row)
local current_row
current_row=$((start_row - 1))
trap "_cursor_blink_on; stty echo; exit" 2
_cursor_blink_off
_check_range() {
val=$1
if [[ "$val" -gt "$max" ]]; then
val=$min
elif [[ "$val" -lt "$min" ]]; then
val=$max
fi
echo "$val"
}
while true; do
_prompt_text "$1"
printf "\033[37m%s\033[0m \033[1;90m\033[0m \033[36m%s%s\033[0m \033[1;90m\033[0m \033[37m%s\033[0m\n" "$min" "${padding:${#selected}}" "$selected" "$max" >&2
case $(_key_input) in
enter)
break
;;
left)
selected="$(_check_range $((selected - 1)))"
;;
right)
selected="$(_check_range $((selected + 1)))"
;;
esac
_cursor_to "$current_row"
done
echo "$selected"
}
validate_present() {
if [ "$1" != "" ]; then return 0; else
echo "Please specify the value"
return 1
fi
}
show_error() {
echo -e "\033[91;1m✘ $1\033[0m" >&2
}
show_success() {
echo -e "\033[92;1m✔ $1\033[0m" >&2
}
LOG_ERROR=3
LOG_WARN=2
LOG_INFO=1
LOG_DEBUG=0
parse_log_level() {
local level="$1"
local parsed
case "${level}" in
info | INFO) parsed=$LOG_INFO ;;
debug | DEBUG) parsed=$LOG_DEBUG ;;
warn | WARN) parsed=$LOG_WARN ;;
error | ERROR) parsed=$LOG_ERROR ;;
*) parsed=-1 ;;
esac
export LOG_LEVEL="${parsed}"
}
log() {
local level="$1"
local message="$2"
local color=""
if [[ $level -lt ${LOG_LEVEL:-$LOG_INFO} ]]; then
return
fi
case "${level}" in
"$LOG_INFO")
level="INFO"
color='\033[1;36m'
;;
"$LOG_DEBUG")
level="DEBUG"
color='\033[1;34m'
;;
"$LOG_WARN")
level="WARN"
color='\033[0;33m'
;;
"$LOG_ERROR")
level="ERROR"
color='\033[0;31m'
;;
esac
echo -e "[${color}$(printf '%-5s' "${level}")\033[0m] \033[1;35m$(date +'%Y-%m-%dT%H:%M:%S')\033[0m ${message}"
}
detect_os() {
case "$OSTYPE" in
solaris*) echo "solaris" ;;
darwin*) echo "macos" ;;
linux*) echo "linux" ;;
bsd*) echo "bsd" ;;
msys*) echo "windows" ;;
cygwin*) echo "windows" ;;
*) echo "unknown" ;;
esac
}
get_opener() {
local cmd
case "$(detect_os)" in
macos) cmd="open" ;;
linux) cmd="xdg-open" ;;
windows) cmd="start" ;;
*) cmd="" ;;
esac
echo "$cmd"
}
open_link() {
cmd="$(get_opener)"
if [ "$cmd" == "" ]; then
echo "Your platform is not supported for opening links."
echo "Please open the following URL in your preferred browser:"
echo " ${1}"
return 1
fi
$cmd "$1"
if [[ $? -eq 1 ]]; then
echo "Failed to open your browser."
echo "Please open the following URL in your browser:"
echo "${1}"
return 1
fi
return 0
}
-1
View File
@@ -1 +0,0 @@
docs/index.md
+2 -1
View File
@@ -36,7 +36,8 @@ echo "Link ${release_tag} to latest ..."
rm latest || true rm latest || true
ln -s "${release_tag}" latest ln -s "${release_tag}" latest
cp -R "${PROJECT_DIR}/docs" "${release_tag}/docs" rm -rf "${release_tag}/docs"
cp -R "${PROJECT_DIR}/docs/" "${release_tag}/docs/"
git stage . git stage .
git commit -m "chore: Add assets for ${release_tag}\ git commit -m "chore: Add assets for ${release_tag}\