mercurial/ui.py
author mpm@selenic.com
Wed, 08 Jun 2005 10:59:18 -0800
changeset 281 574420507d8c
parent 249 619e775aa7f9
child 285 5a1e6d27f399
permissions -rw-r--r--
hg cat: relative file support -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 hg cat: relative file support also fix a bug in relpath From: K Thananchayan <thananck@yahoo.com> manifest hash: a443a66dfb90b38ea491de1e817b2877170bc9f8 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp0AGywK+sNU5EO8RAgfVAJ9vlXfLKs1A/TegG3wuPeuxoSQMCACbBPGF RObiYj1st0k1zQYBlvSlQbk= =GZbB -----END PGP SIGNATURE-----
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
249
619e775aa7f9 import and startup cleanups
mpm@selenic.com
parents: 241
diff changeset
     8
import os, sys, re
207
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)
234
3427806d5ab9 ui.warn can use more than one argument like the other ui methods.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 207
diff changeset
    33
    def warn(self, *msg):
207
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):
249
619e775aa7f9 import and startup cleanups
mpm@selenic.com
parents: 241
diff changeset
    40
        import tempfile
207
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    41
        (fd, name) = tempfile.mkstemp("hg")
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    42
        f = os.fdopen(fd, "w")
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    43
        f.write(text)
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    44
        f.close()
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    45
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    46
        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
    47
        r = os.system("%s %s" % (editor, name))
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    48
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    49
        if r:
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    50
            raise "Edit failed!"
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    51
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    52
        t = open(name).read()
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    53
        t = re.sub("(?m)^HG:.*\n", "", t)
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    54
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    55
        return t
ec327cf0d3a9 Move ui class to its own module
mpm@selenic.com
parents:
diff changeset
    56