all repos — shlide @ 053dc3e3522f9d9810be4e9b63f776e2eb7e7189

slide deck presentation tool written in pure bash

filter out color codes in length calculation
Akshay nerdypepper@tuta.io
Sun, 02 Feb 2020 23:45:54 +0530
commit

053dc3e3522f9d9810be4e9b63f776e2eb7e7189

parent

ba338addd65b689b8921f7553cceeae37b3a4187

1 files changed, 22 insertions(+), 9 deletions(-)

jump to
M shlideshlide

@@ -5,13 +5,13 @@ # Each slide is a textfile under path/to/slides

# Color definitions -BLK="\e[30m" -RED="\e[31m" -GRN="\e[32m" -YLW="\e[33m" -BLU="\e[34m" -PUR="\e[35m" -CYN="\e[36m" +BLK="\e[38;5;30m" +RED="\e[38;5;31m" +GRN="\e[38;5;32m" +YLW="\e[38;5;33m" +BLU="\e[38;5;34m" +PUR="\e[38;5;35m" +CYN="\e[38;5;36m" RST="\e[0m" lines() {

@@ -27,6 +27,17 @@ done < "$1"

printf '%s\n' "$max" } +colorify() { + eval "declare dummy=\"$1\"" + printf '%b' "$dummy" +} + +shopt -s extglob +ansi_filter() { + local IFS= + echo "${1//$'\e'[\[(]*([0-9;])[@-n]/}" +} + display() { # 1 - slide contents # 2 - slide name

@@ -62,13 +73,15 @@ while IFS= read -r line; do

reduce=0 # Print the contents of the slide file, # line by line. - printf "%s" "$line" + l=$(colorify "$line") + printf '%s' "$l" case $line in "" | *"\n"*) ((++reduce));; esac # Move down and back after each print. - printf '\e[%sD\e[B' "$((${#line} - $reduce))" + l=$(ansi_filter "$l") + printf '\e[%sD\e[B' "$((${#l} - $reduce))" done <<< "$slide_contents" }