fix some ncurses crash. fixed #1817

This commit is contained in:
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 2010-09-10 21:51:13 +00:00
parent 77df6feb97
commit 945dc664d8
3 changed files with 32 additions and 41 deletions

View file

@ -371,7 +371,7 @@ class Gui(object):
(from one of our contacts)
"""
from common import debug
debug('message: %s\n' % message)
# debug('message: %s\n' % message)
if message['type'] == 'groupchat':
return None
# Differentiate both type of messages, and call the appropriate handler.
@ -406,7 +406,7 @@ class Gui(object):
When receiving "normal" messages (from someone in our roster)
"""
from common import debug
debug('MESSAGE: %s\n' % (presence))
# debug('MESSAGE: %s\n' % (presence))
return
@ -414,7 +414,7 @@ class Gui(object):
"""
"""
from common import debug
debug('PRESEEEEEEEEENCE: %s\n' % (presence))
# debug('PRESEEEEEEEEENCE: %s\n' % (presence))
return
def on_roster_update(self, iq):
@ -423,7 +423,7 @@ class Gui(object):
after a roster request, etc
"""
from common import debug
debug("UPDATE: %s\n" % (iq))
# debug("UPDATE: %s\n" % (iq))
for subscriber in iq['roster']['items']:
debug("subscriber: %s\n" % (iq['roster']['items'][subscriber]['subscription']))
@ -446,8 +446,8 @@ class Gui(object):
if char in list(self.key_func.keys()):
self.key_func[char]()
else:
# if len(char) > 1:
# continue # ignore non-handled keyboard shortcuts
if not char or len(char) > 1:
continue # ignore non-handled keyboard shortcuts
self.window.do_command(char)
def current_room(self):
@ -585,7 +585,7 @@ class Gui(object):
Display the error on the room window
"""
from common import debug
debug('ERROR: %s\n' % error)
# debug('ERROR: %s\n' % error)
room = self.get_room_by_name(room_name)
if not room:
room = self.get_room_by_name('Info')
@ -644,6 +644,8 @@ class Gui(object):
"""
Triggered whenever a message is received from a multi-user chat room.
"""
from common import debug
# debug('GROUPCHAT message: %s\n' % message)
delay_tag = message.find('{urn:xmpp:delay}delay')
if delay_tag is not None:
delayed = True
@ -673,6 +675,7 @@ class Gui(object):
return
body = message['body']
subject = message['subject']
# debug('======== %s, %s, %s, %s====\n'% (nick_from, room_from, body, subject))
if subject:
if nick_from:
self.add_message_to_room(room, _("%(nick)s changed the subject to: %(subject)s") % {'nick':nick_from, 'subject':subject}, time=date)

View file

@ -61,7 +61,10 @@ def read_char(s):
if 240 <= first:
(code, c) = get_next_byte(s) # 4 bytes char
char += c
return char.decode('utf-8')# return all the concatened byte objets, decoded
try:
return char.decode('utf-8') # return all the concatened byte objets, decoded
except UnicodeDecodeError:
return None
if __name__ == '__main__':
import curses

View file

@ -93,15 +93,11 @@ class UserList(Win):
g_lock.acquire()
self.win.erase()
y = 0
for user in sorted(users):#sorted(users, compare_user):
for user in sorted(users):
role_col = self.color_role[user.role]
show_col = self.color_show[user.show]
self.win.attron(curses.color_pair(show_col))
self.addnstr(y, 0, theme.CHAR_STATUS, 1)
self.win.attroff(curses.color_pair(show_col))
self.win.attron(curses.color_pair(role_col))
self.addnstr(y, 1, user.nick, self.width-1)
self.win.attroff(curses.color_pair(role_col))
self.addstr(y, 0, theme.CHAR_STATUS, curses.color_pair(show_col))
self.addnstr(y, 1, user.nick, self.width-1, curses.color_pair(role_col))
y += 1
if y == self.height:
break
@ -128,12 +124,12 @@ class Topic(Win):
g_lock.acquire()
self.win.erase()
if not jid:
self.addnstr(0, 0, topic[:self.width-1], curses.color_pair(theme.COLOR_TOPIC_BAR))
while True:
try:
self.win.addch(' ', curses.color_pair(theme.COLOR_TOPIC_BAR))
except:
break
self.addnstr(0, 0, topic[:self.width-1], self.width-1, curses.color_pair(theme.COLOR_TOPIC_BAR))
(y, x) = self.win.getyx()
remaining_size = self.width - x
if remaining_size:
self.addnstr(' '*remaining_size, remaining_size,
curses.color_pair(theme.COLOR_INFORMATION_BAR))
elif jid:
room = jid.split('/')[0]
nick = '/'.join(jid.split('/')[1:])
@ -182,13 +178,12 @@ class RoomInfo(Win):
except: # end of line
break
(y, x) = self.win.getyx()
self.addstr(y, x-1, '] '+ current.name, curses.color_pair(theme.COLOR_INFORMATION_BAR))
self.addnstr(y, x-1, '] '+ current.name, len(current.name)+2, curses.color_pair(theme.COLOR_INFORMATION_BAR))
self.print_scroll_position(current)
while True:
try:
self.addstr(' ', curses.color_pair(theme.COLOR_INFORMATION_BAR))
except:
break
(y, x) = self.win.getyx()
remaining_size = self.width - x
self.addnstr(' '*remaining_size, remaining_size,
curses.color_pair(theme.COLOR_INFORMATION_BAR))
self.win.refresh()
g_lock.release()
@ -314,10 +309,7 @@ class TextWin(Win):
if not colorized:
if color:
self.win.attron(curses.color_pair(color))
try:
self.addstr(y, x, txt)
except: # bug 1665
pass
self.addstr(y, x, txt)
if color:
self.win.attroff(curses.color_pair(color))
@ -330,9 +322,7 @@ class TextWin(Win):
}
for word in txt.split():
if word in list(special_words.keys()):
self.win.attron(curses.color_pair(special_words[word]))
self.addstr(word)
self.win.attroff(curses.color_pair(special_words[word]))
self.addstr(word, curses.color_pair(special_words[word]))
elif word.startswith('(') and word.endswith(')'):
self.addstr('(', curses.color_pair(color))
self.addstr(word[1:-1], curses.color_pair(theme.COLOR_CURLYBRACKETED_WORD))
@ -342,13 +332,8 @@ class TextWin(Win):
elif word.startswith('[') and word.endswith(']'):
self.addstr(word[1:-1], curses.color_pair(theme.COLOR_BRACKETED_WORD))
else:
self.win.attron(curses.color_pair(color))
self.addstr(word)
self.win.attroff(curses.color_pair(color))
try:
self.addstr(' ')
except:
pass
self.addstr(word, curses.color_pair(color))
self.addnstr(' ', 1)
def write_nickname(self, nickname, color):
"""