Hacker News new | past | comments | ask | show | jobs | submit login
Clint, Command Line Library for Python (nicosphere.net)
86 points by Nic0 on Jan 6, 2012 | hide | past | favorite | 9 comments



Something about the colored.red(txt) syntax bothers me.

Shouldn't color should really be a parameter - unless the console only accepts a fixed set of colors?

I like the rest of it - using a 'with' block for indentation is clever.


    from clint.textui.color import red, blue, green

    print "{0}, {1}, and {2}".format(red('red'), blue('blue'), green('green'))


Looks to me like colored.red(string) just calls ColoredString(color, string), so you could use that version if you want to parameterize the color argument.

    print ColoredString("red", "some text")


Well, there's nothing wrong with providing a shortcut, although personally I would have preferred a closure:

    printred = colored.print_function("red")
    printred("This prints in red")


Wouldn't this work? I can't test it at the moment.

    print_function = lambda c:  getattr(colored, c)
    printred = colored.print_function("red")
    printred("This prints in red")


Yes, I've seen a bunch of shell and perl utilities that use this approach. You can't use them when you want 256 colors. You can check http://cbouvi.free.fr/download/colorize/ and http://code.google.com/p/ansi-color/.

Ruby has highline and colored, and perhaps some more too.


There's an experimental branch with 256 support. Fallback isn't simple though.


http://pypi.python.org/pypi/termcolor

print colored('Hello, World!', 'red')


Just released for Python 3 as well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: