"Real-Time" Time Display in Console

"Real-Time" Time Display in Console

Post by Adam The » Wed, 04 Oct 2000 04:00:00



hi. i have been able to write a simple program that displays the
current time, formatted to how i want, using 'strftime' from the
console. i've played around with it, and no problems.

however, i am now wanting to get a similar result in the console, but
have the displayed time constantly updating. "real-time", so to speak,
instead of just displaying the time of the program's execution.

is there anyway to get this done, so i can have the time displayed
constantly in a console? if not console, could someone point me in the
right direction to doing this in a GUI, X Windows System interface?

thanks all.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

"Real-Time" Time Display in Console

Post by James T. Denni » Thu, 05 Oct 2000 04:00:00



> hi. i have been able to write a simple program that displays the
> current time, formatted to how i want, using 'strftime' from the
> console. i've played around with it, and no problems.
> however, i am now wanting to get a similar result in the console, but
> have the displayed time constantly updating. "real-time", so to speak,
> instead of just displaying the time of the program's execution.
> is there anyway to get this done, so i can have the time displayed
> constantly in a console? if not console, could someone point me in the
> right direction to doing this in a GUI, X Windows System interface?
> thanks all.

 Curses.  To do this you want to get the appropriate escape
 sequences to control your terminal's cursor.  (Your Linux console is
 controlled primarily via a terminal compatible abstraction; it
 is treated by the system as a set of independent "virtual terminals").

 At a minimum you need to know how to perform a destructive backspace
 so that you can do something like:

        Wed 4 Oct 2000 01:11:49    << print time
        Wed 4 Oct 2000 01:11:      << two backspaces
        Wed 4 Oct 2000 01:11:50    << print new digits
        Wed 4 Oct 2000 01:11:5     << one backspace
        Wed 4 Oct 2000 01:11:51    << replace last digit

                ... repeat that last for next 9 seconds,
                then backspace 4 characters and print 01:12:00
                etc.

 That's the basics.  In a shell you could look some for these
 using the tput command.  For example:

        #!/bin/sh
        bs=$(tput cub1)  # Read the tput(1) and terminfo(4) man pages
        x=0

        while [ "$x" -lt 10 ] ; do
                echo -n $x; sleep 1; echo -n "$bs"
                done

 Should work (as a simple example).

 
 
 

"Real-Time" Time Display in Console

Post by The Ghost In The Machi » Fri, 06 Oct 2000 04:00:00


In comp.os.linux.development.apps, James T. Dennis

 wrote
on 4 Oct 2000 08:40:46 GMT


>> hi. i have been able to write a simple program that displays the
>> current time, formatted to how i want, using 'strftime' from the
>> console. i've played around with it, and no problems.

>> however, i am now wanting to get a similar result in the console, but
>> have the displayed time constantly updating. "real-time", so to speak,
>> instead of just displaying the time of the program's execution.

>> is there anyway to get this done, so i can have the time displayed
>> constantly in a console? if not console, could someone point me in the
>> right direction to doing this in a GUI, X Windows System interface?

>> thanks all.

> Curses.  To do this you want to get the appropriate escape
> sequences to control your terminal's cursor.  (Your Linux console is
> controlled primarily via a terminal compatible abstraction; it
> is treated by the system as a set of independent "virtual terminals").

> At a minimum you need to know how to perform a destructive backspace
> so that you can do something like:

>    Wed 4 Oct 2000 01:11:49    << print time
>    Wed 4 Oct 2000 01:11:      << two backspaces
>    Wed 4 Oct 2000 01:11:50    << print new digits
>    Wed 4 Oct 2000 01:11:5     << one backspace
>    Wed 4 Oct 2000 01:11:51    << replace last digit

>            ... repeat that last for next 9 seconds,
>            then backspace 4 characters and print 01:12:00
>            etc.

As I understand (n)curses, it will do a "minimal update", which means
that one can simply do a call to ctime(), use printw() or mvprintw(),
refresh(), sleep for a second, then repeat.  Curses will only update
those characters that actually changed -- an issue that may seem a bit
anachronistic now, but was presumably a Godsend in the days of
300-baud modems.

One problem with this is that curses will clear the screen upon
initialization, so all one will see is an updating clock
(unless one implements additional stuff, such as a marquee, ad
banner, scrollable text region for reading a book, input form
system, etc.) There are aso some issues regarding keyboard
responsiveness; I'd frankly have to experiment to see what I can
do regarding getch(), if one can get stdscr to return a file
descriptor (or just be crufty and use standard input -- 0 --
in a select() call, which should work fine unless one uses newterm()
instead of initscr()).

'man ncurses' for a starting point, at least on RedHat systems.
It's an interesting, if primitive, environment. :-)

'man select' for details on the select call, which can wait for
a number of sockets and pipes to retrieve data, along with a
timeout specifiable in milliseconds -- perfect for a clock which
needs keyboard input. :-)

Quote:> That's the basics.  In a shell you could look some for these
> using the tput command.  For example:

>    #!/bin/sh
>    bs=$(tput cub1)  # Read the tput(1) and terminfo(4) man pages
>    x=0

>    while [ "$x" -lt 10 ] ; do
>            echo -n $x; sleep 1; echo -n "$bs"
>            done

> Should work (as a simple example).

Yes, that should work reasonably well.

--

 
 
 

"Real-Time" Time Display in Console

Post by Adam The » Fri, 13 Oct 2000 04:00:00


thank you all for your help both on the newsgroup and in sending me
suggestions through email. i've archived all the help, and can see some
uses for it in the future. i have read through the ncurses manual, and
looked into Tcl. all of which looks too complicated for me right now.

i have decided to use a static time/date display (what i have now), but
just have it easily refresh/redisplay upon a simple command from the
console and redisplay at every opportunity.

i'm saving the shell code and suggestions, since i can see how it will
be very useful when it comes time to expand he program. but at this
time i want to keep the program as complex as my programming skills
are, which is "simple".

if anyone wants, i will notify them when i have a stable, featured
version of the program, which is a clock display, alarm clock, stop
watch/ and countdown timer in one for *nix systems. at first it will
just be console-based, but i will add a GUI to it eventually, once the
features i want in it are there. just email me at

theoretic.com one only after a few days though, since i am just setting
it up now).

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

1. Solaris2.0/2.1 Real time "Fast" timing/scheduling

Hi,
I am porting an application that requires very fine
timing control to Solaris 2.0/2.1. I need to be able to schedule
my program at given time increments. The time increment can be
anywhere from 1 millisecond to 50 milliseconds. I gave played
with setitimer and SIGALRM , they do work fine except I can not
get better than 10 millisecond granularity. So I decided
to try something more hardware oriented and noticed that there are
2 timer/counters in the MMU chip.
Questions:

1) Does the OS use either or both of these counters?
2) Are there other timers available on the Sparc platform?
3) Does the equation change if I use a VME based SparcEngine?
4) Does/Has anybody done/? any work in this area and give me some
   pointers?
5) Are there other calls in Solaris 2.0 and derivatives that would
   allow me to what I am trying to do ????

Thanx for any and all answers/pointers/criticism/etc...
Sinan Karasu

2. Boot to a Parallel Zip Drive?

3. How does "Time Synch Protocol" relate to "Network Time Protocol"?

4. HP Pavilion Keyboard "fix"

5. Configuring Second SGI Ethernet Interface for "Real-Time"

6. Any unix programmers? How does execve work?

7. "Hands-On Embedded and Real-Time Linux" course by uc berkeley extension?

8. eth0: XMT status = 0x400 HELP!!!

9. Since when UNIX is the "real" system that runs the "real" machines?

10. "Real time" programming in Unix

11. How do you do "real time" audio with kaudioserver?

12. "Listening" to remote X session at real time

13. [RESEND] Don't ask about "Enhanced Real Time Clock Support" on some archs