Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1dd6d43
Removed terminal_utils.py.
kmvanbrunt Feb 19, 2026
4783455
Restored upgrade documentation.
kmvanbrunt Feb 20, 2026
0f647bb
Deleted terminal_utils.py.
kmvanbrunt Feb 20, 2026
27e28fb
Merge branch 'main' into async_alert
kmvanbrunt Feb 21, 2026
4f68446
Merge branch 'main' into async_alert
kmvanbrunt Feb 22, 2026
00412f4
Moved logic specific to the main command line from Cmd.read_input() t…
kmvanbrunt Feb 24, 2026
6c36faf
Try setting shell to cmd.exe on Windows but bash on Linux or Mac for …
tleonhardt Feb 24, 2026
7a52b45
Try to fix GitHub Actions
tleonhardt Feb 24, 2026
0ce93bf
Try running windows tests using winpty
tleonhardt Feb 24, 2026
76f13b4
Try to fix running windows tests using winpty
tleonhardt Feb 24, 2026
afdafda
Try using powershell on Windows tests
tleonhardt Feb 24, 2026
73a6d9c
Try setting windows test shell to cmd
tleonhardt Feb 24, 2026
db34ca9
Moved call to patch_stdout() right before creating the prompt.
kmvanbrunt Feb 24, 2026
24dfb2b
Put tests.yml back to the way it was originally
tleonhardt Feb 24, 2026
38b4e62
Only wrap self.stdin and self.stdout if they differ from sys equivale…
kmvanbrunt Feb 24, 2026
a39b929
Fixing tests on Windows.
kmvanbrunt Feb 24, 2026
11cdbda
Fixed mock patch.
kmvanbrunt Feb 24, 2026
db30ea3
Added tests.
kmvanbrunt Feb 24, 2026
c488828
Removed obsolete test code.
kmvanbrunt Feb 24, 2026
df1db8a
Added interactive pipe mode.
kmvanbrunt Feb 24, 2026
484930c
Removed need for constants.EOF.
kmvanbrunt Feb 24, 2026
9edd091
Added Ctrl-d test.
kmvanbrunt Feb 24, 2026
712d55d
Renamed a parser builder function to reflect name of the command.
kmvanbrunt Feb 24, 2026
a300f10
Added documentation.
kmvanbrunt Feb 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ cmd2/argparse_*.py @kmvanbrunt @anselor
cmd2/clipboard.py @tleonhardt
cmd2/cmd2.py @tleonhardt @kmvanbrunt
cmd2/colors.py @tleonhardt @kmvanbrunt
cmd2/command_definition.py @anselor
cmd2/command_definition.py @anselor @kmvanbrunt
cmd2/completion.py @kmvanbrunt
cmd2/constants.py @tleonhardt @kmvanbrunt
cmd2/decorators.py @kmvanbrunt @anselor
cmd2/exceptions.py @kmvanbrunt @anselor
Expand All @@ -43,7 +44,6 @@ cmd2/py_bridge.py @kmvanbrunt
cmd2/rich_utils.py @kmvanbrunt
cmd2/string_utils.py @kmvanbrunt
cmd2/styles.py @tleonhardt @kmvanbrunt
cmd2/terminal_utils.py @kmvanbrunt
cmd2/utils.py @tleonhardt @kmvanbrunt

# Documentation
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ prompt is displayed.
`Statement.redirect_to`.
- Changed `StatementParser.parse_command_only()` to return a `PartialStatement` object.
- Renamed `Macro.arg_list` to `Macro.args`.
- Removed `terminal_utils.py` since `prompt-toolkit` provides this functionality.
- Enhancements
- New `cmd2.Cmd` parameters
- **auto_suggest**: (boolean) if `True`, provide fish shell style auto-suggestions. These
Expand Down
2 changes: 0 additions & 2 deletions cmd2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
from .string_utils import stylize
from .styles import Cmd2Style
from .utils import (
CompletionMode,
CustomCompletionSettings,
Settable,
categorize,
Expand Down Expand Up @@ -103,7 +102,6 @@
"Cmd2Style",
# Utilities
'categorize',
'CompletionMode',
'CustomCompletionSettings',
'Settable',
'set_default_str_sort_key',
Expand Down
435 changes: 213 additions & 222 deletions cmd2/cmd2.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd2/completion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Provides classes and functions related to completion."""
"""Provides classes and functions related to command-line completion."""

import re
import sys
Expand Down
3 changes: 2 additions & 1 deletion cmd2/pt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)

from prompt_toolkit import print_formatted_text
from prompt_toolkit.application import get_app
from prompt_toolkit.completion import (
Completer,
Completion,
Expand Down Expand Up @@ -95,7 +96,7 @@ def get_completions(self, document: Document, _complete_event: object) -> Iterab
# and returning early, we trigger a new completion cycle where the quote
# is already present, allowing for proper common prefix calculation.
if completions._add_opening_quote and search_text_length > 0:
buffer = self.cmd_app.session.app.current_buffer
buffer = get_app().current_buffer

buffer.cursor_left(search_text_length)
buffer.insert_text(completions._quote_char)
Expand Down
144 changes: 0 additions & 144 deletions cmd2/terminal_utils.py

This file was deleted.

19 changes: 0 additions & 19 deletions cmd2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
MutableSequence,
)
from difflib import SequenceMatcher
from enum import Enum
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -733,24 +732,6 @@ def get_defining_class(meth: Callable[..., Any]) -> type[Any] | None:
return cast(type, getattr(meth, '__objclass__', None)) # handle special descriptor objects


class CompletionMode(Enum):
"""Enum for what type of completion to perform in cmd2.Cmd.read_input()."""

# Completion will be disabled during read_input() call
# Use of custom up-arrow history supported
NONE = 1

# read_input() will complete cmd2 commands and their arguments
# cmd2's command line history will be used for up arrow if history is not provided.
# Otherwise use of custom up-arrow history supported.
COMMANDS = 2

# read_input() will complete based on one of its following parameters:
# choices, choices_provider, completer, parser
# Use of custom up-arrow history supported
CUSTOM = 3


class CustomCompletionSettings:
"""Used by cmd2.Cmd.complete() to complete strings other than command arguments."""

Expand Down
3 changes: 3 additions & 0 deletions docs/api/completion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# cmd2.completion

::: cmd2.completion
2 changes: 1 addition & 1 deletion docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ incremented according to the [Semantic Version Specification](https://semver.org
- [cmd2.colors](./colors.md) - StrEnum of all color names supported by the Rich library
- [cmd2.command_definition](./command_definition.md) - supports the definition of commands in
separate classes to be composed into cmd2.Cmd
- [cmd2.completion](./completion.md) - classes and functions related to command-line completion
- [cmd2.constants](./constants.md) - constants used in `cmd2`
- [cmd2.decorators](./decorators.md) - decorators for `cmd2` commands
- [cmd2.exceptions](./exceptions.md) - custom `cmd2` exceptions
Expand All @@ -30,5 +31,4 @@ incremented according to the [Semantic Version Specification](https://semver.org
- [cmd2.rich_utils](./rich_utils.md) - common utilities to support Rich in cmd2 applications
- [cmd2.string_utils](./string_utils.md) - string utility functions
- [cmd2.styles](./styles.md) - cmd2-specific Rich styles and a StrEnum of their corresponding names
- [cmd2.terminal_utils](./terminal_utils.md) - support for terminal control escape sequences
- [cmd2.utils](./utils.md) - various utility classes and functions
3 changes: 0 additions & 3 deletions docs/api/terminal_utils.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/features/generating_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ following sections:
- [cmd2.colors][]
- [cmd2.rich_utils][]
- [cmd2.string_utils][]
- [cmd2.terminal_utils][]

The [color.py](https://github.com/python-cmd2/cmd2/blob/main/examples/color.py) example demonstrates
all colors available to your `cmd2` application.
Expand Down
4 changes: 4 additions & 0 deletions docs/upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ See the
example for a demonstration of how to implement a background thread that refreshes the toolbar
periodically.

### Deleted Modules

Removed `rl_utils.py` and `terminal_utils.py` since `prompt-toolkit` provides this functionality.

## Upgrading to cmd2 3.x from 2.x

For details about all of the changes in the 3.0.0 release, please refer to
Expand Down
21 changes: 4 additions & 17 deletions examples/read_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def do_basic_with_history(self, _) -> None:
else:
self.custom_history.append(input_str)

@cmd2.with_category(EXAMPLE_COMMANDS)
def do_commands(self, _) -> None:
"""Call read_input the same way cmd2 prompt does to read commands."""
self.poutput("Tab completing and up-arrow history configured for commands")
with contextlib.suppress(EOFError):
self.read_input("> ", completion_mode=cmd2.CompletionMode.COMMANDS)

@cmd2.with_category(EXAMPLE_COMMANDS)
def do_custom_choices(self, _) -> None:
"""Call read_input to use custom history and choices."""
Expand All @@ -47,17 +40,16 @@ def do_custom_choices(self, _) -> None:
input_str = self.read_input(
"> ",
history=self.custom_history,
completion_mode=cmd2.CompletionMode.CUSTOM,
choices=['choice_1', 'choice_2', 'choice_3'],
)
except EOFError:
pass
else:
self.custom_history.append(input_str)

def choices_provider(self) -> list[str]:
def choices_provider(self) -> cmd2.Choices:
"""Example choices provider function."""
return ["from_provider_1", "from_provider_2", "from_provider_3"]
return cmd2.Choices.from_values(["from_provider_1", "from_provider_2", "from_provider_3"])

@cmd2.with_category(EXAMPLE_COMMANDS)
def do_custom_choices_provider(self, _) -> None:
Expand All @@ -67,7 +59,6 @@ def do_custom_choices_provider(self, _) -> None:
input_str = self.read_input(
"> ",
history=self.custom_history,
completion_mode=cmd2.CompletionMode.CUSTOM,
choices_provider=ReadInputApp.choices_provider,
)
except EOFError:
Expand All @@ -80,9 +71,7 @@ def do_custom_completer(self, _) -> None:
"""Call read_input to use custom history and completer function."""
self.poutput("Tab completing paths and using custom history")
try:
input_str = self.read_input(
"> ", history=self.custom_history, completion_mode=cmd2.CompletionMode.CUSTOM, completer=cmd2.Cmd.path_complete
)
input_str = self.read_input("> ", history=self.custom_history, completer=cmd2.Cmd.path_complete)
self.custom_history.append(input_str)
except EOFError:
pass
Expand All @@ -99,9 +88,7 @@ def do_custom_parser(self, _) -> None:
self.poutput(parser.format_usage())

try:
input_str = self.read_input(
"> ", history=self.custom_history, completion_mode=cmd2.CompletionMode.CUSTOM, parser=parser
)
input_str = self.read_input("> ", history=self.custom_history, parser=parser)
except EOFError:
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ nav:
- api/clipboard.md
- api/colors.md
- api/command_definition.md
- api/completion.md
- api/constants.md
- api/decorators.md
- api/exceptions.md
Expand All @@ -210,7 +211,6 @@ nav:
- api/rich_utils.md
- api/string_utils.md
- api/styles.md
- api/terminal_utils.md
- api/utils.md
- Version Upgrades:
- upgrades.md
Expand Down
Loading
Loading