annotate Lib/cmd.py @ 10123:bc287c6cfa23 legacy-trunk

Restructured a bit.
author Guido van Rossum <guido@python.org>
date Mon, 08 Feb 1999 22:27:18 +0000
parents e71f83922392
children 52206532d389
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # A generic class to build line-oriented command interpreters
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
2 #
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
3 # Interpreters constructed with this class obey the following conventions:
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
4 #
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
5 # 1. End of file on input is processed as the command 'EOF'.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
6 # 2. A command is parsed out of each line by collecting the prefix composed
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
7 # of characters in the identchars member.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
8 # 3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
9 # is passed a single argument consisting of the remainder of the line.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
10 # 4. Typing an empty line repeats the last command. (Actually, it calls the
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
11 # method `emptyline', which may be overridden in a subclass.)
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
12 # 5. There is a predefined `help' method. Given an argument `topic', it
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
13 # calls the command `help_topic'. With no arguments, it lists all topics
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
14 # with defined help_ functions, broken into up to three topics; documented
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
15 # commands, miscellaneous help topics, and undocumented commands.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
16 # 6. The command '?' is a synonym for `help'. The command '!' is a synonym
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
17 # for `shell', if a do_shell method exists.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
18 #
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
19 # The `default' method may be overridden to intercept commands for which there
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
20 # is no do_ method.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
21 #
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
22 # The data member `self.ruler' sets the character used to draw separator lines
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
23 # in the help messages. If empty, no ruler line is drawn. It defaults to "=".
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
24 #
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
25 # If the value of `self.intro' is nonempty when the cmdloop method is called,
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
26 # it is printed out on interpreter startup. This value may be overridden
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
27 # via an optional argument to the cmdloop() method.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
28 #
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
29 # The data members `self.doc_header', `self.misc_header', and
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
30 # `self.undoc_header' set the headers used for the help function's
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
31 # listings of documented functions, miscellaneous topics, and undocumented
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
32 # functions respectively.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
33 #
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
34 # These interpreters use raw_input; thus, if the readline module is loaded,
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
35 # they automatically support Emacs-like command history and editing features.
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
36 #
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 import string
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 import sys
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 import linecache
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 PROMPT = '(Cmd) '
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 IDENTCHARS = string.letters + string.digits + '_'
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 class Cmd:
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
46 prompt = PROMPT
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
47 identchars = IDENTCHARS
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
48 ruler = '='
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
49 lastcmd = ''
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
50 cmdqueue = []
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
51 intro = None
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
52 doc_leader = ""
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
53 doc_header = "Documented commands (type help <topic>):"
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
54 misc_header = "Miscellaneous help topics:"
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
55 undoc_header = "Undocumented commands:"
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
56 nohelp = "*** No help on %s"
1315
acdc0b9a6c78 * aifc.py: don't die on invalid MARK chunk
Guido van Rossum <guido@python.org>
parents: 1086
diff changeset
57
8615
e7822b64a33d Gotta have an __init__() method -- pdb.py calls it!
Guido van Rossum <guido@python.org>
parents: 8584
diff changeset
58 def __init__(self): pass
e7822b64a33d Gotta have an __init__() method -- pdb.py calls it!
Guido van Rossum <guido@python.org>
parents: 8584
diff changeset
59
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
60 def cmdloop(self, intro=None):
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
61 self.preloop()
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
62 if intro != None:
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
63 self.intro = intro
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
64 if self.intro:
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
65 print self.intro
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 stop = None
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 while not stop:
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
68 if self.cmdqueue:
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
69 line = self.cmdqueue[0]
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
70 del self.cmdqueue[0]
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
71 else:
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
72 try:
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
73 line = raw_input(self.prompt)
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
74 except EOFError:
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
75 line = 'EOF'
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
76 line = self.precmd(line)
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 stop = self.onecmd(line)
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
78 stop = self.postcmd(stop, line)
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
79 self.postloop()
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
80
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
81 def precmd(self, line):
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
82 return line
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
83
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
84 def postcmd(self, stop, line):
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
85 return stop
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
86
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
87 def preloop(self):
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
88 pass
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
89
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
90 def postloop(self):
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
91 pass
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 def onecmd(self, line):
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 line = string.strip(line)
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
95 if line == '?':
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
96 line = 'help'
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
97 elif line == '!':
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
98 if hasattr(self, 'do_shell'):
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
99 line = 'shell'
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
100 else:
8689
de540166d732 Fix another bug in ESR's changes. In order to work properly,
Guido van Rossum <guido@python.org>
parents: 8615
diff changeset
101 return self.default(line)
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
102 elif not line:
8689
de540166d732 Fix another bug in ESR's changes. In order to work properly,
Guido van Rossum <guido@python.org>
parents: 8615
diff changeset
103 return self.emptyline()
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
104 self.lastcmd = line
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 i, n = 0, len(line)
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 while i < n and line[i] in self.identchars: i = i+1
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 cmd, arg = line[:i], string.strip(line[i:])
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 if cmd == '':
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 return self.default(line)
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 else:
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 try:
1086
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 979
diff changeset
112 func = getattr(self, 'do_' + cmd)
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 except AttributeError:
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 return self.default(line)
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 return func(arg)
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
117 def emptyline(self):
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
118 if self.lastcmd:
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
119 return self.onecmd(self.lastcmd)
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
120
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 def default(self, line):
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 print '*** Unknown syntax:', line
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 def do_help(self, arg):
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 if arg:
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 # XXX check arg syntax
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 try:
1086
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 979
diff changeset
128 func = getattr(self, 'help_' + arg)
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 except:
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
130 print self.nohelp % (arg,)
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 return
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 func()
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 else:
9089
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
134 # Inheritance says we have to look in class and
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
135 # base classes; order is not important.
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
136 names = []
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
137 classes = [self.__class__]
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
138 while classes:
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
139 aclass = classes[0]
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
140 if aclass.__bases__:
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
141 classes = classes + list(aclass.__bases__)
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
142 names = names + dir(aclass)
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
143 del classes[0]
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
144 cmds_doc = []
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
145 cmds_undoc = []
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
146 help = {}
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
147 for name in names:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
148 if name[:5] == 'help_':
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
149 help[name[5:]]=1
9089
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
150 names.sort()
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
151 # There can be duplicates if routines overridden
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
152 prevname = ''
624
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 for name in names:
0e436200bf12 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 if name[:3] == 'do_':
9089
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
155 if name == prevname:
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
156 continue
e71f83922392 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 9053
diff changeset
157 prevname = name
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
158 cmd=name[3:]
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
159 if help.has_key(cmd):
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
160 cmds_doc.append(cmd)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
161 del help[cmd]
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
162 else:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
163 cmds_undoc.append(cmd)
9053
16f8397d8f04 Changes by Richard Wolff:
Guido van Rossum <guido@python.org>
parents: 8689
diff changeset
164 print self.doc_leader
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
165 self.print_topics(self.doc_header, cmds_doc, 15,80)
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
166 self.print_topics(self.misc_header, help.keys(),15,80)
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
167 self.print_topics(self.undoc_header, cmds_undoc, 15,80)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
168
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
169 def print_topics(self, header, cmds, cmdlen, maxcol):
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
170 if cmds:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
171 print header;
8584
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
172 if self.ruler:
cb7fcfb56275 Improved by Eric Raymond.
Guido van Rossum <guido@python.org>
parents: 8410
diff changeset
173 print self.ruler * len(header)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
174 (cmds_per_line,junk)=divmod(maxcol,cmdlen)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
175 col=cmds_per_line
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
176 for cmd in cmds:
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
177 if col==0: print
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
178 print (("%-"+`cmdlen`+"s") % cmd),
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
179 col = (col+1) % cmds_per_line
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
180 print "\n"