[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to have the `initscr '() do NOT clear the screen?

From: jianghu
Subject: Re: how to have the `initscr '() do NOT clear the screen?
Date: Mon, 7 Jul 2008 07:41:19 -0700 (PDT)

Thanks. Understood.

I ever found an interesting bash code from internet (forgot the original
place), which works well in xterm (debian latest lenny). But I am afraid it
is not portable, so I doubt whether the C with ncurses can do the same work.
The script is paste below for reference.

# clock.sh

# the script is executed inside a while without conditions
while :                                                                         
    # time and date are formatted to show HH:MM:SS YYYY-MM-DD
    cmd=`date +"%H:%M:%S %F"`
    # cursor's current position is saved through an escape sequence
    echo -n -e "\033[s"
    # Uncomment the next two lines to clean up the whole first line,
although it causes a lot of blinking
    #tput cup 0 0    # positions on row 0 col 0 (left top corner)
    #tput el         # cleans from position to end of line
    # to place the clock on the appropriate column, subtract the length of
'HH:MM:SS YYYY-MM-DD', which is 19,
    # from the total number of columns
    C=$((`tput cols` - 19))
    tput cup 0 $C    # positions cursor at row 0 col $C
    # clock will be shown green inverted
    # setaf 2 = green, smso = inverted
    COLOR=`tput setaf 2; tput smso`
    # back to normal screen colors
    NORMAL=`tput sgr0`
    # print the time-date output on the above position
    echo -n $COLOR$cmd$NORMAL
    # restore the cursor to whatever was its previous position
    echo -n -e "\033[u"
    # script is executed every second
    sleep 1

Thomas Dickey-2 wrote:
> On Sat, 5 Jul 2008, jianghu wrote:
>> I'd like the initscr() to keep current screen, i.e. when the program
>> using
>> curses library is injected in terminal and the terminal keeps unchanged.
>> The
>> user will not aware of that there is a curses library is called. But I
>> can
>> still use the curses's functions to do some interesting things, for
>> example
>> the program using curses draw a toolbar at the top of the terminal
>> showing
>> some hints (stock info, news, etc) but the user can still use its bash to
>> do
>> his work/development.
>> Who can tell me how to do it? Thanks a lot.
> The 'filter()' function lets you use curses as a single-line.  For the 
> rest - curses won't do that since (to work on _all_ terminals) the 
> assumption was made long ago that the terminal has to be cleared to know 
> what's on the screen.
> -- 
> Thomas E. Dickey
> http://invisible-island.net
> ftp://invisible-island.net
> _______________________________________________
> Bug-ncurses mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-ncurses

View this message in context: 
Sent from the Gnu - Ncurses mailing list archive at Nabble.com.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]