You are here

Risharde's Blog

TPUT COLOR COMMANDS FOR BASH TEXT COLOR

Found this somewhere on Stackoverflow:

Colour commands
tput setab [1-7] # Set the background colour using ANSI escape
tput setaf [1-7] # Set the foreground colour using ANSI escape
Colours are as follows:

Num Colour #define RGB

0 black COLOR_BLACK 0,0,0
1 red COLOR_RED max,0,0
2 green COLOR_GREEN 0,max,0
3 yellow COLOR_YELLOW max,max,0
4 blue COLOR_BLUE 0,0,max
5 magenta COLOR_MAGENTA max,0,max
6 cyan COLOR_CYAN 0,max,max
7 white COLOR_WHITE max,max,max
There are also non-ANSI versions of the colour setting functions (setb instead of setab, and setf instead of setaf) which use different numbers, not given here.

Text mode commands
tput bold # Select bold mode
tput dim # Select dim (half-bright) mode
tput smul # Enable underline mode
tput rmul # Disable underline mode
tput rev # Turn on reverse video mode
tput smso # Enter standout (bold) mode
tput rmso # Exit standout mode
tput sgr 0 # Reset all attributes
Cursor movement commands
tput cup Y X # Move cursor to screen postion X,Y (top left is 0,0)
tput cuf N # Move N characters forward (right)
tput cub N # Move N characters back (left)
tput cuu N # Move N lines up
tput ll # Move to last line, first column (if no cup)
tput sc # Save the cursor position
tput rc # Restore the cursor position
tput lines # Output the number of lines of the terminal
tput cols # Output the number of columns of the terminal
Clear and insert commands
tput ech N # Erase N characters
tput clear # Clear screen and move the cursor to 0,0
tput el 1 # Clear to beginning of line
tput el # Clear to end of line
tput ed # Clear to end of screen
tput ich N # Insert N characters (moves rest of line forward!)
tput il N # Insert N lines
Other commands
tput bel # play a bell
With compiz wobbly windows, the bel command makes the terminal wobble for a second to draw the user's attention.

Example usage

echo "$(tput setaf 1)Red text $(tput setab 7)and white background$(tput sgr 0)"
Looks like this on my Ubuntu terminal:

Screenshot of colour terminal text

Use command sgr 0 to reset the colour at the end.

Performing multiple operations at once

tput accepts scripts containing one command per line, which are executed in order before tput exits.

Avoid temporary files by echoing a multiline string and piping it:

echo -e "setf 7\nsetb 1" | tput -S # set fg white and bg red

When work became work

Today, is my first day official home after resigning from my job. It's really astonishing to literally FEEL how much time I've gotten back by just not having to fight to beat the traffic to Port of Spain and well work itself. So what can I say from my experience without breaking contractual privacy / confidentiality agreements. Well, let's start where work became work. I know this sounds like I've made a typographical error but it isn't. One reason for pursuing my tertiary education in Computer Science was because I am truly passionate about Information Technology. Doing "I.T" has been turned from second into first nature for me, it is who I am. People in the work place really get confused when I haven't heard about a piece of technology that they know about - as if to say that someone in I.T MUST KNOW THE ENTIRE WORLD OF I.T.

So coming back to my topic about when work became work. I.T has always been the fun part for me, both in and out of work. In work though, I.T became "work" as opposed to a "job". You see, a job is technically work BUT some people actually LIKE their jobs. So a job is like 1 + 1 = 2 in math. The work I am referring to is when its no longer really a job that you like but really just perhaps a frustration. Getting down deeper into how I feel, I'd say that work was once fun and enjoyable but then circumstances changed (as it naturally does) but in an unnatural way. I had to deal with people who thought they knew I.T and further more, people who would say a few sentences and think that one could build the actually solution within the same time it took for them to say some sentences.

For example: Let there be a house, and there was a house....

Obviously, only God could do such miracles... or so I would imagine.
As I further stated, it became work when I had to really explain I.T to people who couldn't understand it but think that they do. Of course, I'm not saying I'm perfect but why hire someone (with experience and knowledge) and then don't take their advice. So essentially, work became literally work... the joy and fun of having a job was lost and thank God I have the resources to quit. I really do feel sorry for those of you out there who are not in a position to quite your miserable works - I really genuinely do feel sorry. Life isn't fair and the work world is worse than life, its hell.

Stay strong my friends.

Lightweight Torrent Client for Raspberry Pi or any other linux distro

I came across an article which explained in detail how to set up a light weight torrent client called Deluged. I think it might help someone out there that has a Raspberry PI or linux distro with only command line access:

http://www.howtogeek.com/142044/how-to-turn-a-raspberry-pi-into-an-alway...

From the tests ran on deluged, it seems it only uses about 12MB of RAM which is absolutely awesome!

Deluged crashing and Libtorrent on the Raspberry Pi - Solution

Okay so I've been really working my new Raspberry Pi Model B and I encountered a problem with deluged (a torrent client) which apparently uses libtorrent. Now according to my research, there is a known problem with deluged and libtorrent 0.15 which really makes me wonder the sanity of the raspbian developer community. Shouldn't they be bundling the libtorrent 0.16 version instead to maintain stability? Anyways, I read that you can compile your own libtorrent 0.16 so I decided that I'd do just that - WHAT A TASK - You'll need to install a lot of dependencies to get this to work properly!

Here goes:
First thing we need to do is make sure the dependencies are installed

sudo apt-get install libssl-dev
sudo apt-get install libboost-dev
sudo apt-get install libboost-system1.50-dev

#Then we need to download the libtorrent-rasterbar-0.16.5 source code. This takes FOREVER to compile, about 5 hours on PI! Man does the raspberry pi need a faster CPU!

wget http://libtorrent.googlecode.com/files/libtorrent-rasterbar-0.16.5.tar.gz
tar xvzf libtorrent-rasterbar-0.16.5.tar.gz
cd libtorrent-rasterbar-0.16.5
./configure --enable-python-binding
make
checkinstall
sudo make install

ldconfig -v | grep libtorrent

python -c "import libtorrent as lt; print lt.version"

Text To Speech (TTS) / Speech Synthesis with the Raspberry PI Model B

First, set up your webcam or usb microphone to get commands

Plug in your USB microphone. Let’s open up an ALSA configuration file in vim:

sudo nano /etc/modprobe.d/alsa-base.conf

Change the following line:

options snd-usb-audio index=-2

To this:

options snd-usb-audio index=0

Install SoX which is used for playback and not Text to Speech (very useful tool to playback wave files)

sudo apt-get install sox

Also, if you have already set up a microphone as main device, you need to set playback device for Sox to output to the raspberry audio jack:

export AUDIODEV=hw:1,0

THIS IS WHERE TEXT TO SPEACH COMES IN: THAT IS, TEXT CONVERTED INTO AUDIO FOR PLAYBACK

#Install Festival

sudo apt-get install festival

echo “Hello World” | festival --tts

hostname -I | festival --tts

# or install espeak

sudo apt-get install espeak

espeak -ven+f3 -k5 -s150 "Hello World"

# or Google Android TTS - PICO

sudo apt-get install libttspico-utils

pico2wave -w helloworld.wav "Hello World" && aplay helloworld.wav

Raspberry PI - Raspbian Static IP Address

auto lo

iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.50

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

END OF FILE
COMMENTS: Typically, most router are set by default to 192.168.1.1 so if 192.168.1.50, try 192.168.1.1

Pages