Added proper connection error handling.

parent 692d3737
...@@ -51,6 +51,12 @@ class ClientConnection(object, AsyncBase, asyncore.dispatcher): ...@@ -51,6 +51,12 @@ class ClientConnection(object, AsyncBase, asyncore.dispatcher):
if 'connect' in self.event_list: if 'connect' in self.event_list:
self.event_list['connect'](self) self.event_list['connect'](self)
def handle_error(self):
if hasattr(self, 'main'):
self.main.execute('disconnect')
self.main.display_info('Error raised due to a broken or refused'\
+ ' connection')
def handle_close(self): def handle_close(self):
self.close() self.close()
......
...@@ -16,15 +16,15 @@ class BaseBar(object): ...@@ -16,15 +16,15 @@ class BaseBar(object):
self.color_pair = curses.color_pair(0) self.color_pair = curses.color_pair(0)
self._prefix = '' self._prefix = ''
def prefix(self, value=''): def prefix(self, value=None):
if not value: if value == None: # Note: an empty string can also be set.
return self._prefix return self._prefix
self._prefix = value self._prefix = value
self.display(self._msg) self.display(self._msg)
def display(self, msg): def display(self, msg):
self._msg = msg self._msg = msg
if self.prefix: if self.prefix():
msg = self.prefix() + ' ' + msg msg = self.prefix() + ' ' + msg
# Curses will raise a 'curses.error' when the last possible character is # Curses will raise a 'curses.error' when the last possible character is
# written. This exception should therefore always be catched. The raised # written. This exception should therefore always be catched. The raised
......
...@@ -158,7 +158,9 @@ class CLI: ...@@ -158,7 +158,9 @@ class CLI:
self.connection = None self.connection = None
self.display_info('Offline. Type "/connect HOST" to connect' \ self.display_info('Offline. Type "/connect HOST" to connect' \
+ ' to another chat server.') + ' to another chat server.')
self.info_bar.prefix('')
self.debug_window.clear() self.debug_window.clear()
self.refresh()
def help(main): def help(main):
if main.chat_window.displayed_help: if main.chat_window.displayed_help:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment