Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions staging/interface/info_box.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[interface_info_box]
description=Display a rolling info box with dialog/whiptail; reads and shows lines from stdin or a single message.
extend_desc=This helper provides a live-updating infobox for progress or log output in TUI (dialog/whiptail). When piped, shows the last N lines as they arrive. If called with an argument, displays it as a static message. Useful for monitoring, user feedback, or background task reporting in config-v3.
documents=false
options=[message] | (via stdin/pipe)
parent=framework
group=helpers
contributor=Tearran
maintainer=true
arch=arm64 armhf x86-64
require_os=Debian Ubuntu Armbian
require_kernel=5.15+
port=false


[_about_interface_info_box]
description=Display usage and about information for the interface_info_box helper.
extend_disc=Provides concise usage instructions and example commands for the interface_info_box module. Intended for internal and help display use only.
documents=false
options=
parent=framework
group=helpers
contributor=Tearran
maintainer=true
arch=arm64 armhf x86-64
require_os=Debian Ubuntu Armbian
require_kernel=5.15+
port=false
56 changes: 56 additions & 0 deletions staging/interface/info_box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

_about_interface_info_box() {
cat <<EOF
Usage: interface_info_box

Displays a rolling info box using dialog/whiptail.
Reads lines from stdin and displays them live.
If not used with a pipe, shows a single message.

Examples:
some_command | interface_info_box
echo "Hello" | interface_info_box
interface_info_box -h|--help|help
EOF
}

interface_info_box() {
# Help flag: show about if -h or --help is the first argument
case "${1:-}" in
-h|--help|help)
_about_interface_info_box
return 0
;;
esac

local input
local dialog="${DIALOG:-}"
if [[ "$dialog" != "dialog" && "$dialog" != "whiptail" ]]; then
dialog="whiptail"
fi
local title="${TITLE:-Info}"
local -a buffer
local lines=16 width=90 max_lines=18

if [ -p /dev/stdin ]; then
while IFS= read -r line; do
buffer+=("$line")
# Limit buffer size to max_lines
((${#buffer[@]} > max_lines)) && buffer=("${buffer[@]:1}")
# Show buffer in infobox
TERM=ansi $dialog --title "$title" --infobox "$(printf "%s\n" "${buffer[@]}")" $lines $width
sleep 0.5
done
else
input="${1:-}"
if [[ -z "$input" ]]; then
echo "Error: No input provided." >&2
_about_interface_info_box
return 1
fi
TERM=ansi $dialog --title "$title" --infobox "$input" 6 80
sleep 2
fi
echo -ne '\033[3J' # clear the screen
}
23 changes: 23 additions & 0 deletions staging/interface/ok_box.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[interface_message]
feature=interface_message
description=Displays a message to the user using the configured dialog tool.
extend_disc=Reads input text (either from standard input or as an argument) and presents it to the user with the selected dialog frontend. Supports dialog, whiptail, or plain read/echo. Handles input flexibly and routes output appropriately depending on the tool.
extend_docs=false
options=<message>
parent=framework
group=helpers
contributor=Tearran
maintainer=true
arch=arm64 armhf x86-64
require_os=Debian Ubuntu Armbian
require_kernel=5.15+
port=false

[_about_interface_message]
feature=_about_interface_message
description=Show help and usage information for the interface_message helper.
extend_disc=Outputs usage, available options, and example commands for the interface_message helper function.
extend_docs=false
options=
parent=framework
group=helpers
46 changes: 46 additions & 0 deletions staging/interface/ok_box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash


function _about_interface_message() {
cat <<EOF
Usage: interface_message ["message"]
Examples:
interface_ok_box "Operation completed successfully."
echo "Hello from stdin" | interface_ok_box
interface_ok_box <<< "Message from here-string"
EOF

}

function interface_ok_box() {
local message="${1:-}"

if [[ "$message" == "help" || "$message" == "-h" ]]; then
_about_interface_message
return 0
fi

if [[ -z "$message" ]]; then
echo "Error: Missing message." >&2
_about_interface_message
return 1
fi

local dialog="${DIALOG:-whiptail}"

case "$dialog" in
dialog)
dialog --title "${TITLE:-Info}" --msgbox "$message" 10 80 >/dev/tty 2>&1
;;
whiptail)
whiptail --title "${TITLE:-Info}" --msgbox "$message" 10 80 3>&1 1>&2 2>&3
;;
read)
echo "$message"
;;
*)
echo "$message"
Copy link

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the default case of the switch (lines 48-50), consider outputting a clear error message indicating that an unsupported dialog tool was provided, rather than just echoing the message.

Suggested change
echo "$message"
echo "Error: Unsupported dialog tool '$dialog'. Supported tools are: dialog, whiptail, read." >&2

Copilot uses AI. Check for mistakes.
return 1
;;
esac
}
11 changes: 11 additions & 0 deletions staging/interface/test_info_box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail

# info_box - Armbian Config V3 test

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "info_box - Armbian Config V3 test"
echo "# TODO: implement module logic"
exit 1
fi

11 changes: 11 additions & 0 deletions staging/interface/test_ok_box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail

# ok_box - Armbian Config V3 test

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "ok_box - Armbian Config V3 test"
echo "# TODO: implement module logic"
exit 1
fi

Loading