pySim-shell: add "dir" command.

pysim-shell does not have a convinient way to list the files available
in one directory. Tab completion currently is the only way to obtain a
list of the available files. Lets add a dir command to print a file
list.

Change-Id: Ic06a60e0a0ec54d9bb26e151453ceb49d69e3df7
Related: OS#4963
This commit is contained in:
Philipp Maier
2021-02-22 17:22:16 +01:00
parent bd8ed2c4db
commit 5d3e2592f7
2 changed files with 52 additions and 1 deletions

View File

@@ -794,3 +794,25 @@ def sw_match(sw, pattern):
else:
sw_masked = sw_masked + sw_lower[i]
return sw_masked == pattern
def tabulate_str_list(str_list, width = 79, hspace = 2, lspace = 1, align_left = True):
"""Pretty print a list of strings into a tabulated form"""
if str_list == None:
return ""
if len(str_list) <= 0:
return ""
longest_str = max(str_list, key=len)
cellwith = len(longest_str) + hspace
cols = width // cellwith
rows = (len(str_list) - 1) // cols + 1
table = []
for i in iter(range(rows)):
str_list_row = str_list[i::rows]
if (align_left):
format_str_cell = '%%-%ds'
else:
format_str_cell = '%%%ds'
format_str_row = (format_str_cell % cellwith) * len(str_list_row)
format_str_row = (" " * lspace) + format_str_row
table.append(format_str_row % tuple(str_list_row))
return '\n'.join(table)