示例#1
0
def textin_cmd(ses, args, input):
    """
  Takes the contents of the file and outputs it directly to the mud
  without processing it (like #read does).

  If you don't specify a directory, Lyntin will look for the file in
  the datadir.

  category: commands
  """
    if (ses.getName() == "common"):
        exported.write_error("textin cannot be applied to common session.",
                             ses)
        return

    filename = args["file"]

    if os.sep not in filename:
        filename = config.options["datadir"] + filename

    try:
        f = open(filename, "r")
        contents = f.readlines()
        f.close()
        for mem in contents:
            mem = utils.chomp(mem)
            ses.getSocketCommunicator().write(mem + "\n")
        exported.write_message(
            "textin: file %s read and sent to mud." % filename, ses)

    except IOError:
        exported.write_error("textin: file %s is not readable." % filename,
                             ses)
    except Exception, e:
        exported.write_error("textin: exception thrown %s." % e, ses)
示例#2
0
def textin_cmd(ses, args, input):
  """
  Takes the contents of the file and outputs it directly to the mud
  without processing it (like #read does).

  If you don't specify a directory, Lyntin will look for the file in
  the datadir.

  category: commands
  """
  if (ses.getName() == "common"):
    exported.write_error("textin cannot be applied to common session.", ses)
    return

  filename = args["file"]

  if os.sep not in filename:
    filename = config.options["datadir"] + filename
   
  try:
    f = open(filename, "r")
    contents = f.readlines()
    f.close()
    for mem in contents:
      mem = utils.chomp(mem)
      ses.getSocketCommunicator().write(mem + "\n")
    exported.write_message("textin: file %s read and sent to mud." % filename, ses)

  except IOError:
    exported.write_error("textin: file %s is not readable." % filename, ses)
  except Exception, e:
    exported.write_error("textin: exception thrown %s." % e, ses)
示例#3
0
    def handleinput(self, input):
        """
    Nicely handles enqueuing of input events.  Also deals with things 
    like CR and LF.  Call this method with input that's just been
    polled from the user.

    @param input: the raw input from the user
    @type  input: string
    """
        from lyntin import event
        input = utils.chomp(input)
        event.InputEvent(input).enqueue()
示例#4
0
文件: base.py 项目: v-legoff/accertin
  def handleinput(self, input):
    """
    Nicely handles enqueuing of input events.  Also deals with things 
    like CR and LF.  Call this method with input that's just been
    polled from the user.

    @param input: the raw input from the user
    @type  input: string
    """
    from lyntin import event
    input = utils.chomp(input)
    event.InputEvent(input).enqueue()
示例#5
0
  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
示例#6
0
    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
示例#7
0
  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