pacman plugin added. It's only stupid os.system(cmd) class,
[AurShell.git] / showinfo.py
blob3a76048271b4d711d8bdb483cd1779455bc9d12b
1 import sys
3 try:
4 import conf
5 except ImportError:
6 sys.exit("Can't find conf module.")
10 class Put(object):
11 """Show info class"""
12 def __init__(self, stdout=None, stdin=None):
13 """Set stdout and stdin"""
14 if not stdout:
15 self.stdout = sys.stdout
16 else:
17 self.stdout = stdout
18 if not stdin:
19 self.stdin = sys.stdin
20 else:
21 self.stdin = stdin
23 def __call__(self, message, color=None, newline=True, *ignore):
24 """Show message on stdout
26 message - message that would be shown
27 color - opional color of the message
28 newline - end with newline?
29 """
30 if not color:
31 self.show(message, newline)
32 else:
33 self.color(message, color, newline)
36 def show(self, message="", newline=True, *ignore):
37 """Default message printer"""
38 if newline:
39 self.stdout.write(message + "\n")
40 else:
41 self.stdout.write(message)
43 def read(self, message=""):
44 if message:
45 self.show(message + " ", newline=False)
46 return self.stdin.readline()
48 def ask(self, question, color=None, answer=" [Y/n]"):
49 while True:
50 self.color(question + answer, color, False)
51 a = self.stdin.readline()
52 if a in "Yy":
53 return True
54 elif a in "Nn":
55 return False
58 def color(self, msg, color=None, newline=False):
59 """Print message with colors
60 By default it doesn't end with new line character.
61 """
62 if not color:
63 color = "none"
64 self.show(conf.color[color] + msg + conf.color["none"], newline)