示例#1
0
 def test_ignore_curse_errors_raise_exception(self):
     """
     Check that if an exception that is not from curse, it is not ignored.
     """
     with self.assertRaises(LookupError):
         with ignore_curse_errors():
             raise LookupError
示例#2
0
 def output(self):
     if not self.activated:
         return
     for func in [self.outputCaps, self.outputBase, self.outputBox,
                  self.outputBorder]:
         with ignore_curse_errors():
             func()
示例#3
0
    def output(self, controller):
        # TODO: Maybe add methods to the controller to access `stdscr`
        stdscr = controller.stdscr
        decorator = self.decorator
        before = self.before
        after = self.after
        middle = decorator + self.match
        minx, miny, maxx, maxy = controller.getChromeBoundaries()
        y = miny + self.index + controller.getScrollOffset()

        if y < miny or y > maxy:
            # wont be displayed!
            return

        max_len = maxx - minx
        with ignore_curse_errors():
            # beginning
            stdscr.addstr(y, minx, before)
            # bolded middle
            x_index = len(before)

            self.set_color_pairs()
            stdscr.addstr(y, minx + x_index, middle[:max(max_len - x_index, 0)],
                          self.color_pair)
            # end
            x_index = len(before) + len(middle)
            stdscr.addstr(y, minx + x_index, after[:max(max_len - x_index, 0)])
示例#4
0
 def test_ignore_curse_errors_no_exception(self):
     """
     Check that if no exception is raised, the result is still the same.
     """
     with ignore_curse_errors():
         result = 42
     self.assertEqual(result, 42)
示例#5
0
 def test_ignore_curse_errors_raise_from_curse(self):
     """
     Check that if an exception from curse is raised, it is ignored.
     """
     # If the exception is ignored, the test passes. Otherwise it doesn't
     # because an exception is raised.
     with ignore_curse_errors():
         raise curses.error
示例#6
0
    def output(self, controller):
        # TODO: Maybe add methods to the controller to access `stdscr`
        stdscr = controller.stdscr

        minx, miny, maxx, _ = controller.getChromeBoundaries()
        max_len = maxx - minx
        y = miny + self.index + controller.getScrollOffset()
        with ignore_curse_errors():
            stdscr.addstr(y, minx, str(self)[:max_len])
示例#7
0
 def output(self):
     if not self.activated:
         return
     for func in [
             self.outputCaps, self.outputBase, self.outputBox,
             self.outputBorder
     ]:
         with ignore_curse_errors():
             func()
示例#8
0
    def showAndGetCommand(self):
        fileObjs = self.getFilesToUse()
        files = [fileObj.file for fileObj in fileObjs]
        maxy, maxx = self.screen_dimensions
        halfHeight = int(round(maxy / 2) - len(files) / 2.0)

        borderLine = '=' * len(SHORT_COMMAND_PROMPT)
        promptLine = '.' * len(SHORT_COMMAND_PROMPT)
        # from helper chrome code
        maxFileLength = maxx - 5
        if self.helperChrome.is_sidebar_mode:
            # need to be shorter to not go into side bar
            maxFileLength = len(SHORT_COMMAND_PROMPT) + 18

        # first lets print all the files
        startHeight = halfHeight - 1 - len(files)
        with ignore_curse_errors():
            self.stdscr.addstr(startHeight - 3, 0, borderLine)
            self.stdscr.addstr(startHeight - 2, 0, SHORT_FILES_HEADER)
            self.stdscr.addstr(startHeight - 1, 0, borderLine)
            for index, file in enumerate(files):
                self.stdscr.addstr(startHeight + index, 0,
                                   file[0:maxFileLength])

        # first print prompt
        with ignore_curse_errors():
            self.stdscr.addstr(halfHeight, 0, SHORT_COMMAND_PROMPT)
            self.stdscr.addstr(halfHeight + 1, 0, SHORT_COMMAND_PROMPT2)

        # then line to distinguish and prompt line
        with ignore_curse_errors():
            self.stdscr.addstr(halfHeight - 1, 0, borderLine)
            self.stdscr.addstr(halfHeight + 2, 0, borderLine)
            self.stdscr.addstr(halfHeight + 3, 0, promptLine)

        self.stdscr.refresh()
        curses.echo()
        maxX = int(round(maxx - 1))
        command = self.stdscr.getstr(halfHeight + 3, 0, maxX)
        return command
示例#9
0
    def showAndGetCommand(self):
        fileObjs = self.getFilesToUse()
        files = [fileObj.file for fileObj in fileObjs]
        maxy, maxx = self.screen_dimensions
        halfHeight = int(round(maxy / 2) - len(files) / 2.0)

        borderLine = '=' * len(SHORT_COMMAND_PROMPT)
        promptLine = '.' * len(SHORT_COMMAND_PROMPT)
        # from helper chrome code
        maxFileLength = maxx - 5
        if self.helperChrome.is_sidebar_mode:
            # need to be shorter to not go into side bar
            maxFileLength = len(SHORT_COMMAND_PROMPT) + 18

        # first lets print all the files
        startHeight = halfHeight - 1 - len(files)
        with ignore_curse_errors():
            self.stdscr.addstr(startHeight - 3, 0, borderLine)
            self.stdscr.addstr(startHeight - 2, 0, SHORT_FILES_HEADER)
            self.stdscr.addstr(startHeight - 1, 0, borderLine)
            for index, file in enumerate(files):
                self.stdscr.addstr(startHeight + index, 0,
                                   file[0:maxFileLength])

        # first print prompt
        with ignore_curse_errors():
            self.stdscr.addstr(halfHeight, 0, SHORT_COMMAND_PROMPT)
            self.stdscr.addstr(halfHeight + 1, 0, SHORT_COMMAND_PROMPT2)

        # then line to distinguish and prompt line
        with ignore_curse_errors():
            self.stdscr.addstr(halfHeight - 1, 0, borderLine)
            self.stdscr.addstr(halfHeight + 2, 0, borderLine)
            self.stdscr.addstr(halfHeight + 3, 0, promptLine)

        self.stdscr.refresh()
        curses.echo()
        maxX = int(round(maxx - 1))
        command = self.stdscr.getstr(halfHeight + 3, 0, maxX)
        return command
示例#10
0
 def output(self, mode):
     self.mode = mode
     for func in [self.outputSide, self.outputBottom, self.toggleCursor]:
         with ignore_curse_errors():
             func()
示例#11
0
 def output(self, mode):
     self.mode = mode
     for func in [self.outputSide, self.outputBottom, self.toggleCursor]:
         with ignore_curse_errors():
             func()