473,804 Members | 3,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about user interaction with Curses

29 New Member
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 2210
RRick
463 Recognized Expert Contributor
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 Recognized Expert Top Contributor
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
meLlamanJefe
29 New Member
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 Recognized Expert Top Contributor
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
4382
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 can be treated like a normal window when working with panels. I have this code: #!/usr/bin/env python import curses import curses.panel
0
1776
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 getch(); iv) hit a key; v) the program locks up, the interptreter is now munching on the CPU; vi) kill the interpreter from another shell; vii) scratch head and wonder why neither of the mutually exclusive clauses in the _io() member function...
0
1890
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', brightyellow, blue) The module would automatically interpret the above as curses.init_pair(i, curses.COLOR_YELLOW, curses.COLOR_BLUE)
17
2044
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
3933
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 a way to stop the execution with user input. I was thinking something like this: while(user hasn't pressed 'any key'){ keepExecutingScript(); }
3
4147
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. The User Experience, or how the user experiences the end product, is the key to acceptance. And that is where User Interface Design enters the design process. While product engineers focus on the technology, usability specialists focus on the user...
0
1039
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 screen, trying to move off of this square causes addstr to throw and exception. Every other spot works. Any idea why? Thanks:
1
3701
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 # # Brick & Ball in Python # by Jerry Fleming <jerryfleming@etang.com>
5
6333
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
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.