Darned clock watchers!
Brian K. White
brian at aljex.com
Fri Dec 12 04:34:21 PST 2008
----- Original Message -----
From: "Fairlight" <fairlite at fairlite.com>
To: <filepro-list at lists.celestial.com>
Sent: Friday, December 12, 2008 12:21 AM
Subject: Re: Darned clock watchers!
> On Thu, Dec 11, 2008 at 10:44:44PM -0500, Fairlight, the prominent pundit,
> witicized:
>> It really makes a LOT more sense to write a small program like the old
>> BSD
>> 'sysinfo' that would just overlay the time in a small inverse box in the
>> bottom corner of the screen, in like the last 4 characters where fP never
>
> [...]
>
> Actually...one would have to look at the old sysinfo code and find out how
> they got around one little thing. I now have a curses-based program that
> displays the time every 1/10 of a second at the bottom right of the
> screen.
> The only problem is that it gets suspended for tty output if it's
> backgrounded. To work, it has to be the foreground process--which it
> wouldn't be if you wanted to -do- anything with the terminal session.
>
> Now, I -know- for a fact that sysinfo didn't have this issue. I know this
> for certain because I personally used it for over three years, so I'm 100%
> positive that it didn't have concurrency issues.
>
> Alas, I 1) don't have the source at the moment, and 2) even if I did,
> don't
> have time to figure out the workaround at this point. Which is a pity, as
> I actually have the rest of the meat of it done in perl. :)
>
> But I'd love to know how sysinfo did its magic at this point, since it
> technically shouldn't be possible from an article I just read on the tty
> device subsystem (which was actually an interesting read).
>
> Anyway, this solution doesn't appear to be -easily- viable at this point.
> Suggestion withdrawn.
I was thinking of something like this initially before deciding to see if I
could think of an all-in-filepro approach.
I was thinking that you'd have to use something like gnu screen that
effectively becomes a layer between filepro and the actual terminal. From
filepro's point of view, the screen app is the terminal, and the screen app
has the control over the real tty. Then the screen app can overlay things
like the time. Maybe such an overlay/multiplexer app already exists that
lets you combine anything, which would accept the clock data from another
process, or if you have to write the overlayer app yourself then you may
want to have it generate the clock itself
I have no idea if that's how sysinfo did it.
Root at least can write to anyones tty regardless what other apps have
control.
Also I just tested, a user can write to one of their own tty's from another
process even if clerk (suid filepro) currently has the tty.
You could maybe get away with just squirting a tiny message with the ansi
codes to save the cursor, move to the clock position, write the new time,
and restore the cursor.
It might be messy. I don't know how often that would mess up the users
interactive use of the tty.
Maybe it never would if the injected data is all one message, maybe it can
come along at any time and the user couldn't break it, nor should it break
the users traffic as long as the ansi codes included in the clock message
were carefuly chosen. You'd have to save the cursor position and terminal
attributes at least, move cursor, set clock attributes, write time, restore
saved attributes, restor cursor position, ideally wiothout using the nice
easy cusor save/restore ansi codes, since you have no way to know if the
users program is already using the cursor-save right then.
So basically, ignoring my warning about avoiding the easy save/restore codes
for the moment, something like:
... wow this actually works I ended up doing it just to see...
You still have to figure out a nice way to exit. This puts a clock updater
app in the background on the current tty. When the user goes to exit, the
shell will balk at that unless the use the fg or jobs commands to kill the
background clock process.
(ie, exit filepro back to shell, then run "fg 1", then hit ctrl-c, then exit
again to log out.
Anyways, save this script as /usr/local/bin/ctclock:
---TOF---
#!/bin/bash
# ctclock - crude terminal clock
# 20081212 brian at aljex.com
#
# run in background with "ctclock &"
# assumes an ansi-based terminal (linux, scoansi, vt**, xterm, all ok)
#
# <esc>7 = save cursor position & attribs
# <esc>8 = restore cursor position & attribs
# <esc>( = set default font
# <esc>[0m = reset attribs
# <esc>[8m = set hidden
# <esc>[40;33;1m = black bg, yellow fg, bright
# <esc>[25;70f = move cursor to row 25, col 70
BG=0 # background color
FG=3 # foreground color
ROW=25 # clock start position, row
COL=70 # clock start position, column
SLEEP=1 # seconds to sleep between clock display refreshes
[ -z "$tty" ] && { echo "\$tty needs to be provided by /etc/profile" ; exit
1 ;
BG=$((BG+40)) # ansi bg colors are 40-48
FG=$((FG+30)) # ansi fg colors are 30-38
E=`echo -en "\033"` # esc char, because echo -en "\0338" doesn't make esc8
# save cursor position & attributes
# reset attribs to defaults
# set hidden
# move cursor to clock position
# set clock colors
PREFIX=`echo -en
"${E}7${E}[0m${E}[8m${E}[${ROW};${COL}f${E}[${BG};${FG};1m"`
# restore cursor position & attributes
SUFFIX=`echo -en "${E}8"`
# date in fixed format that will always draw the same number of spaces. (10)
# plus the ansi preample and postamble
# unfortunately we can't prevent date from appending a newline,
# so we must use an extra process just to save dates output and
# then echo it seperately without a newline
HMS=" : : "
while echo -en "${PREFIX} ${HMS} ${SUFFIX}" >$tty ;do
sleep $SLEEP
HMS=`date "+%H:%M:%S"`
done
---EOF---
chmod 755 /usr/local/bin/ctclock
then run "ctclock &"
Then do anything else you want, go into filepro etc..
until you log off or manually kill the background process, it continually
writes the time in the bottom-right corner every second, right overtop of
the filepro screen, without interfering with filepro at least in my small
amount of testing. I'm sure it's just a ttiming and statistics game. It's
probably merely _unlikely_ for the script and filepro interfere with each
other very often. And probably occasionally if the user types or filepro
updates at just the wrong time, one or the other may trample each other and
casue junk on the display until the next time filepro redraws.
Now if you reimpliment this in something other than bash, you can probably
make it a lot smaller and more efficient, at the very least avoiding the
need to spawn processes every second just to execute the stand-alone date
binary, and the whole extra shell to run date in, just so I could capture
it's output without a trailing linefeed.
--
Brian K. White brian at aljex.com http://www.myspace.com/KEYofR
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
More information about the Filepro-list
mailing list