LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2003, 02:35 PM   #1
hfawzy
Member
 
Registered: Aug 2002
Location: Egypt
Distribution: Debian Sarge, Slackware 10.0
Posts: 163

Rep: Reputation: 30
drawtext


Hi,
I've just made a function called drawtext using bash that gives styles to the text (colors,bold,underline).
For example, instead of writing :
Code:
echo -e "\E[34;40m\033[1m\Hello world"; tput sgr0
You can simply write :
Code:
drawtext "Hello world" blue bold
I thought that it might be useful..
Anyway, here is the code :
Code:
#!/bin/bash
# Author : Al Hussein Fawzi (hfawzy)
# Name : Drawtext

function drawtext {

#INITIALIZE COULOUR VARIABLES

declare bold="\033[1m"
declare underline="\033[4m"
declare blue='\E[34;40m'
declare red='\E[31;40m'
declare yellow='\E[33;40m'
declare green='\E[32;40m'


	if [ $# -le 1 ] || [ $# -ge 4 ] 
	then	
		echo "Usage:drawline "text" style color"
		echo "Styles: bold and underline"
		echo "Colors: red,yellow,blue,green"
	else
	case $3 in
		"blue")
			if [ "$2" == bold ] 
			then
				echo -e "$blue$bold$1"; tput sgr0
			else
				echo -e "$blue$underline$1"; tput sgr0
			fi
		;;

		
		"red")
			if [ "$2" == bold ] 
			then
				echo -e "$red$bold$1"; tput sgr0
			else
				echo -e "$red$underline$1"; tput sgr0
			fi
		;;
		"yellow")
			if [ "$2" == bold ] 
			then
				echo -e "$yellow$bold$1"; tput sgr0
			else
				echo -e "$yellow$underline$1"; tput sgr0
			fi
		;;
		"green")
			if [ "$2" == bold ] 
			then
				echo -e "$green$bold$1"; tput sgr0
			else
				echo -e "$green$underline$1"; tput sgr0
			fi
		;;
		*)
				if [ "$2" == bold ]
				then
					echo -e "$bold$1";tput sgr0
					
				elif [ "$2" == underline ]
				then
					echo -e "$underline$1"; tput sgr0	
				elif [ "$2" == blue ]
				then
					echo -e "$blue$1"; tput sgr0
				elif [ "$2" == red ]
				then
					echo -e "$red$1"; tput sgr0
				elif [ "$2" == green ]
				then
					echo -e "$green$1"; tput sgr0
				elif [ "$2" == yellow ]
				then
					echo -e "$yellow$1"; tput sgr0				
				fi
		;;
	esac
fi
}
Any comments/suggestions will be welcome.
hfawzy

Last edited by hfawzy; 02-08-2003 at 02:40 PM.
 
Old 02-13-2003, 07:06 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977
not bad... i never deviate from black and white.. but looks useful...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration