Example #1
0
def print_pixel(colour, value_range, invert=1):
    global colour_range
    chars = [".", ".", "+", "*", "%", "#"]
    idx = lambda chars: (colour + 1) * (len(chars) - 1) / value_range
    if invert:
        idx = lambda chars, idx=idx: len(chars) - 1 - idx(chars)
    char = chars[idx(chars)]
    ansi_colour = palette[idx(palette)]
    ansi_print(char, ansi_colour, newline=False, flush=True)
Example #2
0
def print_pixel(colour, value_range, invert=1):
    global colour_range
    chars = [".", ".", "+", "*", "%", "#"]
    idx = lambda chars: (colour+1) * (len(chars) - 1) / value_range
    if invert:
        idx = lambda chars, idx=idx:len(chars) - 1 - idx(chars)
    char = chars[idx(chars)]
    ansi_colour = palette[idx(palette)]
    ansi_print(char, ansi_colour, newline=False, flush=True)
Example #3
0
def main():
    (options, args) = parser.parse_args()
    string = args[0]
    if options.ignorecase:
        string = string.lower()
    for x in curdir.visit('*.py', rec):
        # match filename directly
        s = x.relto(curdir)
        if options.ignorecase:
            s = s.lower()
        if s.find(string) != -1:
            print >> sys.stdout, "%s: filename matches %r" % (x, string)

        try:
            s = x.read()
        except py.error.ENOENT:
            pass  # whatever, probably broken link (ie emacs lock)
        searchs = s
        if options.ignorecase:
            searchs = s.lower()
        if s.find(string) != -1:
            lines = s.splitlines()
            if options.ignorecase:
                searchlines = s.lower().splitlines()
            else:
                searchlines = lines
            for i, (line, searchline) in enumerate(zip(lines, searchlines)):
                indexes = find_indexes(searchline, string)
                if not indexes:
                    continue
                if not options.context:
                    sys.stdout.write("%s:%d: " % (x.relto(curdir), i + 1))
                    last_index = 0
                    for index in indexes:
                        sys.stdout.write(line[last_index:index])
                        ansi_print(line[index:index + len(string)],
                                   file=sys.stdout,
                                   esc=31,
                                   newline=False)
                        last_index = index + len(string)
                    sys.stdout.write(line[last_index:] + "\n")
                else:
                    context = (options.context) / 2
                    for count in range(max(0, i - context),
                                       min(len(lines) - 1, i + context + 1)):
                        print "%s:%d:  %s" % (x.relto(curdir), count + 1,
                                              lines[count].rstrip())
                    print "-" * terminal_width
Example #4
0
 def __call__(self, msg):
     tty = self.isatty()
     flush = False
     newline = True
     keywords = []
     esc = []
     for kw in msg.keywords:
         color, supress = self.kw_to_color.get(kw, (None, False))
         if color:
             esc.extend(color)
         if not supress:
             keywords.append(kw)
     if 'start' in keywords:
         if tty:
             newline = False
             flush = True
             keywords.remove('start')
     elif 'done' in keywords:
         if tty:
             print >> sys.stderr
             return
     elif 'dot' in keywords:
         if tty:
             if self.fancy:
                 if not AnsiLog.wrote_dot:
                     self.mandelbrot_driver.reset()
                 self.mandelbrot_driver.dot()
             else:
                 ansi_print(".",
                            tuple(esc),
                            file=self.file,
                            newline=False,
                            flush=flush)
             AnsiLog.wrote_dot = True
             return
     if AnsiLog.wrote_dot:
         AnsiLog.wrote_dot = False
         sys.stderr.write("\n")
     esc = tuple(esc)
     for line in msg.content().splitlines():
         ansi_print("[%s] %s" % (":".join(keywords), line),
                    esc,
                    file=self.file,
                    newline=newline,
                    flush=flush)
Example #5
0
def main():
    (options, args) = parser.parse_args()
    string = args[0]
    if options.ignorecase:
        string = string.lower()
    for x in curdir.visit('*.py', rec):
        # match filename directly
        s = x.relto(curdir)
        if options.ignorecase:
            s = s.lower()
        if s.find(string) != -1:
           print >>sys.stdout, "%s: filename matches %r" %(x, string)

        try:
            s = x.read()
        except py.error.ENOENT:
            pass # whatever, probably broken link (ie emacs lock)
        searchs = s
        if options.ignorecase:
            searchs = s.lower()
        if s.find(string) != -1:
            lines = s.splitlines()
            if options.ignorecase:
                searchlines = s.lower().splitlines()
            else:
                searchlines = lines
            for i, (line, searchline) in enumerate(zip(lines, searchlines)): 
                indexes = find_indexes(searchline, string)
                if not indexes:
                    continue
                if not options.context:
                    sys.stdout.write("%s:%d: " %(x.relto(curdir), i+1))
                    last_index = 0
                    for index in indexes:
                        sys.stdout.write(line[last_index: index])
                        ansi_print(line[index: index+len(string)],
                                   file=sys.stdout, esc=31, newline=False)
                        last_index = index + len(string)
                    sys.stdout.write(line[last_index:] + "\n")
                else:
                    context = (options.context)/2
                    for count in range(max(0, i-context), min(len(lines) - 1, i+context+1)):
                        print "%s:%d:  %s" %(x.relto(curdir), count+1, lines[count].rstrip())
                    print "-" * terminal_width
Example #6
0
 def __call__(self, msg):
     tty = self.isatty()
     flush = False
     newline = True
     keywords = []
     esc = []
     for kw in msg.keywords:
         color, supress = self.kw_to_color.get(kw, (None, False))
         if color:
             esc.extend(color)
         if not supress:
             keywords.append(kw)
     if 'start' in keywords:
         if tty:
             newline = False
             flush = True
             keywords.remove('start')
     elif 'done' in keywords:
         if tty:
             print >> sys.stderr
             return
     elif 'dot' in keywords:
         if tty:
             if self.fancy:
                 if not AnsiLog.wrote_dot:
                     self.mandelbrot_driver.reset()
                 self.mandelbrot_driver.dot()
             else:
                 ansi_print(".", tuple(esc), file=self.file, newline=False, flush=flush)
             AnsiLog.wrote_dot = True
             return
     if AnsiLog.wrote_dot:
         AnsiLog.wrote_dot = False
         sys.stderr.write("\n")
     esc = tuple(esc)
     for line in msg.content().splitlines():
         ansi_print("[%s] %s" %(":".join(keywords), line), esc, 
                    file=self.file, newline=newline, flush=flush)