JuliaLozova / messenger

0 stars 0 forks source link

Curses and old code not integrating. #3

Open JuliaLozova opened 7 years ago

JuliaLozova commented 7 years ago

So I added three functions that add the curses module into the messenger. As it stands they work on their own. the client can essentially only talk to themselves, and doesn't connect to anyone.

So I am stuck as to how to integrate it so:

  1. user (1) runs program as server
  2. A socket is opened
  3. The display function runs -- and outputs that connection is appeared
  4. user (2) runs program and enters same chatroom

I don't know where to place wrapper(display) , because it feels like that should be called first, then the messengerserver/client functions.

Also how to integrate the stdscr and items, they are different, but I want stdscr to become and item at some point.... but how do I start. I realize that I have a couple of doubles going on now, such as prompt and writingFunc. The item and stdscr are messing with me.

I'm all tangled up. Help.

JuliaLozova commented 7 years ago

So aside from the wrapping display I see that once I changed the function inputData

`def inputData(stdscr, message_queues):

inp = sys.stdin.readline()

#print type(inp)
socket_list = message_queues.keys()
Y,X = stdscr.getyx()
while True:
    inpChar = stdscr.getch()
    if inpChar in (13, 10):
        break
    elif inpChar == 263:
        y, x = stdscr.getyx
        if x > X:
            del inpChar[-1]
            stdscr.move(y, (x-1))
            stdscr.clrtoeol()
            stdscr.refresh()
    elif inpChar in printable:
         inputs.append(chr(inpChar))
         stdscr.addch(inpChar)
    inp = "".join(inputs)
#print inp
return inp
#print inp
for sock in socket_list:
    message_queues[sock].put(inp)
    if sock not in outputs:
        outputs.append(sock)`

the inp is no longer a stdin. which then sends it to interpretData() `def interpretData(item, message_queues): data = item.recv(1024) if data:

A readable client socket has data

   print('Friend:{!r}'.format(data, item.getpeername()))    
else:
   # Interpret empty result as closed connection
   print('closing', server_address)
   inputs.remove(item)
   item.close()
   #Remove message queue  
   del message_queues[item]`

which, then it doesn't read it as data for some reason. --- so it closes the function