MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / __init__

Method __init__

examples/getting_started.py:38–94  ·  view source on GitHub ↗

Initialize the cmd2 application.

(self)

Source from the content-addressed store, hash-verified

36 DEFAULT_CATEGORY = "My Custom Commands"
37
38 def __init__(self) -> None:
39 """Initialize the cmd2 application."""
40 # Startup script that defines a couple aliases for running shell commands
41 alias_script = pathlib.Path(__file__).absolute().parent / ".cmd2rc"
42
43 # Create a shortcut for one of our commands
44 shortcuts = cmd2.DEFAULT_SHORTCUTS
45 shortcuts.update({"&": "intro"})
46 super().__init__(
47 auto_suggest=True,
48 bottom_toolbar=True,
49 include_ipy=True,
50 multiline_commands=["echo"],
51 persistent_history_file="cmd2_history.dat",
52 shortcuts=shortcuts,
53 startup_script=str(alias_script),
54 )
55
56 # Spawn a background thread to refresh the bottom toolbar twice a second.
57 # This is necessary because the toolbar contains a timestamp that we want to keep current.
58 self._stop_refresh = False
59 self._refresh_thread = threading.Thread(target=self._refresh_bottom_toolbar, daemon=True)
60 self._refresh_thread.start()
61
62 # Prints an intro banner once upon application startup
63 self.intro = (
64 stylize(
65 "Welcome to cmd2!",
66 style=Style(color=Color.GREEN1, bgcolor=Color.GRAY0, bold=True),
67 )
68 + " Note the full Unicode support: 😇 💩"
69 + " and the persistent bottom bar with realtime status updates!"
70 )
71
72 # Show this as the prompt when asking for input
73 self.prompt = "myapp> "
74
75 # Used as prompt for multiline commands after the first line
76 self.continuation_prompt = "... "
77
78 # Allow access to your application in py and ipy via self
79 self.self_in_py = True
80
81 # Color to output text in with echo command
82 self.foreground_color = Color.CYAN.value
83
84 # Make echo_fg settable at runtime
85 fg_colors = [c.value for c in Color]
86 self.add_settable(
87 cmd2.Settable(
88 "foreground_color",
89 str,
90 "Foreground color to use with echo command",
91 self,
92 choices=fg_colors,
93 )
94 )
95

Callers

nothing calls this directly

Calls 2

stylizeFunction · 0.90
add_settableMethod · 0.45

Tested by

no test coverage detected