This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathui.rc
101 lines (78 loc) · 2.12 KB
/
ui.rc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#
# Copyright 2015-2020 Adrian DC
#
# 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.
#
# === Advanced Development Shell Tools UI ===
function __shtoolsui()
{
# Usage: __shtoolsui <enable/start/input/disable> (UI wrapper for the project)
# Enable UI wrapper
if [ "${1}" = 'enable' ]; then
# Terminal backup
tput smcup;
# Clear UI wrapper
elif [ "${1}" = 'start' ]; then
# Terminal colors
tput setab 0;
tput setaf 7;
# Terminal cleanup
clear;
# Input UI wrapper
elif [ "${1}" = 'input' ]; then
# Enable interruption inputs
trap 'echo ""; kill -s SIGINT -- $$' SIGINT;
# Interruptible read
export key;
key=$(read -r input; echo "${input}");
# Disable interruption inputs
trap - SIGINT;
# Disable UI wrapper
else
# Terminal restore
tput rmcup;
fi;
}
# === Advanced Development Shell Tools UI Test ===
function __shtoolstestui()
{
# Usage: __shtoolstestui (UI test for the project)
# Variables
local cnt=0;
local key;
# Enable UI wrapper
__shtoolsui 'enable';
__shtoolsui 'start';
# Function header
echo '';
echo -e " \e[1;37m[ Advanced Development Shell Tools - Test ]";
echo '';
# Display test menu
while [ ${cnt} -lt 9 ]; do
# Item choice
cnt=$((cnt + 1));
sleep 0.1;
echo -e " \e[1;33m${cnt}: \e[1;37mItem entry or function \e[1;32m[Content ${cnt}]";
done;
echo '';
# Request user input
echo -en " \e[1;37m> Entry selection [1-${cnt}] : ";
__shtoolsui 'input';
# Display user input
echo '';
echo -en " \e[1;37m< Selected entry '${key}'...";
sleep 2;
# Disable UI wrapper
__shtoolsui 'disable';
}