Exemplo n.º 1
0
 def to_str(self, index):
     s = ""
     if self.is_link():
         s += cindex('({0}) '.format(index), color=cfg.colors[cfg.g.BACKGROUND]["cindex_link"])
     else:
         s += cindex('({0}) '.format(index))
     s += self.tag
     if len(self.keys) > 1:
         s += '...'
     return s
Exemplo n.º 2
0
def show_short_url(short_url, long_url=None, expanded=None):
    print(cindex(short_url, color=cfg.colors[cfg.g.BACKGROUND]["cindex"]))
    if long_url and expanded:
        expanded = simplify_url(expanded)
        if expanded == long_url:
            feedback = cindex("(match)", color="green")
        else:
            feedback = cindex("(differs)", color="red")
        print('# expanded from shortened URL: {url} {f}'.format(url=expanded, f=feedback))
    text_to_clipboards(short_url)
    print("# use show() to zoom in")
Exemplo n.º 3
0
def subcommand(li):
    def is_link(k):
        return Hit(tag=None, key=k).is_link()

    for index, k in enumerate(li, start=1):
        if is_link(k):
            pre = cindex('[{0}]'.format(index), color=cfg.colors[cfg.g.BACKGROUND]["cindex_link"])
        else:
            pre = cindex('[{0}]'.format(index))
        print("{pre} {main_tag} ({doc})".format(
            pre=pre,
            main_tag=hdict[k]["tags"][0],
            doc=hdict[k]["doc"]
        ))
    print("[q] <<")
    while True:
        try:
            inp = raw_input("~~> ").strip()
        except (KeyboardInterrupt, EOFError):
            print()
            return None
        if len(inp) == 0:
            continue
        if inp == 'q':
            return None
        if inp == 'qq':
            my_exit(0)
        try:
            index = int(inp) - 1
            if index < 0:
                raise IndexError
            perform_action(li[index])
            return
        except IndexError:
            print("out of range...")
        except ValueError:
            print('Wat?')