Пример #1
0
    def runui(self):
        global HELP_TEXT
        exported.add_help("tkui", HELP_TEXT)
        exported.write_message('For tk help type "#help tkui".')
        exported.add_command("colorcheck", colorcheck_cmd)

        # run the tk mainloop here
        self._tk.mainloop()
Пример #2
0
    def runui(self):
        global HELP_TEXT
        exported.add_help("tkui", HELP_TEXT)
        exported.write_message("For tk help type \"#help tkui\".")
        exported.add_command("colorcheck", colorcheck_cmd)

        # run the tk mainloop here
        self._tk.mainloop()
Пример #3
0
    def runui(self):
        global HELP_TEXT
        exported.add_help("textui", HELP_TEXT)
        exported.write_message("For textui help, type \"#help textui\".")

        # termios is the module that allows us to change echo for a terminal
        # but only if the module is present
        try:
            import termios
        except ImportError:
            self._tio = 0
        else:
            self._tio = 1
            echonew = termios.tcgetattr(self._stdin.fileno())
            self._onecho_attr = echonew[3]
            self._offecho_attr = echonew[3] & ~termios.ECHO

        if config.options.has_key("readline"):
            try:
                import readline
            except ImportError:
                self._rline = 0
                exported.write_error("Readline not available for your system.")
            else:
                self._rline = 1

                # we do some stuff to grab the readlinerc file if they have one
                # so the user can set some readline oriented things which makes
                # things a little nicer for the user.
                d = exported.get_config("datadir")

                try:
                    readline.read_init_file(d + "readlinerc")
                except:
                    exported.write_error(
                        "Note: No readlinerc file available in %s." % d)

                exported.write_message("Readline enabled.")

        if self._tio == 0 or self._rline == 1:
            exported.write_error("Warming: echo off is unavailable.  " +
                                 "Your password will be visible.")

        # go into the main loop
        self.run()
Пример #4
0
  def runui(self):
    global HELP_TEXT
    exported.add_help("textui", HELP_TEXT)
    exported.write_message("For textui help, type \"#help textui\".")

    # termios is the module that allows us to change echo for a terminal
    # but only if the module is present
    try:
      import termios
    except ImportError:
      self._tio = 0
    else:
      self._tio = 1
      echonew = termios.tcgetattr(self._stdin.fileno())
      self._onecho_attr = echonew[3]
      self._offecho_attr = echonew[3] & ~termios.ECHO

    if config.options.has_key("readline"):
      try:
        import readline
      except ImportError:
        self._rline = 0
        exported.write_error("Readline not available for your system.")
      else:
        self._rline = 1

        # we do some stuff to grab the readlinerc file if they have one
        # so the user can set some readline oriented things which makes 
        # things a little nicer for the user.
        d = exported.get_config("datadir")

        try:
          readline.read_init_file(d + "readlinerc")
        except:
          exported.write_error("Note: No readlinerc file available in %s." % d)
        
        exported.write_message("Readline enabled.")

    if self._tio == 0 or self._rline == 1:
      exported.write_error("Warming: echo off is unavailable.  " +
                           "Your password will be visible.")

    # go into the main loop
    self.run()
Пример #5
0
def load():
    exported.add_help("bugs", bugs)
    exported.add_help("command", command)
    exported.add_help("contribute", contribute)
    exported.add_help("errata", errata)
    exported.add_help("evaluation", evaluation)
    exported.add_help("general", general)
    exported.add_help("gettingstarted", gettingstarted)
    exported.add_help("osnotes", osnotes)
    exported.add_help("regexp", regexp)
    exported.add_help("whylyntin", whylyntin)
Пример #6
0
def load():
  exported.add_help("bugs", bugs)
  exported.add_help("command", command)
  exported.add_help("contribute", contribute)
  exported.add_help("errata", errata)
  exported.add_help("evaluation", evaluation)
  exported.add_help("general", general)
  exported.add_help("gettingstarted", gettingstarted)
  exported.add_help("osnotes", osnotes)
  exported.add_help("regexp", regexp)
  exported.add_help("whylyntin", whylyntin)
Пример #7
0
  def runui(self):
    # 
    # This is the loop for user input polling and for mud output.
    #
    global HELP_TEXT
    
    exported.add_help("cursesui", HELP_TEXT)

    stdscr = curses.initscr()
    try:
    
      if curses.has_colors():
        curses.start_color()
        for i in xrange(1,64):
          curses.init_pair(i, i%8, i/8)
      curses.raw()
      curses.noecho()
      curses.nonl()
      curses.meta(1)

      out = None
      edit = None
      scrollback = None

      lines = self.lines_

      exported.write_message("For Cursesui help, type \"#help cursesui\".")
      exported.write_message("For some commands help, type \"#help curses\".")

      dirty_count = 0
      timestamp = 0
      output_count = 0

      hotkey_buffer = ''
      keyboard_buffer = []

      select_timeout = 100
      keyboard_fd = sys.stdin.fileno()
      output_pipe_fd = self.output_[0]
      select_input_list = [ keyboard_fd, output_pipe_fd ]

      while self.running_:

        #
        # set output windows:
        #
        if not out:
          stdscr = curses.initscr()
          (screen_h, screen_w) = stdscr.getmaxyx()
          win = curses.newwin(1, screen_w, screen_h-1, 0)
          if edit:
            edit.attach(win)
          else:  
            edit = inputbox(self, win)
          if not scrollback:
            out = scroller(curses.newwin(screen_h-1, screen_w, 0, 0), lines)
          else:
            scroll_h = screen_h/3*2
            out_h = (screen_h - 2) - scroll_h 
            scrollback = scroller(curses.newwin(scroll_h, screen_w, 0, 0),
                                  lines[:])
            scrollback.redraw()
            wborder = curses.newwin(1, screen_w, scroll_h, 0)
            wborder.bkgd(curses.ACS_HLINE)
            wborder.erase()
            wborder.noutrefresh()
            out = scroller(curses.newwin(out_h, screen_w, scroll_h+1, 0), lines)
          out.redraw()

        edit._align()

        if keyboard_buffer and not hotkey_buffer:
          ch = keyboard_buffer.pop()
        else: 
          ch = win.getch()
          if ch == curses.ERR:
          
            # drop the hotkey buffer when the keyboard goes idle
            hotkey_buffer = ''

            # enter idle mode:
            try:
                (i, o, x) = select.select(select_input_list, [], [], select_timeout)
            except:
                # It's probably stray EINTR - further investigation is needed
                (i, o, x) = (None, None, None)

            if not i:
              # timeout was hit:
              out.redraw(self.cfg_maxscrollback_)
              select_timeout = 100
              dirty_count = 0
              continue
            else:    
              
              if keyboard_fd in i:
                ch = win.getch()
 
              if output_pipe_fd in i:  
                line=os.read(output_pipe_fd, 1024)
                dirty_count += len(line)
                
              if ch == curses.ERR:
                timestamp_now = time()
                if ((timestamp_now - timestamp) > 0.2) or (dirty_count > self.cfg_lazy_):
                  out.redraw(self.cfg_maxscrollback_)
                  select_timeout = 100
                  dirty_count = 0
                  output_count = 0
                else:  
                  select_timeout = 0.2
                  output_count += 1
                timestamp = timestamp_now
                continue

          keyboard_buffer.insert(0, ch)
          if ch < 256:
            keycodename = chr(ch)
            hotkey_buffer += keycodename
            
            if self.cfg_keydebug_:
              if is_a_char(keycodename):
                exported.write_message(keycodename)
              elif ch==0x1b:
                exported.write_message("<ESC>")

            binding = bindings.get(hotkey_buffer)
            if binding:
              hotkey_buffer = ''
              keyboard_buffer = []
              self.handleinput(binding[1], internal=1)
              continue
            elif not filter(lambda x: x.startswith(hotkey_buffer), bindings.keys()):
              hotkey_buffer = ''
            continue
          else:
            keycodename = keytext.get(ch)
            if keycodename:
              if self.cfg_keydebug_:
                exported.write_message(keycodename)
              binding = bindings.get(keycodename)
              if binding:
                self.handleinput(binding[1], internal=1)
                keyboard_buffer.pop() # get it back
            hotkey_buffer = ''
            continue

        if ch == curses.KEY_PPAGE:
          if not scrollback:
            scrollback = 1 # create scrollback window at next iteration
            out = None
          else: 
            scrollback.redraw( scroll = -(scroll_h/2+1) )
          continue
        if ch == curses.KEY_NPAGE:
          if scrollback:
            scrollback.redraw( scroll = scroll_h/2+1 )
          continue

        if ch == curses.ascii.ESC and scrollback:
          scrollback = None
          out = None
          continue

        ch = edit.do_command(ch)    

        if ch in (curses.ascii.CR, curses.ascii.LF):
          edit_string = edit.get_string()
          if edit_string.strip() == "#end":
            break
          self.handleinput( edit_string )
          edit.set("")

        elif ch in (curses.KEY_RESIZE, curses.ascii.FF): # force screen redraw
          out = None
          continue

        elif ch == curses.ascii.ETX:    # Ctrl-C
          break

    finally:
      endcurses()
Пример #8
0
def load():
	exported.hook_register("from_mud_hook", handle_from_mud)
	modutils.load_commands(commands_dict)
	exported.add_help("root.commands.commo", commo_help)
	exported.remove_help("root.commo")
Пример #9
0
def load():
    modutils.load_commands(commands_dict)
    exported.add_help("root.commands.ifvar", ifvar_help)
    exported.remove_help("root.ifvar")
Пример #10
0
class CommandManager(manager.Manager):
    """ 
  The CommandManager holds a series of _CommandData objects
  and methods to manipulate and use them.  Lyntin developers
  can add their own commands to Lyntin.

  There should be one instance of the CommandManager and
  the engine should have it.  All CommandManager interaction
  should be done through the exported module.
  """
    def __init__(self, e):
        self._commands = {}
        self._engine = e

    def getCommands(self):
        """
    Returns a list of the commands we have registered.

    @return: all the commands that have been registered
    @rtype:  list of strings
    """
        return self._commands.keys()

    def addCommand(self,
                   name,
                   func,
                   arguments=None,
                   argoptions=None,
                   helptext=""):
        """
    Registers a command.

    @param name: the name of the command to add
    @type  name: string

    @param func: the function that handles the command
    @type  func: function

    @param arguments: the argument spec to create the argparser
    @type  arguments: string

    @param argoptions: options for how the argument spec should be parsed
    @type  argoptions: string

    @param helptext: the help text for this command for the user
    @type  helptext: string

    @raise ValueError: if the function is uncallable
    @raise Exception: if the argument spec for the command is unparseable
    """
        if not callable(func):
            raise ValueError, "%s is uncallable." % name

        cd = _CommandData()

        syntaxline = ""

        # try to figure out the arguments and syntax line stuff
        if arguments != None:
            try:
                cd.setName(name)
                cd.setArgParser(argparser.ArgumentParser(
                    arguments, argoptions))
                syntaxline = utils.wrap_text(cd.getArgParser().syntaxline, 60,
                                             6)
            except Exception, e:
                raise Exception, "Error with arguments for command %s, (%s)" % (
                    name, e)

        cd.setFunc(func)

        # removeCommand tests to see if the command exists already and will
        # remove it if it does.
        self.removeCommand(name)

        # toss the command thing in the dict
        self._commands[name] = cd

        # deal with the help text
        if not helptext:
            if func.__doc__:
                helptext = inspect.getdoc(func)
            else:
                helptext = "\nThis command has no help."

        if name.startswith("^"):
            cd.setNameAdjusted(name[1:])
        else:
            cd.setNameAdjusted(name)

        if syntaxline:
            commandchar = self._engine.getConfigManager().get("commandchar")
            helptext = ("syntax: %s%s %s\n" %
                        (commandchar, cd.getNameAdjusted(), syntaxline) +
                        helptext)

        fqn = exported.add_help(cd.getNameAdjusted(), helptext)
        cd.setFQN(fqn)
Пример #11
0
  def addCommand(self, name, func, arguments=None, argoptions=None, helptext=""):
    """
    Registers a command.

    @param name: the name of the command to add
    @type  name: string

    @param func: the function that handles the command
    @type  func: function

    @param arguments: the argument spec to create the argparser
    @type  arguments: string

    @param argoptions: options for how the argument spec should be parsed
    @type  argoptions: string

    @param helptext: the help text for this command for the user
    @type  helptext: string

    @raise ValueError: if the function is uncallable
    @raise Exception: if the argument spec for the command is unparseable
    """
    if not callable(func):
      raise ValueError("%s is uncallable." % name)

    cd = _CommandData()

    syntaxline = ""

    # try to figure out the arguments and syntax line stuff
    if arguments != None:
      try:
        cd.setName(name)
        cd.setArgParser(argparser.ArgumentParser(arguments, argoptions))
        syntaxline = utils.wrap_text(cd.getArgParser().syntaxline, 60, 6)
      except Exception as e:
        raise Exception("Error with arguments for command %s, (%s)" % (name,e))

    cd.setFunc(func)

    # removeCommand tests to see if the command exists already and will
    # remove it if it does.
    self.removeCommand(name)

    # toss the command thing in the dict
    self._commands[name] = cd

    # deal with the help text
    if not helptext:
      if func.__doc__:
        helptext = inspect.getdoc(func)
      else:
        helptext = "\nThis command has no help."

    if name.startswith("^"):
      cd.setNameAdjusted(name[1:])
    else:
      cd.setNameAdjusted(name)

    if syntaxline:
      commandchar = self._engine.getConfigManager().get("commandchar")
      helptext = ("syntax: %s%s %s\n" % 
             (commandchar, cd.getNameAdjusted(), syntaxline) + helptext)

    fqn = exported.add_help(cd.getNameAdjusted(), helptext)
    cd.setFQN(fqn)
Пример #12
0
    def runui(self):
        #
        # This is the loop for user input polling and for mud output.
        #
        global HELP_TEXT

        exported.add_help("cursesui", HELP_TEXT)

        stdscr = curses.initscr()
        try:

            if curses.has_colors():
                curses.start_color()
                for i in xrange(1, 64):
                    curses.init_pair(i, i % 8, i / 8)
            curses.raw()
            curses.noecho()
            curses.nonl()
            curses.meta(1)

            out = None
            edit = None
            scrollback = None

            lines = self.lines_

            exported.write_message(
                "For Cursesui help, type \"#help cursesui\".")
            exported.write_message(
                "For some commands help, type \"#help curses\".")

            dirty_count = 0
            timestamp = 0
            output_count = 0

            hotkey_buffer = ''
            keyboard_buffer = []

            select_timeout = 100
            keyboard_fd = sys.stdin.fileno()
            output_pipe_fd = self.output_[0]
            select_input_list = [keyboard_fd, output_pipe_fd]

            while self.running_:

                #
                # set output windows:
                #
                if not out:
                    stdscr = curses.initscr()
                    (screen_h, screen_w) = stdscr.getmaxyx()
                    win = curses.newwin(1, screen_w, screen_h - 1, 0)
                    if edit:
                        edit.attach(win)
                    else:
                        edit = inputbox(self, win)
                    if not scrollback:
                        out = scroller(
                            curses.newwin(screen_h - 1, screen_w, 0, 0), lines)
                    else:
                        scroll_h = screen_h / 3 * 2
                        out_h = (screen_h - 2) - scroll_h
                        scrollback = scroller(
                            curses.newwin(scroll_h, screen_w, 0, 0), lines[:])
                        scrollback.redraw()
                        wborder = curses.newwin(1, screen_w, scroll_h, 0)
                        wborder.bkgd(curses.ACS_HLINE)
                        wborder.erase()
                        wborder.noutrefresh()
                        out = scroller(
                            curses.newwin(out_h, screen_w, scroll_h + 1, 0),
                            lines)
                    out.redraw()

                edit._align()

                if keyboard_buffer and not hotkey_buffer:
                    ch = keyboard_buffer.pop()
                else:
                    ch = win.getch()
                    if ch == curses.ERR:

                        # drop the hotkey buffer when the keyboard goes idle
                        hotkey_buffer = ''

                        # enter idle mode:
                        try:
                            (i, o, x) = select.select(select_input_list, [],
                                                      [], select_timeout)
                        except:
                            # It's probably stray EINTR - further investigation is needed
                            (i, o, x) = (None, None, None)

                        if not i:
                            # timeout was hit:
                            out.redraw(self.cfg_maxscrollback_)
                            select_timeout = 100
                            dirty_count = 0
                            continue
                        else:

                            if keyboard_fd in i:
                                ch = win.getch()

                            if output_pipe_fd in i:
                                line = os.read(output_pipe_fd, 1024)
                                dirty_count += len(line)

                            if ch == curses.ERR:
                                timestamp_now = time()
                                if ((timestamp_now - timestamp) >
                                        0.2) or (dirty_count > self.cfg_lazy_):
                                    out.redraw(self.cfg_maxscrollback_)
                                    select_timeout = 100
                                    dirty_count = 0
                                    output_count = 0
                                else:
                                    select_timeout = 0.2
                                    output_count += 1
                                timestamp = timestamp_now
                                continue

                    keyboard_buffer.insert(0, ch)
                    if ch < 256:
                        keycodename = chr(ch)
                        hotkey_buffer += keycodename

                        if self.cfg_keydebug_:
                            if is_a_char(keycodename):
                                exported.write_message(keycodename)
                            elif ch == 0x1b:
                                exported.write_message("<ESC>")

                        binding = bindings.get(hotkey_buffer)
                        if binding:
                            hotkey_buffer = ''
                            keyboard_buffer = []
                            self.handleinput(binding[1], internal=1)
                            continue
                        elif not filter(lambda x: x.startswith(hotkey_buffer),
                                        bindings.keys()):
                            hotkey_buffer = ''
                        continue
                    else:
                        keycodename = keytext.get(ch)
                        if keycodename:
                            if self.cfg_keydebug_:
                                exported.write_message(keycodename)
                            binding = bindings.get(keycodename)
                            if binding:
                                self.handleinput(binding[1], internal=1)
                                keyboard_buffer.pop()  # get it back
                        hotkey_buffer = ''
                        continue

                if ch == curses.KEY_PPAGE:
                    if not scrollback:
                        scrollback = 1  # create scrollback window at next iteration
                        out = None
                    else:
                        scrollback.redraw(scroll=-(scroll_h / 2 + 1))
                    continue
                if ch == curses.KEY_NPAGE:
                    if scrollback:
                        scrollback.redraw(scroll=scroll_h / 2 + 1)
                    continue

                if ch == curses.ascii.ESC and scrollback:
                    scrollback = None
                    out = None
                    continue

                ch = edit.do_command(ch)

                if ch in (curses.ascii.CR, curses.ascii.LF):
                    edit_string = edit.get_string()
                    if edit_string.strip() == "#end":
                        break
                    self.handleinput(edit_string)
                    edit.set("")

                elif ch in (curses.KEY_RESIZE,
                            curses.ascii.FF):  # force screen redraw
                    out = None
                    continue

                elif ch == curses.ascii.ETX:  # Ctrl-C
                    break

        finally:
            endcurses()
Пример #13
0
 def runui(self):
   global HELP_TEXT
   exported.add_help("mudder", HELP_TEXT)
   self.window.Show()
   self.app.MainLoop()
Пример #14
0
def load():
	modutils.load_commands(commands_dict)
	exported.add_help("root.commands.ifvar", ifvar_help)
	exported.remove_help("root.ifvar")