473,320 Members | 2,158 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,320 software developers and data experts.

Curses, Terminal Settings

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.

The problem I'm having is described here:

I call the following things to get the terminal into a the state I want,
and then back out of it:

def _pysh_cursesInmode():
curses.noecho()
curses.raw()
stdscr.keypad(1)
stdscr.idlok(1)
stdscr.scrollok(1)
curses.nonl()

def _pysh_cursesOutmode():
curses.echo()
curses.noraw()
stdscr.keypad(0)
stdscr.idlok(0)
stdscr.scrollok(0)
curses.nl()

Then, if a line, or an `inline command`, is determined to be a program
invocation, the shell piggybacks onto bash for forking/exec ing, piping,
and all that jazz, with a 'bash -noprofile -c "cmd"'.

When I call out to bash, I obviously want the terminal back in a
non-curses state. I want to undo *all* the changes so that when bash,
ls, ps, etc, starts up, the terminal is in a sane state when they write
to stdout.

Despite calling the Outmode() function listed above, the terminal is not
in this state. Newlines don't return the output to position 0, though
they do advance down a line.

like
this

Here's a real example.

zsh:
(10:06:38)jamwt/ % ls
LICENSE Maildir bin doc lists scrib vault
Mail att devel etc public tmp web
(10:06:38)jamwt/ % ls

bash through python curses:
$ ls
LICENSE Maildir bin doc lists scrib vault
Mail att
devel etc public tmp web
$

.... and something like 'top' looks just terrible.

I really don't know what else to do besides undo the changes I've made!
That seems to be what I'm doing with the mode functions above.. what am
I missing?

This is the end of the problem description. Thanks.

Here's a look at the pre-curses shell:

(10:09:41)jamwt/ % pysh
$ ls
LICENSE Maildir bin doc lists scrib vault
Mail att devel etc public tmp web
$ for item in `ls`.split("\n"): print item[:3]

LIC
Mai
Mai
att
bin
dev
doc
etc
lis
pub
scr
tmp
vau
web

$ FOO = "bar"
$ import sys
$ BAR = sys.version
$ export FOO
$ export BAR
$ env
FTP_PASSIVE_MODE=YES

.... etc ..

BAR=2.3 (#1, Jul 31 2003, 00:45:11)
[GCC 2.95.4 20020320 [FreeBSD]]

.... etc ..

FOO=bar
- Jamie

Jul 18 '05 #1
0 1670

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

Similar topics

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...
7
by: M.Senthil Kumar | last post by:
hai all, I need a help from you. I 'm working in a project using "curses.h" in Linux using 'C'. I have some doughts regarding menus and line. 1. I used to draw box in window using...
30
by: Ian Ward | last post by:
When I run the following code in a terminal with the encoding set to UTF-8 I get garbage on the first line, but the correct output on the second. import curses s = curses.initscr()...
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 # #...
48
by: Daniele C. | last post by:
As soon as my sourceforge.net project gets approved, I am going to build a ncurses port to win32 bindable to sockets, e.g. allowing VT100/ANSI terminals and the creation of simple terminal servers...
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...
0
by: skip | last post by:
I have a fairly simple curses app which is giving me this error: addstr() returned ERR I'm trapping it and continuing. I can see that *some* of my addstring calls succeed. This one happens...
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: Michael Goerz | last post by:
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.