Beispiel #1
0
    def updateDecoratedMatch(self, maxLen=None):
        '''Update the cached decorated match formatted string, and
        dirty the line, if needed'''
        if self.hovered and self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_RED, 0)
        elif self.hovered:
            attributes = (curses.COLOR_WHITE, curses.COLOR_BLUE, 0)
        elif self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_GREEN, 0)
        elif not self.allInput:
            attributes = (0, 0, FormattedText.UNDERLINE_ATTRIBUTE)
        else:
            attributes = (0, 0, 0)

        decoratorText = self.getDecorator()

        # we may not be connected to a controller (during processInput,
        # for example)
        if self.controller:
            self.controller.dirtyLine(self.index)

        plainText = decoratorText + self.getMatch()
        if maxLen and len(plainText) > maxLen:
            # alright, we need to chop the ends off of our
            # decorated match and glue them together with our
            # truncation decorator
            spaceAllowed = maxLen - len(self.TRUNCATE_DECORATOR)
            midPoint = int(spaceAllowed / 2)
            beginMatch = plainText[0:midPoint]
            endMatch = plainText[-midPoint:len(plainText)]
            plainText = beginMatch + self.TRUNCATE_DECORATOR + endMatch

        self.decoratedMatch = FormattedText(
            FormattedText.getSequenceForAttributes(*attributes) + plainText)
Beispiel #2
0
    def updateDecoratedMatch(self):
        '''Update the cached decorated match formatted string'''
        if self.hovered and self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_RED, 0)
        elif self.hovered:
            attributes = (curses.COLOR_WHITE, curses.COLOR_BLUE, 0)
        elif self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_GREEN, 0)
        else:
            attributes = (0, 0, FormattedText.UNDERLINE_ATTRIBUTE)

        decoratorText = self.getDecorator()
        self.decoratedMatch = FormattedText(
            FormattedText.getSequenceForAttributes(*attributes) +
            decoratorText + self.getMatch())

        # because decorators add length to the line, when the decorator
        # is removed, we need to print blank space (aka "erase") the
        # part of the line that is stale. calculate how much this is based
        # on the max length decorator.
        self.endingClearText = FormattedText(
            FormattedText.getSequenceForAttributes(
                FormattedText.DEFAULT_COLOR_FOREGROUND,
                FormattedText.DEFAULT_COLOR_BACKGROUND,
                0) +
            " " * (self.getMaxDecoratorLength() - len(decoratorText)))
Beispiel #3
0
    def updateDecoratedMatch(self):
        '''Update the cached decorated match formatted string'''
        if self.hovered and self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_RED, 0)
        elif self.hovered:
            attributes = (curses.COLOR_WHITE, curses.COLOR_BLUE, 0)
        elif self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_GREEN, 0)
        else:
            attributes = (0, 0, FormattedText.UNDERLINE_ATTRIBUTE)

        self.decoratedMatch = FormattedText(
            FormattedText.getSequenceForAttributes(*attributes) +
            self.getDecorator() + self.getMatch())
Beispiel #4
0
def getLineObjsFromLines(inputLines, validateFileExists=True, allInput=False):
    lineObjs = {}
    for index, line in enumerate(inputLines):
        line = line.replace('\t', '    ')
        # remove the new line as we place the cursor ourselves for each
        # line. this avoids curses errors when we newline past the end of the
        # screen
        line = line.replace('\n', '')
        formattedLine = FormattedText(line)
        result = parse.matchLine(str(formattedLine),
                                 validateFileExists=validateFileExists,
                                 allInput=allInput)

        if not result:
            line = format.SimpleLine(formattedLine, index)
        else:
            line = format.LineMatch(formattedLine,
                                    result,
                                    index,
                                    validateFileExists=validateFileExists,
                                    allInput=allInput)

        lineObjs[index] = line

    return lineObjs
Beispiel #5
0
 def testUnresolvable(self):
     fileLine = ".../something/foo.py"
     result = parse.matchLine(fileLine)
     lineObj = format.LineMatch(FormattedText(fileLine), result, 0)
     self.assertTrue(not lineObj.isResolvable(),
                     '"%s" should not be resolvable' % fileLine)
     print('Tested unresolvable case.')
Beispiel #6
0
    def updateDecoratedMatch(self, maxLen=None):
        '''Update the cached decorated match formatted string, and
        dirty the line, if needed'''
        if self.hovered and self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_RED, 0)
        elif self.hovered:
            attributes = (curses.COLOR_WHITE, curses.COLOR_BLUE, 0)
        elif self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_GREEN, 0)
        elif not self.allInput:
            attributes = (0, 0, FormattedText.UNDERLINE_ATTRIBUTE)
        else:
            attributes = (0, 0, 0)

        decoratorText = self.getDecorator()

        # we may not be connected to a controller (during processInput,
        # for example)
        if self.controller:
            self.controller.dirtyLine(self.index)

        plainText = decoratorText + self.getMatch()
        if maxLen and len(plainText) > maxLen:
            # alright, we need to chop the ends off of our
            # decorated match and glue them together with our
            # truncation decorator
            spaceAllowed = maxLen - len(self.TRUNCATE_DECORATOR)
            midPoint = int(spaceAllowed / 2)
            beginMatch = plainText[0:midPoint]
            endMatch = plainText[-midPoint:len(plainText)]
            plainText = beginMatch + self.TRUNCATE_DECORATOR + endMatch

        self.decoratedMatch = FormattedText(
            FormattedText.getSequenceForAttributes(*attributes) +
            plainText)
Beispiel #7
0
    def testResolvable(self):
        toCheck = [case for case in fileTestCases if case['match']]
        for testCase in toCheck:
            result = parse.matchLine(testCase['input'])
            lineObj = format.LineMatch(FormattedText(testCase['input']),
                                       result, 0)
            self.assertTrue(lineObj.isResolvable(),
                            'Line "%s" was not resolvable' % testCase['input'])
        print('Tested %d resolvable cases.' % len(toCheck))

    def testFileMatch(self):
        for testCase in fileTestCases:
            self.checkFileResult(testCase)
        print('Tested %d cases.' % len(fileTestCases))

    def checkFileResult(self, testCase):
        result = parse.matchLine(testCase['input'])
        if not result:
            self.assertFalse(
                testCase['match'],
                'Line "%s" did not match any regex' % testCase['input'])
            return

        file, num, match = result
        self.assertTrue(testCase['match'],
                        'Line "%s" did match' % testCase['input'])

        self.assertEqual(
            testCase['file'], file,
            'files not equal |%s| |%s|' % (testCase['file'], file))

        self.assertEqual(
            testCase['num'], num, 'num matches not equal %d %d for %s' %
            (testCase['num'], num, testCase.get('input')))
Beispiel #8
0
    def testResolvable(self):
        toCheck = [case for case in fileTestCases if case['match']]
        for testCase in toCheck:
            result = parse.matchLine(testCase['input'])
            lineObj = format.LineMatch(FormattedText(testCase['input']),
                                       result, 0)
            self.assertTrue(lineObj.isResolvable(),
                            'Line "%s" was not resolvable' % testCase['input'])
        print('Tested %d resolvable cases.' % len(toCheck))

    def testFileMatch(self):
        for testCase in fileTestCases:
            self.checkFileResult(testCase)
        print('Tested %d cases.' % len(fileTestCases))

    def testAllInputMatches(self):
        for testCase in allInputTestCases:
            result = parse.matchLine(testCase['input'], False, True)

            if not result:
                self.assertTrue(
                    testCase['match'] is None,
                    'Expected a match "%s" where one did not occur.' %
                    testCase['match'])

                continue

            (match, _, _) = result
            self.assertEqual(match, testCase['match'],
                             'Line "%s" did not match.' % testCase['input'])

        print('Tested %d cases for all-input matching.' %
              len(allInputTestCases))

    def checkFileResult(self, testCase):
        result = parse.matchLine(testCase['input'],
                                 validateFileExists=testCase.get(
                                     'validateFileExists', False))
        if not result:
            self.assertFalse(
                testCase['match'],
                'Line "%s" did not match any regex' % testCase['input'])
            return

        file, num, match = result
        self.assertTrue(testCase['match'],
                        'Line "%s" did match' % testCase['input'])

        self.assertEqual(
            testCase['file'], file,
            'files not equal |%s| |%s|' % (testCase['file'], file))

        self.assertEqual(
            testCase.get('num', 0), num, 'num matches not equal %d %d for %s' %
            (testCase.get('num', 0), num, testCase.get('input')))
Beispiel #9
0
def getLineObjs():
    inputLines = sys.stdin.readlines()
    lineObjs = {}
    for index, line in enumerate(inputLines):
        line = line.replace('\t', '    ')
        formattedLine = FormattedText(line)
        result = parse.matchLine(str(formattedLine))

        if not result:
            line = format.SimpleLine(formattedLine, index)
        else:
            line = format.LineMatch(formattedLine, result, index)

        lineObjs[index] = line

    return lineObjs
Beispiel #10
0
    def updateDecoratedMatch(self):
        '''Update the cached decorated match formatted string, and
        dirty the line, if needed'''
        if self.hovered and self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_RED, 0)
        elif self.hovered:
            attributes = (curses.COLOR_WHITE, curses.COLOR_BLUE, 0)
        elif self.selected:
            attributes = (curses.COLOR_WHITE, curses.COLOR_GREEN, 0)
        else:
            attributes = (0, 0, FormattedText.UNDERLINE_ATTRIBUTE)

        decoratorText = self.getDecorator()

        # we may not be connected to a controller (during processInput,
        # for example)
        if self.controller:
            self.controller.dirtyLine(self.index)

        self.decoratedMatch = FormattedText(
            FormattedText.getSequenceForAttributes(*attributes) +
            decoratorText + self.getMatch())
Beispiel #11
0
# print (ABSPATH)
# print (sys.path)
import logger
import parse
from formattedText import FormattedText

PathMarker_buffer_file = os.path.expanduser('~/.PathMarker')
open(PathMarker_buffer_file, 'a').close()
theline = ""

if __name__ == "__main__":
    if sys.argv[1] == "set":
        count = 0
        f = open(PathMarker_buffer_file,"w")
        for name in sys.stdin.readlines():
            formattedLine = FormattedText(name)
            result=parse.matchLine(str(formattedLine), allInput=False)
            if result:
                path = parse.prependDir(result[0], withFileInspection=False)
                count += 1
                sys.stdout.write("%d\t%s" % (count, name))
                f.write("%s\n" % path)
            else:
                sys.stdout.write("\t%s" % (name))
        f.close

    if sys.argv[1] == "setall":
        count = 0
        f = open(PathMarker_buffer_file,"w")
        for name in sys.stdin.readlines():
            formattedLine = FormattedText(name)