#!/bin/sh #---------------------------------------------------------------------------- # /usr/local/bin/techo - table echo # # Creation: 2004-08-20 max # Last Update: $Id$ # # Copyright (c) 2004-2007 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # usage #---------------------------------------------------------------------------- # # techo [-tty|-html|-file] [-std|-info|-warn|-error] begin width width ... # techo [-tty|-html|-file] [-std|-info|-warn|-error] row [-std|-info|-warn|-error] message ... # techo [-tty|-html|-file] [-std|-info|-warn|-error] end # # options: # -tty use console colors # -html use html tags for colors # -file don't use any color tags # # message-options: # -std print standard message (default) # -info print info message # -warn print warning message # -error print error message # # example: # techo begin 3 3r 15 10 28* 20 # techo row "" 1 foo foo "This is a somehow longer text, since i need a very long line of text" foo # techo row "->" 2 -info "bar foo" -warn "foo bar" foo # techo row "" 12 foofoo foo foo -error foobar # techo -info row "" 24 foo foobar foo -error foobar # techo end # #---------------------------------------------------------------------------- #============================================================================ # main #============================================================================ techo () { _techo_opt='STD' _techo_mode="$_EISLIB_PRINTMODE" _techo_call='' _techo_colors='' while [ 1 ] do case "$1" in -std) _techo_opt='STD'; shift;; -info) _techo_opt='INFO'; shift;; -warn) _techo_opt='WARN'; shift;; -error) _techo_opt='ERROR'; shift;; -tty) _techo_mode=tty; shift;; -html) _techo_mode=html; shift;; -file) _techo_mode=file; shift;; *) break;; esac done _techo_mode2=`echo $_techo_mode | tr 'a-z' 'A-Z'` case "$1" in begin|row|end) _techo_call=$1; shift;; *) _techo_call='row';; esac case "$_techo_call" in begin) _techo_total=0 _techo_total_variable=0 for _techo_width in `echo "$*" | tr -d 'rl'` do case "$_techo_width" in *'*'*) let _techo_total_variable+=`echo "$_techo_width" | tr -d '*'` esac let _techo_total+=`echo $_techo_width | tr -d '*'` done if [ $_techo_total -gt 80 ] then mecho -$_techo_mode -error "You cannot use techo with more than 80 columns." exit 255 fi _techo_width_factor=100 if [ $_EISLIB_SCREENSIZE_X -gt 80 -a $_techo_total_variable -gt 0 ] then let _techo_width_factor=($_EISLIB_SCREENSIZE_X-80)*100/$_techo_total_variable+100 fi ;; esac if [ "$_techo_mode" = "tty" -o "$_techo_mode" = "file" ] then case "$_techo_call" in begin) eval _techo_pre='$'_EISLIB_COLOR_${_techo_mode2}_PRE eval _techo_post='$'_EISLIB_COLOR_${_techo_mode2}_POST eval _techo_reset='$'_EISLIB_COLOR_${_techo_mode2}_RESET _techo_column=1 while [ $# -gt 0 ] do case "$1" in *r*) _techo_align='';; *) _techo_align='-';; esac _techo_width=`echo "$1" | tr -d 'rl*'` case "$1" in *'*'*) let _techo_width=$_techo_width*$_techo_width_factor/100;; esac let _techo_width-- # generates pre-formatet string # ...%b...%-7.7s... eval _EISLIB_TECHO_${_techo_column}='${_techo_pre}%b${_techo_post}%${_techo_align}${_techo_width}.${_techo_width}s${_techo_reset}\ ' let _techo_column++ shift done ;; row) _techo_column=1 _techo_mask=$_EISLIB_TECHO_1 while [ $# -gt 0 -a "$_techo_mask" != "" ] do case $1 in -info) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_INFO; shift;; -warn) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_WARN; shift;; -error) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_ERROR; shift;; -std) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_STD; shift;; *) eval _techo_colors='$'_EISLIB_COLOR_${_techo_mode2}_${_techo_opt};; esac printf "${_techo_mask}" "$_techo_colors" "$1" let _techo_column++ eval _techo_mask='$'_EISLIB_TECHO_${_techo_column} shift done echo ;; end) _techo_column=1 _techo_mask=$_EISLIB_TECHO_1 while [ "$_techo_mask" != "" ] do unset _EISLIB_TECHO_${_techo_column} let _techo_column++ eval _techo_mask='$'_EISLIB_TECHO_${_techo_column} done ;; esac elif [ "$_techo_mode" = "html" ] then case "$_techo_call" in begin) echo "
" printf "${_EISLIB_COLOR_HTML_PRE}%s${_EISLIB_COLOR_HTML_POST}%s${_EISLIB_COLOR_HTML_RESET}" "$_techo_colors" "$1" echo " | " shift done echo "