diff --git a/scripts/codemap.py b/scripts/codemap.py index fe871299..99f5e120 100755 --- a/scripts/codemap.py +++ b/scripts/codemap.py @@ -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,23 +1369,47 @@ 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) - ring.draw() + # 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 if Inotify: @@ -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', diff --git a/scripts/dbgbmap.py b/scripts/dbgbmap.py index dad03c07..dd3d63b5 100755 --- a/scripts/dbgbmap.py +++ b/scripts/dbgbmap.py @@ -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='?', diff --git a/scripts/plot.py b/scripts/plot.py index 36f5d05d..3c591d32 100755 --- a/scripts/plot.py +++ b/scripts/plot.py @@ -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( diff --git a/scripts/tracebd.py b/scripts/tracebd.py index e8540aff..700ae743 100755 --- a/scripts/tracebd.py +++ b/scripts/tracebd.py @@ -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( diff --git a/scripts/treemap.py b/scripts/treemap.py index 5ffa3259..39c3a02d 100755 --- a/scripts/treemap.py +++ b/scripts/treemap.py @@ -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,23 +1250,47 @@ 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) - ring.draw() + # 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 if Inotify: @@ -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',