def write(self, args): msg = args["message"] if type(msg) == types.StringType: msg = message.Message(msg, message.LTDATA) msg.data = msg.data elif msg.type == message.USERDATA: msg.data = msg.data #elif msg.type==message.ERROR: # msg.data = msg.data #elif msg.type==message.LTDATA: # msg.data = msg.data #elif msg.type==message.MUDDATA: # msg.data = msg.data text = self.munge(msg.data) #ses = msg.session #if line == '' or self.showTextForSession(ses) == 0: # return global buffer buffer.put(text) #print buffer.get() return
def write(self, msg): """ This writes text to the text buffer for viewing by the user. This is overridden from the 'base.BaseUI'. """ if type(msg) == tuple: msg = msg[0] if type(msg) == bytes: msg = message.Message(msg, message.LTDATA) line = msg.data ses = msg.session if line == '': return color, leftover = buffer_write(msg, self._txt, self._currcolors, self._unfinishedcolor) if msg.type == message.MUDDATA: self._unfinishedcolor[ses] = leftover self._currcolors[ses] = color self._clipText() self._yadjust()
def write(self, args): """ Handles writing information from the mud and/or Lyntin to the user. """ msg = args["message"] if type(msg) == types.StringType: msg = message.Message(msg, message.LTDATA) elif msg.type == message.USERDATA: return line = msg.data ses = msg.session if line == '' or self.showTextForSession(ses) == 0: return line = line.replace("\t", " ") pretext = [] if ses != None and ses != exported.get_current_session(): attr = self.attr_session_ pretext = [("[", attr), (ses.getName(), attr | curses.A_BOLD), ("] ", attr)] default_attr = curses.A_NORMAL if msg.type == message.ERROR: pretext[:0] = [("! ", self.attr_error_)] elif msg.type == message.LTDATA: pretext[:0] = [("@ ", self.attr_lyntin_)] self._decode_colors(ses, default_attr, line, pretext)
def handle_recv_data(args): msg = args["message"] if type(msg) == types.StringType: msg = message.Message(msg, message.LTDATA) if not hasattr(msg, "data"): return line = msg.data ses = msg.session output.speak(filter_ansi(line), 0) return line
def __init__(self): base.BaseUI.__init__(self) exported.hook_register("shutdown_hook", self.shutdown) exported.hook_register("to_user_hook", self.write) exported.hook_register("config_change_hook", self.configChangeHandler) exported.hook_register("bell_hook", self.bell) exported.hook_register("prompt_hook", lambda x: self.write( { 'message': message.Message(x["prompt"], message.MUDDATA, x["session"]) } ) ) self.app = wx.App() self.window = window() self.window.input.Bind(wx.EVT_CHAR_HOOK, self.process)
def write_mud_data(text, ses=None): """ Calls engine.myengine.writeMudData which writes a MUDDATA message. If there is no engine instance available, it prints it to sysout. @param text: the message to send @type text: string @param ses: the session instance the mud data is associated with @type ses: session.Session """ if myengine: myengine.writeUI(message.Message(text, message.MUDDATA, ses)) else: print("muddata:", text)
def write_user_data(text, ses=None): """ Calls engine.myengine.writeUserData which writes a USERDATA message. If there is no engine instance available, it prints it to sysout. @param text: the message to send @type text: string @param ses: the session instance the user data is associated with @type ses: session.Session """ text = str(text) if myengine: myengine.writeUI(message.Message(text + "\n", message.USERDATA, ses)) else: print "userdata:", text
def write_error(text, ses=None): """ Calls engine.myengine.writeError which writes ERROR message. If there is no engine instance available, it prints it to sysout. @param text: the message to send @type text: string @param ses: the session instance the error data is associated with @type ses: session.Session """ text = str(text) if myengine: myengine.writeUI(message.Message(text + "\n", message.ERROR, ses)) else: print "error:", text
def write_message(text, ses=None, **hints): """ Calls engine.myengine.writeMessage which writes LTDATA message. If there is no engine instance available, it prints it to sysout. @param text: the message to send @type text: string @param ses: the session instance the error data is associated with @type ses: session.Session """ #text = str(text) if myengine: myengine.writeUI(message.Message(text + "\n", message.LTDATA, ses, **hints)) else: print("message:", text)
def write(self, args): """ Handles writing information from the mud and/or Lyntin to the user. """ msg = args["message"] if type(msg) == types.StringType: msg = message.Message(msg, message.LTDATA) if not hasattr(msg, "data"): return line = msg.data ses = msg.session if line == '' or self.showTextForSession(ses) == 0: return # we prepend the session name to the text if this is not the # current session sending text. pretext = "" if ses != None and ses != exported.get_current_session(): pretext = "[" + ses.getName() + "] " if msg.type == message.ERROR or msg.type == message.LTDATA: if msg.type == message.ERROR: pretext = "error: " + pretext line = pretext + utils.chomp(line).replace("\n", "\n" + pretext) self.window.write(line+"\n") return elif msg.type == message.MUDDATA: if "\n" not in msg.data: msg.data = msg.data + "\n" self.window.write(msg.data) return if exported.get_config("ansicolor") == 0: if pretext: if line.endswith("\n"): line = (pretext + line[:-1].replace("\n", "\n" + pretext) + "\n") else: line = pretext + line.replace("\n", "\n" + pretext) self.window.write(line) return
def write_internal(self, args): mess = args["message"] if type(mess) == types.StringType: mess = message.Message(mess, message.LTDATA) line = mess.data ses = mess.session if line == '' or self.showTextForSession(ses) == 0: return color, leftover = buffer_write(mess, self._txt, self._currcolors, self._unfinishedcolor) if mess.type == message.MUDDATA: self._unfinishedcolor[ses] = leftover self._currcolors[ses] = color self._clipText() self._yadjust()
def __init__(self): base.BaseUI.__init__(self) locale.setlocale(locale.LC_ALL, "") exported.hook_register("startup_hook", startup_hook) exported.hook_register("to_user_hook", self.write) exported.hook_register("config_change_hook", self.config_changed) exported.hook_register("bell_hook", lambda x: sys.stdout.write('\07')) exported.hook_register( "prompt_hook", lambda x: self.write({ 'message': message.Message(x["prompt"], message.MUDDATA, x["session"]) })) exported.hook_register("write_hook", bindings_persist) self.unfinished_ = {} self.prompt_ = [("", curses.A_NORMAL)] self.lines_ = [self.prompt_] self.prompt_index_ = 0 self.running_ = 1 self.cfg_lazy_ = exported.get_config("curses.lazy") self.cfg_maxscrollback_ = exported.get_config("curses.maxscrollback") self.cfg_keydebug_ = exported.get_config("curses.keydebug") self.cfg_compact_ = exported.get_config("curses.compact") self.cfg_echo_ = exported.get_config("mudecho") global color_lookup self.attr_error_ = color_lookup[exported.get_config( "curses.attr.error")] self.attr_session_ = color_lookup[exported.get_config( "curses.attr.session")] self.attr_lyntin_ = color_lookup[exported.get_config( "curses.attr.lyntin")] self.attr_user_ = color_lookup[exported.get_config("curses.attr.user")] self.output_ = os.pipe() # MUD output signalling pipe
def write_internal(self, args): mess = args["message"] if type(mess) == bytes: mess = message.Message(mess, message.LTDATA) elif "window" in mess.hints: self.writeWindow_internal(mess.hints["window"], mess) return line = mess.data ses = mess.session if line == '' or self.showTextForSession(ses) == 0: return color, leftover = buffer_write(mess, self._txt, self._currcolors, self._unfinishedcolor) if mess.type == message.MUDDATA: self._unfinishedcolor[ses] = leftover self._currcolors[ses] = color self._clipText() self._yadjust()
def run(self): """ While the connection hasn't been shut down, we spin through this loop retrieving data from the mud, """ from lyntin import exported try: data = '' while not self._shutdownflag: newdata = self._pollForData() if newdata: newdata = self._filterIncomingData(newdata) if newdata == "": continue last_index = 0 alldata = (data+newdata).replace("\r","") # incrementally walk through each line in the data, # adjusting last_index to the end of the previous match for (m) in self._line_regex.finditer(alldata): oneline = alldata[last_index:m.end()] last_index = m.end() self.handleData(oneline) # keep the remainder (empty if alldata ended with a delimiter) data = alldata[last_index:] elif newdata == '': # if we got back an empty string, then something's amiss # and we should dump them. if data: self.handleData(data) if self._shutdownflag == 0 and self._session: self._session.shutdown(()) break elif not self._good_prompts and data: # Now we have rest of the input which is neither delimited prompt # nor complete line, and we yet did not see this server # delimiting it's prompts with telnet GA or EOR option. # We'll handle these data because the socket read was timed out. self.handleData(data) data = '' except SystemExit: if self._session: self._session.shutdown(()) except: exported.write_traceback("socket exception") if self._session: self._session.shutdown(()) # if we hit this point, we want to shut down the socket try: self._sock.shutdown(2) except: pass try: self._sock.close() except: pass self._sock = None self._session = None # sometimes the mud will hose up with echo off--we want to kick it # on again. self._config.change("mudecho", "on") # output message so the user knows what happened. event.OutputEvent(message.Message("Lost connection to: %s\n" % self._host)).enqueue()
def write(self, args): """ Handles writing information from the mud and/or Lyntin to the user. """ msg = args["message"] if type(msg) == types.StringType: msg = message.Message(msg, message.LTDATA) line = msg.data ses = msg.session if line == '' or self.showTextForSession(ses) == 0: return # we prepend the session name to the text if this is not the # current session sending text. pretext = "" if ses != None and ses != exported.get_current_session(): pretext = "[" + ses.getName() + "] " if msg.type == message.ERROR or msg.type == message.LTDATA: if msg.type == message.ERROR: pretext = "error: " + pretext else: pretext = "lyntin: " + pretext line = pretext + utils.chomp(line).replace("\n", "\n" + pretext) if exported.get_config("ansicolor") == 1: line = DEFAULT_ANSI + line sys.stdout.write(line + "\n") return elif msg.type == message.USERDATA: # we don't print user data in the textui return if exported.get_config("ansicolor") == 0: if pretext: if line.endswith("\n"): line = (pretext + line[:-1].replace("\n", "\n" + pretext) + "\n") else: line = pretext + line.replace("\n", "\n" + pretext) sys.stdout.write(line) sys.stdout.flush() return # each session has a saved current color for mud data. we grab # that current color--or user our default if we don't have one # for the session yet. if self._currcolors.has_key(ses): color = self._currcolors[ses] else: # need a copy of the list and not a reference to the list itself. color = list(DEFAULT_COLOR) # some sessions have an unfinished color as well--in case we # got a part of an ansi color code in a mud message, and the other # part is in another message. if self._unfinishedcolor.has_key(ses): leftover = self._unfinishedcolor[ses] else: leftover = "" lines = line.splitlines(1) if lines: for i in range(0, len(lines)): mem = lines[i] acolor = ansi.convert_tuple_to_ansi(color) color, leftover = ansi.figure_color(mem, color, leftover) if pretext: lines[i] = DEFAULT_ANSI + pretext + acolor + mem else: lines[i] = DEFAULT_ANSI + acolor + mem sys.stdout.write("".join(lines) + DEFAULT_ANSI) sys.stdout.flush() self._currcolors[ses] = color self._unfinishedcolor[ses] = leftover