Python and Curses, mangled mess
Posted on 2006-10-31
I'm fairly new to Python and completely confused when it comes to Curses. Perhaps an expert here can lend me a helping hand as I'm having a heck of a time trying to get any reason out of Curses.. the documentation for it is vague and not very helpful to me anymore, I can only ever seem to get the same couple of guides a million times on Google, so if anyone has any good tutorials or examples of this python socket curses client, that'd be nice too.
I am making a 3rd party client for a game. This game is typically graphical, however this client will be text only. I need a big huge window for a chat buffer and an input box below it for inputting text. The game is pretty much just a chat program, so the buffer will be filled with lots of "He says: Hi" and "She says: Bye".
My code so far is below... I was so frustrated I got rid of the bottom input box and just made it all the same.. I guess my main questions would be:
1. How can I add "scrolling", such that text does not get overwritten in the same spot in the output window all the time. I want each new line to be at the bottom and all lines before it to move up.
2. Please please please show me how to seperate the text input window from the output text window.
3. Any other hints or help would be appreciated!
from socket import *
win = curses.initscr()
max_y, max_x = win.getmaxyx()
begin_x = 1 ; begin_y = 1
win = curses.newwin(max_y-1, max_x-1, begin_y, begin_x)
fsocket = socket(AF_INET, SOCK_STREAM)
ADDR = ('blah.blahblah.com', 80)
fsocket.send("connect Username password\n")
data = fsocket.recv(1024)
data = ""
data = win.getstr(0,0)
fsocket.send(data + "\n")