Available to Download Now!
Bash Console Colours for C++
Here’s a little header file for C/C++ that I knocked up to make colouring console output a little easier. Not all of these colour codes are supported by every console emulator, but if you stick to the primary colours, you should be fine.
File: shellColours.h
//// Foreground Colours ////
# define SH_FG_BLACK "\033[0;30m"
# define SH_FG_BLUE "\033[0;34m"
# define SH_FG_GREEN "\033[0;32m"
# define SH_FG_CYAN "\033[0;36m"
# define SH_FG_RED "\033[0;31m"
# define SH_FG_PURPLE "\033[0;35m"
# define SH_FG_YELLOW "\033[0;33m"
# define SH_FG_LIGHT_GREY "\033[0;37m"
# define SH_FG_DARK_GREY "\033[1;30m"
# define SH_FG_LIGHT_BLUE "\033[1;34m"
# define SH_FG_LIGHT_GREEN "\033[1;32m"
# define SH_FG_LIGHT_CYAN "\033[1;36m"
# define SH_FG_LIGHT_RED "\033[1;31m"
# define SH_FG_LIGHT_PURPLE "\033[1;35m"
# define SH_FG_LIGHT_YELLOW "\033[1;33m"
# define SH_FG_WHITE "\033[1;37m"
//// Background Colours ////
# define SH_BG_BLACK "\033[0;40m"
# define SH_BG_BLUE "\033[0;44m"
# define SH_BG_GREEN "\033[0;42m"
# define SH_BG_CYAN "\033[0;46m"
# define SH_BG_RED "\033[0;41m"
# define SH_BG_PURPLE "\033[0;45m"
# define SH_BG_YELLOW "\033[0;43m"
# define SH_BG_LIGHT_GREY "\033[0;47m"
# define SH_BG_DARK_GREY "\033[1;40m"
# define SH_BG_LIGHT_BLUE "\033[1;44m"
# define SH_BG_LIGHT_GREEN "\033[1;42m"
# define SH_BG_LIGHT_CYAN "\033[1;46m"
# define SH_BG_LIGHT_RED "\033[1;41m"
# define SH_BG_LIGHT_PURPLE "\033[1;45m"
# define SH_BG_LIGHT_YELLOW "\033[1;43m"
# define SH_BG_WHITE "\033[1;47m"
//// Others ////
# define SH_DEFAULT "\033[0m"
# define SH_UNDERLINE "\033[4m"
# define SH_BLINK "\033[5m"
# define SH_INVERSE "\033[7m"
# define SH_CONCEALED "\033[8m"
And here’s how to use it. Note that you’ve got to set the colours back to default at the end of the sequence.
File: shellColoursTest.cpp
# include "../shellColours.h"
# include
using namespace std;
int main (){
cout < < SH_FG_BLUE <<"Foreground Blue" << SH_DEFAULT << endl;
cout << SH_BG_GREEN <<"Background Green" << SH_DEFAULT << endl;
cout << SH_UNDERLINE <<"Text Underlined" << SH_DEFAULT << " Back To Normal Text" << endl;
}
Crontab Debugging
Sometimes, a script which works perfectly fine when run from the shell, fails when run as a cron job. It’s often quite difficult to debug these problems, but to make the task a little easier, try this.
Edit the crontab file with
crontab -e
Add this line for your script (obviously change the script path and username)
*/5 * * * * /usr/bin/myscript >~username/crontab.out 2>~username/crontab.err
This will run your script every 5 minutes, and send outputs to two files. Standard output will go to contab.out and errors will go to crontab.err.
If you want to use a different editor run the following, then start over.
EDITOR=/path/to/editor
export EDITOR
CSS Pop-Out Rollovers
Here’s how to acheive the appearence of text popping out as you hover over it with your mouse. It’s a simple effect that can be acheived with nothing more than a little CSS. I’ve used this on the title’s of each blog post, but I also think it looks quite effective in lists, like in the Categories section in the sidebar.
All you need is the following code in your style sheet.
a:hover {text-spacing: 1px; padding-left: -3px;}
Obviously, adjust the figures to taste.
This will work in all browsers, as long as its applied to the anchor (a) element, IE6 doesn’t recognise the :hover pseudo class when applied to other objects.
Hello!
My name is Craig, I live in Leicester and I do work in IT. I like to draw, eat sandwiches and fold paper. more...
Flickr
Search
Categories
- Android (1)
- Astronomy (1)
- Atheism (3)
- Comment (7)
- Environment (1)
- Evolution (1)
- Government (1)
- Internet (2)
- Linux (4)
- MSc (1)
- Papercraft (15)
- Photos (2)
- Programming (4)
- Psychology (5)
- Questions (2)
- Robots (2)
- Science (4)
- Sculpture (3)
- Software (8)
- Tutorials (3)
- Uncategorized (3)
- WebApps (3)