473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Question about user interaction with Curses

I have a C++ application that instantiates various instances of the same object (let's call it MainExec) and puts them into a vector. Each instance of a MainExec runs in its own thread. The code was originally written to run only one instance (thread) of the MainExec object and it uses Curses to interact with the user. The Curses session runs on the same physical terminal screen where the program was executed in and is used to read user commands and display output states.

Now that the code is being expanded to run more than one MainExec object at one time I am wondering if it is possible to have each MainExec thread spawn or create/open a new physical terminal screen to launch its Curses session so the user can interact with each instance separately but can also monitor them all at once. So if the program is told to run 4 instances of MainExec then I would like to get 4 different physical terminals on the computer monitor.

Is this possible and does anyone have example code if this is the case?

Thanks.

-Marco
May 15 '09 #1
4 2190
RRick
463 Expert 256MB
Curses appears to work with a single terminal (or tty in unix speak). You can create new windows that sit on top of other windows, but all of these windows use the same tty. With this layered approach, a single program could create threads to deal with each window instance. You would also need some mechanism to switch between windows.

The more common use of curses is a new term program for each window. The only way (I know of) to attach to these windows is by starting a new and separate program with each terminal. Say good-bye to the threaded approach. If there is some program watching all of these processes, you are going to need some way to communicate and that means using interprocess communication like sockets, pipes, files, etc.

In either case, this doesn't sound like a simple thing to do.
May 16 '09 #2
donbock
2,426 Expert 2GB
Do you have the source for this curses? I implemented a version of curses for our embedded product a few years ago and found it wasn't very hard to add in a multiple-tty feature while I was at it.

Does your target operating system support multi-tasking such that each task can have a different stdin/stdout? If so, then spawn off each instance to its own task and redirect stdin/stdout to the appropriate physical terminal screen. As I recall, curses prefers to deal with stdout and stdin.

When you say "new physical terminal screen" do you mean several actual physical monitors?
May 16 '09 #3
Sorry for the late reply. Thanks for taking a look at my question. I am developing on a linux system (RH Enterprise 5, x86) so I can certainly download and modify a copy of curses that I can use for my project. I have very little experience in this so I would appreciate some pointers regarding your suggestion. It also sounds like spawning a task would be an acceptable solution to my problem. I don't have to keep the application multi-threaded, that was just a proof of concept and we can change it if we find a better way. I also have no experience with how task spawning works so if you can point me to some examples or documentation I would really appreciate it.

As far as your last question, when I say "new physical terminal screen" I am not necessarily referring to separate monitors but rather separate windows within X where each window has its own terminal emulator. (Hope this makes sense).

-Marco
May 19 '09 #4
donbock
2,426 Expert 2GB
In curses, a single 'screen' can have multiple 'windows', but each 'window' belongs to exactly one 'screen'.

In traditional curses, the initscr() function initializes the single screen supported by curses based on the TERM environment variable.

I vaguely recall hacking curses in order to add support for multiple screens. I accomplished this by creating a variant of initscr() that accepted an argument. I had to make changes to the data structures to support multiple screen objects. I switched between screens by changing the value of a current-screen global variable -- because the vast majority of the standard functions assume they know which screen you mean.

The other alternative is to spawn off multiple tasks, each with a different TERM environment variable.
May 19 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Edmond Ho | last post by:
Hi, I'm having trouble with a small curses program. I'm associate a pad with a panel. As I understand, a pad is supposed to be just a window with an arbitrary size. That seems to imply that a pad...
0
by: Matthew Alton | last post by:
The appended program freaks python 2.2 & 2.3 completely out. To reproduce the wierdness: i) copy the source to a file called consarn.py ii) $ python consarn.py; iii) the program is now doing a...
0
by: Matt Garman | last post by:
I'd like to write a class or module in python that allows me to do on-the-fly color changing in the curses module. I'm thinking about something along the lines of this: addstr(y, x, 'hello',...
17
by: Materialised | last post by:
Ok, I need some info on how to print in colours to the xterm using c. take a simple program #include <stdio.h> voice main(void) { printf("I want this in colour\n"; return 0; }
23
by: ern | last post by:
I have a program that runs scripts. If the user types "script myScript.dat" the program will grab commands from the text file, verify correctness, and begin executing the script UNTIL... I need...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
0
by: mike.baranski | last post by:
So, can someone tell me why the following code is wrong? When you run it, it will place a . as you arrow key around the screen. Everything works, until you get to the bottom right corner of the...
1
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # #...
5
by: 7stud | last post by:
I can't see to get any y, x coordinates to work with curses. Here is an example: import curses def my_program(screen): while True: ch = screen.getch() if ch == ord("q"): break
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.