Simple, Two-Frame Terminal Application

B

Bryan Richardson

Hello All,

I am in need of a way to develop a simple, two-frame terminal
application that can display event-driven data in one frame and allow
for the input of commands in a different frame. Without having to go to
the extremes of something like ncurses, does anyone know of a way to do
this? Nothing fancy is needed like CTRL key bindings and such, just two
simple frames.
 
J

John Morrice

I am in need of a way to develop a simple, two-frame terminal
application that can display event-driven data in one frame and allow
for the input of commands in a different frame. Without having to go
to the extremes of something like ncurses, does anyone know of a way
to do this? Nothing fancy is needed like CTRL key bindings and such,
just two simple frames.

What about having two processes that communicate over DRb, and use
screen to put them in different frames?

screen has an -X switch which you can use to send commands to the
currently running screen (like split, focus etc)

My project, CARPS, needs to do this because it currently has no GUI, but
to be cross platform, it allows the user to specify a command which
wraps the subprocess (ie, start /wait %cmd, if you are on windows)

John
 
R

Rahul Kumar

There are other options too:

Are you on a unix/osx or on Windows ?

1. Have 2 threads. One takes user input, and another displays or does
work.
I;ve done a small program like this that plays music while giving me a
prompt so user can pause, halt etc.

If your work is not in the background, then you don't need threads. You
can position the cursor using system("tput cup"). You would do this for
always taking input on top or bottom line. Not clean but it works.


2. Another simple option is to use Liveconsole. You can open another
terminal window and pass commands on the prompt (an irb prompt).
Liveconsole gives you samples, its very easy.
 
J

John Morrice

If your work is not in the background, then you don't need threads.
You can position the cursor using system("tput cup"). You would do
this for always taking input on top or bottom line. Not clean but it
works.

Ace, cheers for the tidbit! I've never seen that before. Time to make
some more lolsome text-based programs :)
 
B

Bryan Richardson

Hi Rahul,

Thanks for responding. I like your option 1 with threading... how can I
get my terminal split up such that one thread can be displaying data in
one section of the terminal and the other thread can be waiting for
input in another section of the terminal? Does your suggestion of using
tcup apply here as well, or is there a "cleaner" way to do it?

Oh, and I am on Linux.
 
M

Matt Lawrence

Hi Rahul,

Thanks for responding. I like your option 1 with threading... how can I
get my terminal split up such that one thread can be displaying data in
one section of the terminal and the other thread can be waiting for
input in another section of the terminal? Does your suggestion of using
tcup apply here as well, or is there a "cleaner" way to do it?

Oh, and I am on Linux.

I've always used ncurses for that. I found the book "Unix Programming
with Curses" to be useful and entertaining when people see it...

-- Matt
It's not what I know that counts.
It's what I can remember in time to use.
 
B

Bryan Richardson

Yeah, I just haven't found the documentation for Ruby's ncurses
bindings to be very helpful at all, and for something as simple as I'm
wanting to do I was hoping there was a simpler alternative. Oh well,
maybe this is a good, simple entry level program to get my feet wet
with ncurses.
 
J

John Morrice

Yeah, I just haven't found the documentation for Ruby's ncurses
bindings to be very helpful at all, and for something as simple as I'm
wanting to do I was hoping there was a simpler alternative. Oh well,
maybe this is a good, simple entry level program to get my feet wet
with ncurses.

Have you read the C documentation? IMO ncurses is lovely! It's
off-topic but I wrote a stupid platform game with curses in haskell.
Have fun!

John
 
R

Rahul Kumar

Bryan Richardson wrote in post #962617:
Hi Rahul,

Thanks for responding. I like your option 1 with threading... how can I
get my terminal split up such that one thread can be displaying data in
one section of the terminal and the other thread can be waiting for
input in another section of the terminal? Does your suggestion of using
tcup apply here as well, or is there a "cleaner" way to do it?
In my case, the terminal was not split up. I would use the last row for
inputting user commands, and display on top. Yes, that requires me to
position the cursor using tput cup, and also to clear the line first, so
the previous command is erased.

I also used readline, so that the user can search or reuse previous
commands. The cleaner way perhaps is the screen option someone else
mentioned (which i have not used yet). Best would be to use ncurses or
ffi-ncurses.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top