forked from Imagelibrary/littlefs
scripts: Adopted -n/--lines in most ascii art scripts
The notable exception being plot.py, where line-level history doesn't really make sense. These scripts all default to height=1, and -n/--lines can be useful for viewing changes over time. In theory you could achieve something similar to this with tailpipe.py, but you would lose the header info, which is useful. --- Note, as a point of simplicity, we do _not_ show sub-char history like we used to in tracebd.py. That was way too complicated for what it was worth.
This commit is contained in:
@@ -1357,8 +1357,11 @@ def main_(f, paths, *,
|
||||
|
||||
|
||||
def main(paths, *,
|
||||
width=None,
|
||||
height=None,
|
||||
no_header=None,
|
||||
keep_open=False,
|
||||
lines=None,
|
||||
head=False,
|
||||
cat=False,
|
||||
sleep=False,
|
||||
@@ -1366,22 +1369,46 @@ def main(paths, *,
|
||||
# keep-open?
|
||||
if keep_open:
|
||||
try:
|
||||
# keep track of history if lines specified
|
||||
if lines is not None:
|
||||
ring = RingIO(lines+1
|
||||
if not no_header and lines > 0
|
||||
else lines)
|
||||
while True:
|
||||
# register inotify before running the command, this avoids
|
||||
# modification race conditions
|
||||
if Inotify:
|
||||
inotify = Inotify(paths)
|
||||
|
||||
# cat? write directly to stdout
|
||||
if cat:
|
||||
main_(sys.stdout, paths,
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1,
|
||||
height=-1 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
# not cat? write to a bounded ring
|
||||
else:
|
||||
ring = RingIO(head=head)
|
||||
main_(ring, paths,
|
||||
height=height if height is not False else 0,
|
||||
ring_ = RingIO(head=head)
|
||||
main_(ring_, paths,
|
||||
width=width,
|
||||
height=0 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
# no history? draw immediately
|
||||
if lines is None:
|
||||
ring_.draw()
|
||||
# history? merge with previous lines
|
||||
else:
|
||||
# write header separately?
|
||||
if not no_header:
|
||||
if not ring.lines:
|
||||
ring.lines.append('')
|
||||
ring.lines.extend(it.islice(ring_.lines, 1, None))
|
||||
ring.lines[0] = ring_.lines[0]
|
||||
else:
|
||||
ring.lines.extend(ring_.lines)
|
||||
ring.draw()
|
||||
|
||||
# try to inotifywait
|
||||
@@ -1402,8 +1429,10 @@ def main(paths, *,
|
||||
# single-pass?
|
||||
else:
|
||||
main_(sys.stdout, paths,
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1,
|
||||
height=-1 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
|
||||
|
||||
@@ -1518,7 +1547,7 @@ if __name__ == "__main__":
|
||||
'-H', '--height',
|
||||
nargs='?',
|
||||
type=lambda x: int(x, 0),
|
||||
const=False,
|
||||
const=..., # handles shell prompt spacing, which is a bit subtle
|
||||
help="Height in rows. <=0 uses the terminal height. Defaults "
|
||||
"to 1.")
|
||||
parser.add_argument(
|
||||
@@ -1630,6 +1659,13 @@ if __name__ == "__main__":
|
||||
'-k', '--keep-open',
|
||||
action='store_true',
|
||||
help="Continue to open and redraw the CSV files in a loop.")
|
||||
parser.add_argument(
|
||||
'-n', '--lines',
|
||||
nargs='?',
|
||||
type=lambda x: int(x, 0),
|
||||
const=0,
|
||||
help="Show this many lines of history. <=0 uses the terminal "
|
||||
"height. Defaults to 1.")
|
||||
parser.add_argument(
|
||||
'-^', '--head',
|
||||
action='store_true',
|
||||
|
||||
@@ -4821,7 +4821,9 @@ def main_(f, disk, mroots=None, *,
|
||||
|
||||
|
||||
def main(disk, mroots=None, *,
|
||||
width=None,
|
||||
height=None,
|
||||
no_header=None,
|
||||
keep_open=False,
|
||||
lines=None,
|
||||
head=False,
|
||||
@@ -4834,7 +4836,7 @@ def main(disk, mroots=None, *,
|
||||
# keep track of history if lines specified
|
||||
if lines is not None:
|
||||
ring = RingIO(lines+1
|
||||
if not args.get('no_header') and lines > 0
|
||||
if not no_header and lines > 0
|
||||
else lines)
|
||||
while True:
|
||||
# register inotify before running the command, this avoids
|
||||
@@ -4842,18 +4844,21 @@ def main(disk, mroots=None, *,
|
||||
if Inotify:
|
||||
inotify = Inotify([disk])
|
||||
|
||||
# TODO sync these comments
|
||||
# cat? write directly to stdout
|
||||
if cat:
|
||||
main_(sys.stdout, disk, mroots,
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1,
|
||||
height=-1 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
# not cat? write to a bounded ring
|
||||
else:
|
||||
ring_ = RingIO(head=head)
|
||||
main_(ring_, disk, mroots,
|
||||
height=height if height is not False else 0,
|
||||
width=width,
|
||||
height=0 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
# no history? draw immediately
|
||||
if lines is None:
|
||||
@@ -4861,7 +4866,7 @@ def main(disk, mroots=None, *,
|
||||
# history? merge with previous lines
|
||||
else:
|
||||
# write header separately?
|
||||
if not args.get('no_header'):
|
||||
if not no_header:
|
||||
if not ring.lines:
|
||||
ring.lines.append('')
|
||||
ring.lines.extend(it.islice(ring_.lines, 1, None))
|
||||
@@ -4888,8 +4893,10 @@ def main(disk, mroots=None, *,
|
||||
# single-pass?
|
||||
else:
|
||||
main_(sys.stdout, disk, mroots,
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1,
|
||||
height=-1 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
|
||||
|
||||
@@ -4996,7 +5003,7 @@ if __name__ == "__main__":
|
||||
'-H', '--height',
|
||||
nargs='?',
|
||||
type=lambda x: int(x, 0),
|
||||
const=False,
|
||||
const=..., # handles shell prompt spacing, which is a bit subtle
|
||||
help="Height in rows. <=0 uses the terminal height. Defaults "
|
||||
"to 1.")
|
||||
parser.add_argument(
|
||||
@@ -5079,7 +5086,6 @@ if __name__ == "__main__":
|
||||
'-k', '--keep-open',
|
||||
action='store_true',
|
||||
help="Continue to open and redraw the CSV files in a loop.")
|
||||
# TODO drop this?
|
||||
parser.add_argument(
|
||||
'-n', '--lines',
|
||||
nargs='?',
|
||||
|
||||
@@ -1801,6 +1801,7 @@ def main_(f, csv_paths, *,
|
||||
|
||||
|
||||
def main(csv_paths, *,
|
||||
width=None,
|
||||
height=None,
|
||||
keep_open=False,
|
||||
head=False,
|
||||
@@ -1816,15 +1817,19 @@ def main(csv_paths, *,
|
||||
if Inotify:
|
||||
inotify = Inotify(csv_paths)
|
||||
|
||||
# cat? write directly to stdout
|
||||
if cat:
|
||||
main_(sys.stdout, csv_paths,
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1,
|
||||
height=-1 if height is ... else height,
|
||||
**args)
|
||||
# not cat? write to a bounded ring
|
||||
else:
|
||||
ring = RingIO(head=head)
|
||||
main_(ring, csv_paths,
|
||||
height=height if height is not False else 0,
|
||||
width=width,
|
||||
height=0 if height is ... else height,
|
||||
**args)
|
||||
ring.draw()
|
||||
|
||||
@@ -1846,8 +1851,9 @@ def main(csv_paths, *,
|
||||
# single-pass?
|
||||
else:
|
||||
main_(sys.stdout, csv_paths,
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1,
|
||||
height=-1 if height is ... else height,
|
||||
**args)
|
||||
|
||||
|
||||
@@ -1969,7 +1975,7 @@ if __name__ == "__main__":
|
||||
'-H', '--height',
|
||||
nargs='?',
|
||||
type=lambda x: int(x, 0),
|
||||
const=False,
|
||||
const=..., # handles shell prompt spacing, which is a bit subtle
|
||||
help="Height in rows. <=0 uses the terminal height. Defaults "
|
||||
"to 17.")
|
||||
parser.add_argument(
|
||||
|
||||
@@ -2511,13 +2511,13 @@ def main(path='-', *,
|
||||
# other scripts?
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1)
|
||||
height=-1 if height is ... else height)
|
||||
# not cat? write to a bounded ring
|
||||
else:
|
||||
ring_ = RingIO(head=head)
|
||||
draw__(ring_,
|
||||
width=width,
|
||||
height=height if height is not False else 0)
|
||||
height=0 if height is ... else height)
|
||||
# no history? draw immediately
|
||||
if lines is None:
|
||||
ring_.draw()
|
||||
@@ -2704,7 +2704,7 @@ if __name__ == "__main__":
|
||||
'-H', '--height',
|
||||
nargs='?',
|
||||
type=lambda x: int(x, 0),
|
||||
const=False,
|
||||
const=..., # handles shell prompt spacing, which is a bit subtle
|
||||
help="Height in rows. <=0 uses the terminal height. Defaults "
|
||||
"to 1.")
|
||||
parser.add_argument(
|
||||
|
||||
@@ -1238,8 +1238,11 @@ def main_(f, csv_paths, *,
|
||||
|
||||
|
||||
def main(csv_paths, *,
|
||||
width=None,
|
||||
height=None,
|
||||
no_header=None,
|
||||
keep_open=False,
|
||||
lines=None,
|
||||
head=False,
|
||||
cat=False,
|
||||
sleep=False,
|
||||
@@ -1247,22 +1250,46 @@ def main(csv_paths, *,
|
||||
# keep-open?
|
||||
if keep_open:
|
||||
try:
|
||||
# keep track of history if lines specified
|
||||
if lines is not None:
|
||||
ring = RingIO(lines+1
|
||||
if not no_header and lines > 0
|
||||
else lines)
|
||||
while True:
|
||||
# register inotify before running the command, this avoids
|
||||
# modification race conditions
|
||||
if Inotify:
|
||||
inotify = Inotify(csv_paths)
|
||||
|
||||
# cat? write directly to stdout
|
||||
if cat:
|
||||
main_(sys.stdout, csv_paths,
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1,
|
||||
height=-1 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
# not cat? write to a bounded ring
|
||||
else:
|
||||
ring = RingIO(head=head)
|
||||
main_(ring, csv_paths,
|
||||
height=height if height is not False else 0,
|
||||
ring_ = RingIO(head=head)
|
||||
main_(ring_, csv_paths,
|
||||
width=width,
|
||||
height=0 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
# no history? draw immediately
|
||||
if lines is None:
|
||||
ring_.draw()
|
||||
# history? merge with previous lines
|
||||
else:
|
||||
# write header separately?
|
||||
if not no_header:
|
||||
if not ring.lines:
|
||||
ring.lines.append('')
|
||||
ring.lines.extend(it.islice(ring_.lines, 1, None))
|
||||
ring.lines[0] = ring_.lines[0]
|
||||
else:
|
||||
ring.lines.extend(ring_.lines)
|
||||
ring.draw()
|
||||
|
||||
# try to inotifywait
|
||||
@@ -1283,8 +1310,10 @@ def main(csv_paths, *,
|
||||
# single-pass?
|
||||
else:
|
||||
main_(sys.stdout, csv_paths,
|
||||
width=width,
|
||||
# make space for shell prompt
|
||||
height=height if height is not False else -1,
|
||||
height=-1 if height is ... else height,
|
||||
no_header=no_header,
|
||||
**args)
|
||||
|
||||
|
||||
@@ -1381,7 +1410,7 @@ if __name__ == "__main__":
|
||||
'-H', '--height',
|
||||
nargs='?',
|
||||
type=lambda x: int(x, 0),
|
||||
const=False,
|
||||
const=..., # handles shell prompt spacing, which is a bit subtle
|
||||
help="Height in rows. <=0 uses the terminal height. Defaults "
|
||||
"to 1.")
|
||||
parser.add_argument(
|
||||
@@ -1475,6 +1504,13 @@ if __name__ == "__main__":
|
||||
'-k', '--keep-open',
|
||||
action='store_true',
|
||||
help="Continue to open and redraw the CSV files in a loop.")
|
||||
parser.add_argument(
|
||||
'-n', '--lines',
|
||||
nargs='?',
|
||||
type=lambda x: int(x, 0),
|
||||
const=0,
|
||||
help="Show this many lines of history. <=0 uses the terminal "
|
||||
"height. Defaults to 1.")
|
||||
parser.add_argument(
|
||||
'-^', '--head',
|
||||
action='store_true',
|
||||
|
||||
Reference in New Issue
Block a user