Gestion de l'encodage pour la fonction prompt (par Stphane).
darcs-hash:20051101170235-41617-47fba016ac1075f704cfb9c5b66919fcf0e85ed2.gz
This commit is contained in:
parent
2f0a98f453
commit
0ab7852e1f
1 changed files with 13 additions and 7 deletions
|
@ -9,6 +9,10 @@ Licence : GPLv2
|
|||
|
||||
import sys, sre, os, tempfile
|
||||
|
||||
# Détermination de l'encodage
|
||||
from locale import getpreferredencoding
|
||||
encoding = getpreferredencoding()
|
||||
|
||||
if 'TERM' in os.environ and os.environ['TERM'] != 'unknown':
|
||||
el = os.popen('tput cr ; tput el').read()
|
||||
else:
|
||||
|
@ -140,13 +144,15 @@ def get_screen_size():
|
|||
except:
|
||||
return (24, 80)
|
||||
|
||||
def prompt(prompt, defaut=''):
|
||||
""" Pose la question prompt, retourne la réponse """
|
||||
sys.stdout.write(coul(prompt,'gras'))
|
||||
def prompt(prompt, defaut='', couleur='gras'):
|
||||
u"""
|
||||
Pose la question prompt en couleur (défaut gras), retourne la réponse.
|
||||
"""
|
||||
sys.stdout.write(coul(prompt, couleur).encode(encoding))
|
||||
if defaut :
|
||||
sys.stdout.write(" ["+defaut+"]")
|
||||
sys.stdout.write(" ")
|
||||
v=sys.stdin.readline().strip()
|
||||
sys.stdout.write((" [%s]" % defaut).encode(encoding))
|
||||
sys.stdout.write(" ".encode(encoding))
|
||||
v = sys.stdin.readline().decode(encoding).strip()
|
||||
if not v: v = defaut
|
||||
return v
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue