kyberkits Sat, 25 Jul 2015 20:22:28 +0000 Sat, 25 Jul 2015 20:22:28 +0000 http://kyber.kits.ee/ Jekyll 2.5.3 ANSI Select Graphic Rendition in Python Tue, 03 Feb 2015 20:00:00 +0000 http://kyber.kits.ee/2015/02/03/ansi-sgr-in-python/ http://kyber.kits.ee/2015/02/03/ansi-sgr-in-python/ kyber@kits.ee (Günter Kits) ANSI SGR in Python

The code in this gist gives an easy way to use ANSI SGR parameters in terminal using Python.

The code is lightweight and thou it also already has an example I’ll explain a bit more how to use it.


Examples

First we need to import the module:

from ansi_sgr import *

The example below prints all defined SGR codes as their corresponding styles (RED as red, and BOLD as bold):

for idx, code in enumerate(CODE_MAP):
    if code:
        print ftt(code, idx)

This example combines multiple SGR codes and produces yellow bold text on green background:

print ftt('Yellow bold text on green background', 'YELLOW', 'BOLD', 'BG-GREEN')

Also, the order is irrelevant, the code below gives same result as the code above:

print ftt('The order is irrelevant', 'BG-GREEN', 'YELLOW', 'BOLD')

The last code of same type takes precedence:

print ftt("As long as same type of style isn't overwritten", 'BG-GREEN', 'YELLOW', 'BOLD', 'BG-RED')
]]>
Tere maailm! Thu, 01 Jan 1970 00:00:01 +0000 http://kyber.kits.ee/1970/01/01/tere-maailm/ http://kyber.kits.ee/1970/01/01/tere-maailm/ kyber@kits.ee (Günter Kits) Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sed efficitur ligula. Pellentesque ex nunc, pellentesque sit amet enim vel, auctor placerat lectus. Nullam a imperdiet dolor. Aenean tempor massa at ligula mollis ullamcorper. Curabitur porttitor, nisl in lacinia facilisis, nisl urna mattis enim, nec consequat purus est et nibh.

Integer at congue mauris. Phasellus lacus mauris, ornare nec aliquet ut, dictum non nunc. Duis sed nisi eget risus facilisis facilisis eu at leo. Ut dui ipsum, aliquam vitae mi eget, tincidunt rutrum nulla. Phasellus sit amet eleifend quam, non dapibus nisi. Praesent nec magna sit amet sapien mattis bibendum. Sed lobortis faucibus turpis vitae tempus. Etiam at quam elit. Fusce ut dui iaculis, maximus mauris blandit, vulputate ex. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus volutpat turpis non elementum egestas.

Tere Python’i maailm

def hello(s):
    return ' '.join(["tere", s]).title()

print hello("maailm!")
]]>
Hello World! Thu, 01 Jan 1970 00:00:01 +0000 http://kyber.kits.ee/1970/01/01/hello-world/ http://kyber.kits.ee/1970/01/01/hello-world/ kyber@kits.ee (Günter Kits) Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sed efficitur ligula. Pellentesque ex nunc, pellentesque sit amet enim vel, auctor placerat lectus. Nullam a imperdiet dolor. Aenean tempor massa at ligula mollis ullamcorper. Curabitur porttitor, nisl in lacinia facilisis, nisl urna mattis enim, nec consequat purus est et nibh.

Integer at congue mauris. Phasellus lacus mauris, ornare nec aliquet ut, dictum non nunc. Duis sed nisi eget risus facilisis facilisis eu at leo. Ut dui ipsum, aliquam vitae mi eget, tincidunt rutrum nulla. Phasellus sit amet eleifend quam, non dapibus nisi. Praesent nec magna sit amet sapien mattis bibendum. Sed lobortis faucibus turpis vitae tempus. Etiam at quam elit. Fusce ut dui iaculis, maximus mauris blandit, vulputate ex. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus volutpat turpis non elementum egestas.

Hello Python World

def hello(s):
    return ' '.join(["hello", s]).title()

print hello("world!")
]]>