473,782 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

curses & disable readline & replace stdin

Hi !

I'd like to init curses and still have working Python interactive
command line. I found that you can replace stdin/stdout/stderr
like this:

#!/usr/bin/python -i

import curses
import sys
import atexit

# this doesn't help, anyway
#del sys.modules['readline']

# global variable (curses window)
stdscr = None

class FakeStdIO(objec t):

def write(self, str):
global stdscr
stdscr.addstr(s tr)
stdscr.refresh( )

def readline(self):
print "$ ",
return stdscr.getstr()

stdscr = curses.initscr( )
atexit.register (curses.endwin)
curses.echo()

f = FakeStdIO()
sys.stdin = f
sys.stdout = f
sys.stderr = f

print 'Hello, curses !' # <-- this works

l = sys.stdin.readl ine() # <-- this also works fine

# <-- interactive Python prompt doesn't echo imput

It looks that '>>>' prompt is using the readline module, which
is not using sys.stdin at all.

Q: Can you prevent python interpreter to use readline module
(even when it is available), *without* recompiling python ?

I think it should be possible to write a module in C to access
Python internals. But can you do it "from python" ?

The other option is to make readline somehow work with curses.
This is however not what I intended.

Platform: Linux Mandrake, Python 2.3.5

Thanks,

BranoZ

Jul 18 '05 #1
0 2403

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

Similar topics

0
1691
by: J Turner | last post by:
Hello, I'm playing with a python-based shell, which uses (guess what?) python as it's scripting language, for iterative invocation, environment variables, etc. Everything was going well, until I moved beyond sys.readline() into curses territory to flesh out the line-editing capabilities. Curses always seems to get me.
0
1036
by: Stefan Zollinger | last post by:
Hi I'm working on a "telnet" server which should serve piped output from curses based applications. So far it works fine with plain text, but it looks like stdin.readline() scrambles the control characters of curses applications. Does anyone know a way to work around this? Thanks for help,
12
53320
by: Mike Maxwell | last post by:
When I invoke readline() in a for loop, why does it return a series of one-char strings, rather than the full line? >>> for sL in sys.stdin.readline(): print sL .... abc a b c
19
2937
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your company's clients. Your company has generated its own unique ID numbers to replace the social security numbers. Now, management would like the IT guys to go thru the old data and replace as many SSNs with the new ID numbers as possible. You...
39
3113
by: n00m | last post by:
Given a list of N arbitrarily permutated integers from set {1..N}. Need to find the ordering numbers of each integer in the LONGEST increasing sequence to which this number belongs. Sample: List: Corresponding ordering numbers:
6
2787
by: Christian Convey | last post by:
Hello, I've got a program that (ideally) perpetually monitors sys.stdin for lines of text. As soon as a line comes in, my program takes some action. The problem is, it seems like a very large amount of data must accumulate on sys.stdin before even my first invocation of readline() returns. This delay prevents my program from being responsive in the way it must be.
3
3717
by: skip | last post by:
I'm having no success building the curses module on Solaris 8 (yes, I know it's ancient - advancing the state-of-the-art is not yet an option) for Python 2.4. Sun provides an apparently ancient version of curses in /usr/lib, so I downloaded and installed ncurses 5.5, both using default settings and using --with-shared. When the curses module is linked against libcurses.so I get some strange error about acs32map being undefined (which...
0
1133
by: Berend van Berkum | last post by:
Hi all, I'm looking at building an interactive session in front of some rdfobj instances. I've used cmd and just found code.Interactive*. Protocol doesn't matter, I'm looking at the UI possibilities. History is nice to have and my intention is to write output of the session to stdin/stderr. However, my question, can I change the "prompt" string in respond
2
4433
by: Grant Edwards | last post by:
I'm trying to figure out how to use the gnu readline library so that when my program is prompting the user for input there is line editing and history support. I've read and re-read the documentation for the "readline" module in the standard library and I still can't figure out how to use the module or even if the module is intended to do what I want. The example code all seems to be about on how to modify the behavior of an...
0
9639
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
10308
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
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
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...
1
7486
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
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
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
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.