For the past two weeks I was working on PRS terminal emulation. We have managed to get the emulation working to a large extend. Today, I helped the UTS guys with this program which wrote the status of their database sync to the terminal.
There were two issues they were facing.
1. Where to write?
The information has to be on screen when the PRS application runs. However, this can be running on any terminal. So, the programmer does not know if his application is going to run on tty1 or tty6, or even pts1 or pts25.
The solution was simple. I told him to write to /dev/tty. This is because, in Linux, /dev/tty always points to your current terminal. So, if I am in tty5 and do a echo 1 > /dev/tty, it will get echoed on my terminal (tty5). If I go to a virtual terminal like /dev/pts/2 and then do a echo 1 > /dev/tty, it will still appear on my current terminal, because /dev/tty will be pointing to /dev/pts/2!.
2. We need to write only one line that needs to be refreshed always. Other programs will be writing to same terminal but not on our line. How do I send the cursor back to where it was after I write my string?
Answer to this terminal sharing issue came from VT220 emulation commands. When you want to save the current cursor position and the characteristic, you just need to print ESC 7 ("\0337"). After that you can do whatever that you want with the termianl. Then you again write ESC 8 ("\0338") to the screen. It will restore all the settings that was present at the time of sending last ESC 7.
I am still working on a few other issues. Will post here once I find a solution.