|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright (C) 2024 Rocky Bernstein <rocky@gnu.org> |
| 3 | +# |
| 4 | +# This program is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation, either version 3 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | +# |
| 9 | +# This program is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +# Our local modules |
| 18 | +from trepan.lib.complete import complete_token |
| 19 | +from trepan.processor.command.base_subcmd import DebuggerSubcommand |
| 20 | + |
| 21 | +from trepan.interfaces.user import DEFAULT_USER_SETTINGS |
| 22 | + |
| 23 | +class ShowHistory(DebuggerSubcommand): |
| 24 | + """**show history** [ *filename* | *save* | *size* ] |
| 25 | +
|
| 26 | + Show history information |
| 27 | +
|
| 28 | + options include: |
| 29 | + * size: Show the size of the command history. |
| 30 | + * filename Show the filename in which to record the command historyh. |
| 31 | +
|
| 32 | + Examples: |
| 33 | + -------- |
| 34 | + (trepan3k) show history size |
| 35 | + The size of the command history is 50. |
| 36 | +
|
| 37 | + (trepan3k) show history |
| 38 | + history filename: The filename in which to record the command history is "/home/joe/.trepan3k_hist". |
| 39 | + history save: Saving of the history record on exit is on. |
| 40 | + history size: The size of the command history is 50. |
| 41 | + """ |
| 42 | + |
| 43 | + min_abbrev = len("his") |
| 44 | + need_stack = False |
| 45 | + short_help = "Generic command for showing command history parameters" |
| 46 | + |
| 47 | + def complete(self, prefix): |
| 48 | + return complete_token(("filename", "save", "size")) |
| 49 | + |
| 50 | + def run(self, args): |
| 51 | + opts = self.debugger.settings |
| 52 | + show_prefix = False |
| 53 | + if len(args) == 0: |
| 54 | + args = ("filename", "save", "size") |
| 55 | + show_prefix = True |
| 56 | + |
| 57 | + for arg in args: |
| 58 | + prefix = f"history {arg}: " if show_prefix else "" |
| 59 | + if arg == "filename": |
| 60 | + self.msg(f'{prefix}The filename in which to record the command history is "{self.proc.intf[-1].histfile}".') |
| 61 | + elif arg == "save": |
| 62 | + self.msg(f'{prefix}Saving of the history record on exit is {"on" if opts.get("hist_save", False) else "off"}.') |
| 63 | + elif arg == "size": |
| 64 | + self.msg(f'{prefix}The size of the command history is {DEFAULT_USER_SETTINGS["histsize"]}.') |
| 65 | + else: |
| 66 | + self.errmsg(f"Undefined show history command: {arg}") |
| 67 | + pass |
| 68 | + return |
| 69 | + |
| 70 | + pass |
| 71 | + |
| 72 | + |
| 73 | +if __name__ == "__main__": |
| 74 | + from trepan.processor.command.set_subcmd.__demo_helper__ import demo_run |
| 75 | + |
| 76 | + sub = demo_run(ShowHistory, []) |
| 77 | + d = sub.proc.debugger |
| 78 | + sub.run([]) |
| 79 | + sub.run(["filename"]) |
| 80 | + sub.run(["save"]) |
| 81 | + sub.run(["size"]) |
| 82 | + sub.run(["foo"]) |
| 83 | + pass |
0 commit comments