summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortaro <taro>2022-05-27 18:06:59 +0000
committertaro <taro>2022-05-27 18:06:59 +0000
commit529337424bdef90122e592edb64625c10aa0491c (patch)
treeb388c677664b717915a33281f7821df667a4d52e
parent6bb6aed5a0b34389a4f2cb8fc13a697904186f33 (diff)
downloadgab-529337424bdef90122e592edb64625c10aa0491c.tar.gz
mejoras en la presentación de mensajes
-rwxr-xr-xgab36
1 files changed, 28 insertions, 8 deletions
diff --git a/gab b/gab
index f78bc4a..77e613e 100755
--- a/gab
+++ b/gab
@@ -23,7 +23,7 @@ GAB_DEBUG=0
[[ $GAB_DEBUG -eq 0 ]] && GAB_LOG=/var/gab/chatlog.txt || GAB_LOG="$HOME/chatlog.txt"
-TITLE="GAB v1.1 'Mirá mamá, sin comillas!!'"
+TITLE="GAB v1.2 'Ese formato sí se puede ver!!'"
LAST_MSG_DATE=$(date -r $(stat -f %m $GAB_LOG))
@@ -36,6 +36,7 @@ then
exit 1
fi
+
# https://github.com/dylanaraps/pure-sh-bible#trim-leading-and-trailing-white-space-from-string
trim_string() {
# Usage: trim_string " example string "
@@ -53,18 +54,38 @@ trim_string() {
printf '%s\n' "$trim"
}
+
# Acá está la función que formatea las líneas y las imprime por pantalla
# todas las cuestiones relacionadas con modificación de apariencia de la salida
# de los mensajes debería ir por acá
# https://github.com/dylanaraps/pure-sh-bible#parsing-a-keyval-file
output_beautiful_messages(){
+ last_user=''
+ COLUMNS=$( tput cols )
+ width=$(echo "$COLUMNS * 0.85" | bc | cut -d'.' -f1)
while IFS="$SEPARATOR" read -r user message; do
- printf '\033[7m\033[1m %s\033[0m%s\n' "$user" "$message"
- echo '- - -'
+ if [[ "$last_user" != "$user" ]]
+ then
+ last_user="$user"
+ print_username "$user"
+ fi
+ print_message "$message" "$width"
done
}
+
+print_username(){
+ printf '\033[7m\033[1m %s\033[0m\n' "$1"
+}
+
+
+print_message(){
+ echo " $1" | fmt $2
+}
+
+
+
# Imprime las últimas n líneas del log de mensajes
# parámetro 1 es la cantidad de líneas a leer
# parámetro 2 es el path del archivo a leer
@@ -117,7 +138,7 @@ then
output_last_messages
else
case "$1" in
- -m | --msg)
+ -m | --msg)
if [ -z "$2" ]
then
echo "Debe incluir un mensaje"
@@ -126,7 +147,7 @@ else
add_message ${@:2}
fi
;;
- -l | --log)
+ -l | --log)
if [ -z "$2" ]
then
output_last_messages
@@ -138,15 +159,14 @@ else
exit 1
fi
;;
- -h | --help)
+ -h | --help)
echo "$HELP_TEXT"
exit 0
;;
- *)
+ *)
echo "Opción desconocida $1"
echo "$HELP_TEXT"
exit 1
;;
esac
fi
-
Un proyecto texto-plano.xyz