static_var n'a pas vraiment de raison d'être dans affichage.py
This commit is contained in:
parent
394531a537
commit
3f1b7401ca
2 changed files with 23 additions and 21 deletions
20
cranslib/decorators.py
Normal file
20
cranslib/decorators.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import functools
|
||||
|
||||
def static_var(*couples):
|
||||
"""Decorator setting static variable
|
||||
to a function.
|
||||
|
||||
"""
|
||||
# Using setattr magic, we set static
|
||||
# variable on function. This avoid
|
||||
# computing stuff again.
|
||||
def decorate(fun):
|
||||
functools.wraps(fun)
|
||||
for (name, val) in couples:
|
||||
setattr(fun, name, val)
|
||||
return fun
|
||||
return decorate
|
||||
|
|
@ -8,10 +8,6 @@
|
|||
# Contenu :
|
||||
# ---------
|
||||
#
|
||||
# Décorateur :
|
||||
# static_var([(name, val)]), un décorateur pour créer des variables
|
||||
# statiques dans une fonction
|
||||
#
|
||||
# Fonctions :
|
||||
# getTerminalSize(), une fonction qui récupère le couple
|
||||
# largeur, hauteur du terminal courant.
|
||||
|
@ -39,12 +35,13 @@ import os
|
|||
import fcntl
|
||||
import termios
|
||||
import struct
|
||||
import functools
|
||||
import time
|
||||
import re
|
||||
|
||||
from locale import getpreferredencoding
|
||||
|
||||
from cranslib.decorators import static_var
|
||||
|
||||
OCT_NAMES = ["Pio", "Tio", "Gio", "Mio", "Kio"]
|
||||
OCT_SIZES = [1024**(len(OCT_NAMES) - i) for i in xrange(0, len(OCT_NAMES))]
|
||||
TERM_FORMAT = '\x1b\[[0-1];([0-9]|[0-9][0-9])m'
|
||||
|
@ -90,21 +87,6 @@ def guess_preferred_encoding():
|
|||
|
||||
return encoding
|
||||
|
||||
def static_var(couples):
|
||||
"""Decorator setting static variable
|
||||
to a function.
|
||||
|
||||
"""
|
||||
# Using setattr magic, we set static
|
||||
# variable on function. This avoid
|
||||
# computing stuff again.
|
||||
def decorate(fun):
|
||||
functools.wraps(fun)
|
||||
for (name, val) in couples:
|
||||
setattr(fun, name, val)
|
||||
return fun
|
||||
return decorate
|
||||
|
||||
def getTerminalSize():
|
||||
"""Dummy function to get term dimensions.
|
||||
Thanks to http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python
|
||||
|
@ -278,7 +260,7 @@ def nostyle(dialog=False):
|
|||
return "\Zn"
|
||||
return "\033[1;0m"
|
||||
|
||||
@static_var([("styles", {})])
|
||||
@static_var(("styles", {}))
|
||||
def style(texte, what=None, dialog=False):
|
||||
"""Pretty text is pretty
|
||||
On peut appliquer plusieurs styles d'affilée, ils seront alors traités
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue