473,472 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

'normal' shell with curses

Hi,

I'm trying to print out text in color. As far as I know, curses is the
only way to do that (or not?). So, what I ultimately want is a curses
terminal that behaves as closely as possible as a normal terminal, i.e.
it breaks lines and scrolls automatically, so that I can implement a
function myprint(color, text) that does what print() does, only in color.

So, my first tests brought up some problems:

#!/usr/bin/python

from time import sleep
import curses
import sys

stdscr = curses.initscr()
stdscr.addstr("Initialized\n")
stdscr.refresh()
(maxlines, maxcolumns) = stdscr.getmaxyx()
try:
for counter in xrange(24):
stdscr.addstr("Hello world %s\n" % counter)
stdscr.refresh()
if counter >= maxlines:
stdscr.scroll()
stdscr.refresh()
except Exception, data:
sys.stderr.write("Exception: \n");
sys.stderr.write(str(data));
finally:
sleep(5)
curses.endwin()

Instead of scrolling, the program throws an exception. Any hints?

Also, is there a way leave the curses output on the screen after
curses.endwin(), instead of returning to the normal terminal without a
trace of curses.

Thanks,
Michael
Mar 4 '08 #1
1 2342
Hello Michael,
I'm trying to print out text in color. As far as I know, curses is the
only way to do that (or not?).
On unix, every XTerm compatible terminal will be able to display color
using escape sequence.
(Like the one you see in the output of 'grep --color')

See the shameless plug in http://pythonwise.blogspot.com/2008/03/ansiprint.html

HTH,
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com
Mar 4 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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',...
3
by: Tomas | last post by:
Hi! I'm looking for a replacement for the standard interactive python shell. So far I've tried IPython and PyCrust. I liked both, but I'm not 100% happy with any of them. My main complaint about...
4
by: schwerdy | last post by:
Hi together, can someone provide an example of a curses application that works in a xterm that can be resized? I could not find any working example yet... Thanks in advance, Sebastian...
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 # #...
3
by: Simon Morgan | last post by:
Hi, I'm having trouble with the following code. The problem is that the value read by getch() when I hit the up or down keys doesn't match curses.KEY_UP or curses.KEY_DOWN respectively. Other...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
12
by: Krypto | last post by:
I have been using python shell to test small parts of the big program. What other ways can I use the shell effectively. My mentor told me that you can virtually do anything from testing your...
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
1
by: Hero45 | last post by:
I'm currently working on a homework assignment to write a shell. I've got pretty much all of it done, but I'm having some problems getting arrow key history working. I spent a decent amount of time...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.