From 529337424bdef90122e592edb64625c10aa0491c Mon Sep 17 00:00:00 2001 From: taro Date: Fri, 27 May 2022 18:06:59 +0000 Subject: =?UTF-8?q?mejoras=20en=20la=20presentaci=C3=B3n=20de=20mensajes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gab | 36 ++++++++++++++++++++++++++++-------- 1 file 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 - -- cgit v1.2.3