annotate mercurial/ui.py @ 207:ec327cf0d3a9

Move ui class to its own module -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Move ui class to its own module manifest hash: f75c8f9cdfe16f143ab633d0072c14ba88ac88be -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCnVxxywK+sNU5EO8RAgPgAJ48p7w4Do/saCC8WkBvHj/rdnoiEgCgrSs9 Wu1fOSgST3rn/2JpZAdFRdA= =91tt -----END PGP SIGNATURE-----
author mpm@selenic.com
date Tue, 31 May 2005 22:57:53 -0800
parents
children 3427806d5ab9 4f802588cdfb afe895fcc0d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
1 # ui.py - user interface bits for mercurial
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
2 #
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
4 #
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
5 # This software may be used and distributed according to the terms
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
6 # of the GNU General Public License, incorporated herein by reference.
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
7
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
8 import os, tempfile, sys, re
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
9
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
10 class ui:
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
11 def __init__(self, verbose=False, debug=False, quiet=False,
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
12 interactive=True):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
13 self.quiet = quiet and not verbose and not debug
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
14 self.verbose = verbose or debug
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
15 self.debugflag = debug
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
16 self.interactive = interactive
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
17 def write(self, *args):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
18 for a in args:
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
19 sys.stdout.write(str(a))
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
20 def readline(self):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
21 return sys.stdin.readline()[:-1]
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
22 def prompt(self, msg, pat, default = "y"):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
23 if not self.interactive: return default
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
24 while 1:
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
25 self.write(msg, " ")
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
26 r = self.readline()
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
27 if re.match(pat, r):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
28 return r
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
29 else:
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
30 self.write("unrecognized response\n")
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
31 def status(self, *msg):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
32 if not self.quiet: self.write(*msg)
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
33 def warn(self, msg):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
34 self.write(*msg)
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
35 def note(self, *msg):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
36 if self.verbose: self.write(*msg)
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
37 def debug(self, *msg):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
38 if self.debugflag: self.write(*msg)
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
39 def edit(self, text):
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
40 (fd, name) = tempfile.mkstemp("hg")
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
41 f = os.fdopen(fd, "w")
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
42 f.write(text)
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
43 f.close()
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
44
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
45 editor = os.environ.get("HGEDITOR") or os.environ.get("EDITOR", "vi")
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
46 r = os.system("%s %s" % (editor, name))
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
47
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
48 if r:
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
49 raise "Edit failed!"
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
50
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
51 t = open(name).read()
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
52 t = re.sub("(?m)^HG:.*\n", "", t)
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
53
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
54 return t
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
55