CLI Magic: Use ANSI escape sequences to display a clock in your terminal

Posted by Scott_Ruecker on Jan 22, 2008 7:04 PM EDT
Linux.com; By Sergio Gonzalez Duran
Mail this story
Print this story

When I'm in a Linux terminal, I often find myself typing date just to see the time. To make life a bit easier, I wrote a script to always display a clock in the top right corner of the screen. The script saves the current cursor position with an ANSI escape sequence instruction. Then, using the tput command, the cursor is sent to row 0 (the top of the screen) and the last column minus 19 characters (19 is the length of HH:MM:SS YYYY-MM-DD). The formatted date command is displayed in green inverted color. The cursor is then sent back to its original position with another ANSI sequence that restores the original saved position.

Full Story

  Nav
» Read more about: Story Type: News Story; Groups: Linux

« Return to the newswire homepage

This topic does not have any threads posted yet!

You cannot post until you login.