Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c706c28d
Commit
c706c28d
authored
Dec 02, 2002
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a better columnizer to print_topics().
parent
3b10dc35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
7 deletions
+58
-7
Lib/cmd.py
Lib/cmd.py
+58
-7
No files found.
Lib/cmd.py
View file @
c706c28d
...
...
@@ -319,10 +319,61 @@ class Cmd:
print
header
if
self
.
ruler
:
print
self
.
ruler
*
len
(
header
)
(
cmds_per_line
,
junk
)
=
divmod
(
maxcol
,
cmdlen
)
col
=
cmds_per_line
for
cmd
in
cmds
:
if
col
==
0
:
print
print
((
"%-"
+
`cmdlen`
+
"s"
)
%
cmd
),
col
=
(
col
+
1
)
%
cmds_per_line
print
"
\
n
"
self
.
columnize
(
cmds
,
maxcol
-
1
)
print
def
columnize
(
self
,
list
,
displaywidth
=
80
):
"""Display a list of strings as a compact set of columns.
Each column is only as wide as necessary.
Columns are separated by two spaces (one was not legible enough).
"""
if
not
list
:
print
"<empty>"
return
nonstrings
=
[
i
for
i
in
range
(
len
(
list
))
if
not
isinstance
(
list
[
i
],
str
)]
if
nonstrings
:
raise
TypeError
,
(
"list[i] not a string for i in %s"
%
", "
.
join
(
map
(
str
,
nonstrings
)))
size
=
len
(
list
)
if
size
==
1
:
print
list
[
0
]
return
# Try every row count from 1 upwards
for
nrows
in
range
(
1
,
len
(
list
)):
ncols
=
(
size
+
nrows
-
1
)
//
nrows
colwidths
=
[]
totwidth
=
-
2
for
col
in
range
(
ncols
):
colwidth
=
0
for
row
in
range
(
nrows
):
i
=
row
+
nrows
*
col
if
i
>=
size
:
break
x
=
list
[
i
]
colwidth
=
max
(
colwidth
,
len
(
x
))
colwidths
.
append
(
colwidth
)
totwidth
+=
colwidth
+
2
if
totwidth
>
displaywidth
:
break
if
totwidth
<=
displaywidth
:
break
else
:
nrows
=
len
(
list
)
ncols
=
1
colwidths
=
[
0
]
for
row
in
range
(
nrows
):
texts
=
[]
for
col
in
range
(
ncols
):
i
=
row
+
nrows
*
col
if
i
>=
size
:
x
=
""
else
:
x
=
list
[
i
]
texts
.
append
(
x
)
while
texts
and
not
texts
[
-
1
]:
del
texts
[
-
1
]
for
col
in
range
(
len
(
texts
)):
texts
[
col
]
=
texts
[
col
].
ljust
(
colwidths
[
col
])
print
" "
.
join
(
texts
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment