usecli 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. {usecli-0.2.0 → usecli-0.2.1}/PKG-INFO +6 -6
  2. {usecli-0.2.0 → usecli-0.2.1}/pyproject.toml +12 -12
  3. {usecli-0.2.0 → usecli-0.2.1}/pyproject.toml.orig +14 -12
  4. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/base/about_command.py +7 -24
  5. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/core/utils.py +2 -2
  6. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/init_command.py +1 -5
  7. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/config/colors.py +2 -4
  8. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/base_command.py +1 -1
  9. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/exceptions/validation.py +3 -1
  10. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/runtime.py +2 -2
  11. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/ui/title.py +1 -6
  12. usecli-0.2.1/src/usecli/cli/utils/interactive/prompt_input.py +143 -0
  13. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/progress.py +1 -1
  14. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/config/manager.py +30 -11
  15. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/upgrades/pyproject.py +1 -5
  16. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/ui.py +5 -0
  17. usecli-0.2.1/src/usecli/usecli.config.toml +44 -0
  18. usecli-0.2.0/src/usecli/usecli.config.toml +0 -21
  19. {usecli-0.2.0 → usecli-0.2.1}/LICENSE +0 -0
  20. {usecli-0.2.0 → usecli-0.2.1}/README.md +0 -0
  21. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/__init__.py +0 -0
  22. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/bundler/__init__.py +0 -0
  23. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/bundler/__main__.py +0 -0
  24. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/__init__.py +0 -0
  25. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/README.md +0 -0
  26. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/__init__.py +0 -0
  27. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/custom/README.md +0 -0
  28. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/custom/__init__.py +0 -0
  29. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/__init__.py +0 -0
  30. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/base/__init__.py +0 -0
  31. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/base/help_command.py +0 -0
  32. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/base/inspire_command.py +0 -0
  33. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/base/internal/__init__.py +0 -0
  34. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/base/internal/interactive_command.py +0 -0
  35. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/base/upgrade_command.py +0 -0
  36. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/core/__init__.py +0 -0
  37. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/make/__init__.py +0 -0
  38. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/make/make_bundle_command.py +0 -0
  39. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/make/make_command.py +0 -0
  40. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/commands/defaults/make/make_theme_command.py +0 -0
  41. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/config/__init__.py +0 -0
  42. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/__init__.py +0 -0
  43. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/_typer_compat.py +0 -0
  44. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/error/__init__.py +0 -0
  45. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/error/handler.py +0 -0
  46. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/error/utils.py +0 -0
  47. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/exceptions/__init__.py +0 -0
  48. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/exceptions/base.py +0 -0
  49. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/exceptions/config.py +0 -0
  50. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/exceptions/usage.py +0 -0
  51. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/ui/__init__.py +0 -0
  52. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/ui/list.py +0 -0
  53. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/ui/title.txt +0 -0
  54. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/validators/__init__.py +0 -0
  55. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/validators/network.py +0 -0
  56. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/validators/numeric.py +0 -0
  57. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/validators/path.py +0 -0
  58. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/core/validators/string.py +0 -0
  59. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/services/__init__.py +0 -0
  60. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/services/command_service.py +0 -0
  61. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/templates/command.py.j2 +0 -0
  62. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/templates/theme.toml.j2 +0 -0
  63. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/templates/usecli.config.toml.j2 +0 -0
  64. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/ayu_dark.toml +0 -0
  65. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/catppuccin_frappe.toml +0 -0
  66. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/catppuccin_latte.toml +0 -0
  67. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/catppuccin_macchiato.toml +0 -0
  68. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/catppuccin_mocha.toml +0 -0
  69. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/default.toml +0 -0
  70. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/dracula.toml +0 -0
  71. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/gruvbox_dark.toml +0 -0
  72. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/nord.toml +0 -0
  73. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/themes/tokyo_night.toml +0 -0
  74. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/utils/__init__.py +0 -0
  75. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/utils/interactive/__init__.py +0 -0
  76. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/cli/utils/interactive/terminal_menu.py +0 -0
  77. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/entry.py +0 -0
  78. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/menu.py +0 -0
  79. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/params.py +0 -0
  80. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/__init__.py +0 -0
  81. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/config/__init__.py +0 -0
  82. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/config/globals.py +0 -0
  83. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/upgrades/__init__.py +0 -0
  84. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/upgrades/checker.py +0 -0
  85. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/upgrades/discovery.py +0 -0
  86. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/upgrades/installer.py +0 -0
  87. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/upgrades/service.py +0 -0
  88. {usecli-0.2.0 → usecli-0.2.1}/src/usecli/shared/upgrades/settings.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: usecli
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A powerful Python CLI framework for building beautiful, developer-friendly command-line tools.
5
5
  Author: Edward Boswell
6
6
  Author-email: Edward Boswell <thememium@gmail.com>
@@ -10,15 +10,15 @@ Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Intended Audience :: Developers
12
12
  Requires-Dist: case-converter>=1.2.0
13
- Requires-Dist: click>=8.4.2
13
+ Requires-Dist: click>=8.5.1
14
14
  Requires-Dist: jinja2>=3.1.6
15
+ Requires-Dist: prompt-toolkit>=3.0.53
15
16
  Requires-Dist: rich>=15.0.0
16
17
  Requires-Dist: simple-term-menu>=1.6.6
17
- Requires-Dist: tomli>=2.4.1
18
- Requires-Dist: typer>=0.27.0
18
+ Requires-Dist: typer>=0.29.2
19
19
  Requires-Dist: pyfiglet>=1.0.4 ; extra == 'figlet'
20
- Requires-Dist: pyinstaller>=6.21.0 ; extra == 'pyinstaller'
21
- Requires-Python: >=3.10
20
+ Requires-Dist: pyinstaller>=6.22.3 ; extra == 'pyinstaller'
21
+ Requires-Python: >=3.11
22
22
  Project-URL: Homepage, https://github.com/thememium/usecli
23
23
  Project-URL: Documentation, https://github.com/thememium/usecli
24
24
  Project-URL: Repository, https://github.com/thememium/usecli.git
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "usecli"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "A powerful Python CLI framework for building beautiful, developer-friendly command-line tools."
5
5
  readme = "README.md"
6
- requires-python = ">=3.10"
6
+ requires-python = ">=3.11"
7
7
  classifiers = [
8
8
  "Programming Language :: Python :: 3",
9
9
  "Operating System :: OS Independent",
@@ -11,12 +11,12 @@ classifiers = [
11
11
  ]
12
12
  dependencies = [
13
13
  "case-converter>=1.2.0",
14
- "click>=8.4.2",
14
+ "click>=8.5.1",
15
15
  "jinja2>=3.1.6",
16
+ "prompt-toolkit>=3.0.53",
16
17
  "rich>=15.0.0",
17
18
  "simple-term-menu>=1.6.6",
18
- "tomli>=2.4.1",
19
- "typer>=0.27.0",
19
+ "typer>=0.29.2",
20
20
  ]
21
21
  license = "MIT"
22
22
  license-files = ["LICEN[CS]E*"]
@@ -27,7 +27,7 @@ email = "thememium@gmail.com"
27
27
 
28
28
  [project.optional-dependencies]
29
29
  figlet = ["pyfiglet>=1.0.4"]
30
- pyinstaller = ["pyinstaller>=6.21.0"]
30
+ pyinstaller = ["pyinstaller>=6.22.3"]
31
31
 
32
32
  [project.urls]
33
33
  Homepage = "https://github.com/thememium/usecli"
@@ -47,14 +47,14 @@ build-backend = "uv_build"
47
47
  [dependency-groups]
48
48
  dev = [
49
49
  "deptry>=0.25.1",
50
- "isort>=8.0.1",
51
- "poethepoet>=0.48.0",
50
+ "isort>=9.0.2",
51
+ "poethepoet>=0.49.0",
52
52
  "pyfiglet>=1.0.4",
53
- "pyinstaller>=6.21.0",
54
- "pytest>=9.1.1",
53
+ "pyinstaller>=6.22.3",
54
+ "pytest>=9.2.0",
55
55
  "pytest-cov>=7.1.0",
56
- "ruff>=0.16.1",
57
- "ty>=0.0.65",
56
+ "ruff>=0.17.5",
57
+ "ty>=0.0.107",
58
58
  ]
59
59
 
60
60
  [tool.deptry]
@@ -1,10 +1,10 @@
1
1
  [project]
2
2
  name = "usecli"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "A powerful Python CLI framework for building beautiful, developer-friendly command-line tools."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Edward Boswell", email = "thememium@gmail.com" }]
7
- requires-python = ">=3.10"
7
+ requires-python = ">=3.11"
8
8
  classifiers = [
9
9
  "Programming Language :: Python :: 3",
10
10
  "Operating System :: OS Independent",
@@ -12,19 +12,21 @@ classifiers = [
12
12
  ]
13
13
  dependencies = [
14
14
  "case-converter>=1.2.0",
15
- "click>=8.4.2",
15
+ "click>=8.5.1",
16
16
  "jinja2>=3.1.6",
17
+ "prompt-toolkit>=3.0.53",
17
18
  "rich>=15.0.0",
18
19
  "simple-term-menu>=1.6.6",
19
- "tomli>=2.4.1",
20
- "typer>=0.27.0",
20
+ "typer>=0.29.2",
21
21
  ]
22
22
  license = "MIT"
23
23
  license-files = ["LICEN[CS]E*"]
24
24
 
25
25
  [project.optional-dependencies]
26
26
  figlet = ["pyfiglet>=1.0.4"]
27
- pyinstaller = ["pyinstaller>=6.21.0"]
27
+ pyinstaller = [
28
+ "pyinstaller>=6.22.3",
29
+ ]
28
30
 
29
31
  [project.urls]
30
32
  Homepage = "https://github.com/thememium/usecli"
@@ -44,14 +46,14 @@ build-backend = "uv_build"
44
46
  [dependency-groups]
45
47
  dev = [
46
48
  "deptry>=0.25.1",
47
- "isort>=8.0.1",
48
- "poethepoet>=0.48.0",
49
+ "isort>=9.0.2",
50
+ "poethepoet>=0.49.0",
49
51
  "pyfiglet>=1.0.4",
50
- "pyinstaller>=6.21.0",
51
- "pytest>=9.1.1",
52
+ "pyinstaller>=6.22.3",
53
+ "pytest>=9.2.0",
52
54
  "pytest-cov>=7.1.0",
53
- "ruff>=0.16.1",
54
- "ty>=0.0.65",
55
+ "ruff>=0.17.5",
56
+ "ty>=0.0.107",
55
57
  ]
56
58
 
57
59
  [tool.deptry]
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import os
4
4
  import sys
5
+ import tomllib
5
6
  from importlib.metadata import PackageNotFoundError
6
7
  from pathlib import Path
7
8
 
@@ -27,24 +28,6 @@ class _LazyConsole:
27
28
  console = _LazyConsole()
28
29
 
29
30
 
30
- def _load_toml(text: str):
31
- if sys.version_info >= (3, 11):
32
- import tomllib
33
- else:
34
- import tomli as tomllib
35
-
36
- return tomllib.loads(text)
37
-
38
-
39
- def _toml_decode_error():
40
- if sys.version_info >= (3, 11):
41
- pass
42
- else:
43
- pass
44
-
45
- return _toml_decode_error()
46
-
47
-
48
31
  def _get_version() -> str:
49
32
  from importlib.metadata import PackageNotFoundError
50
33
  from importlib.metadata import version as get_version
@@ -119,8 +102,8 @@ def _get_dependencies(config) -> list[tuple[str, str | None]]:
119
102
  return []
120
103
 
121
104
  try:
122
- data = _load_toml(pyproject_path.read_text())
123
- except (_toml_decode_error(), OSError):
105
+ data = tomllib.loads(pyproject_path.read_text())
106
+ except (tomllib.TOMLDecodeError, OSError):
124
107
  return []
125
108
 
126
109
  deps = data.get("project", {}).get("dependencies", [])
@@ -185,8 +168,8 @@ def _get_project_description(config) -> str | None:
185
168
  return None
186
169
 
187
170
  try:
188
- data = _load_toml(pyproject_path.read_text())
189
- except (_toml_decode_error(), OSError):
171
+ data = tomllib.loads(pyproject_path.read_text())
172
+ except (tomllib.TOMLDecodeError, OSError):
190
173
  return None
191
174
 
192
175
  description = data.get("project", {}).get("description")
@@ -233,8 +216,8 @@ def _get_script_commands() -> list[str]:
233
216
  return []
234
217
 
235
218
  try:
236
- data = _load_toml(pyproject_path.read_text())
237
- except (_toml_decode_error(), OSError):
219
+ data = tomllib.loads(pyproject_path.read_text())
220
+ except (tomllib.TOMLDecodeError, OSError):
238
221
  return []
239
222
 
240
223
  scripts = data.get("project", {}).get("scripts", {})
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import re
6
6
  import sys
7
- from datetime import datetime, timedelta, timezone
7
+ from datetime import UTC, datetime, timedelta
8
8
  from pathlib import Path
9
9
 
10
10
 
@@ -118,7 +118,7 @@ def format_relative_time(timestamp: datetime) -> str:
118
118
  Returns:
119
119
  Relative time string (e.g., "2 hours ago", "3 days ago").
120
120
  """
121
- now = datetime.now(tz=timezone.utc)
121
+ now = datetime.now(tz=UTC)
122
122
  diff = now - timestamp
123
123
 
124
124
  if diff < timedelta(minutes=1):
@@ -7,6 +7,7 @@ import re
7
7
  import shutil
8
8
  import subprocess
9
9
  import sys
10
+ import tomllib
10
11
  from pathlib import Path
11
12
  from typing import Annotated
12
13
 
@@ -16,11 +17,6 @@ from rich.console import Console
16
17
  from rich.panel import Panel
17
18
  from rich.prompt import Confirm, Prompt
18
19
 
19
- if sys.version_info >= (3, 11):
20
- import tomllib
21
- else:
22
- import tomli as tomllib # pragma: no cover - only on Python < 3.11
23
-
24
20
  from usecli.cli.config.colors import COLOR
25
21
  from usecli.cli.core.base_command import BaseCommand
26
22
  from usecli.cli.core.exceptions import UsecliBadParameter
@@ -23,10 +23,8 @@ logger = logging.getLogger(__name__)
23
23
 
24
24
 
25
25
  def _import_tomllib():
26
- if sys.version_info >= (3, 11):
27
- import tomllib
28
- else:
29
- import tomli as tomllib
26
+ import tomllib
27
+
30
28
  return tomllib
31
29
 
32
30
 
@@ -6,7 +6,7 @@ from abc import ABC, abstractmethod
6
6
  from typing import TYPE_CHECKING, Any, ClassVar
7
7
 
8
8
  if TYPE_CHECKING:
9
- from typing_extensions import Self
9
+ from typing import Self
10
10
 
11
11
  import typer
12
12
  from click.exceptions import Exit
@@ -49,7 +49,9 @@ class UsecliValidationError(UsecliError):
49
49
  style = self.SEVERITY_STYLES.get(severity, self.SEVERITY_STYLES["error"])
50
50
  self.icon = style["icon"]
51
51
  self.color = style["color"]
52
- self.exit_code = 1 if severity in ("error", "critical") else 0
52
+ # click types exit_code as a ClassVar but reads it from the instance;
53
+ # warnings are not failures, so the code differs per severity.
54
+ self.exit_code = 1 if severity in ("error", "critical") else 0 # type: ignore[ty:invalid-attribute-access]
53
55
 
54
56
  def show(self, file: IO[str] | None = None) -> None:
55
57
  """Display validation error with severity styling.
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import json
6
- from collections.abc import Iterator, Mapping
6
+ from collections.abc import Generator, Mapping
7
7
  from contextlib import contextmanager
8
8
  from contextvars import ContextVar
9
9
 
@@ -44,7 +44,7 @@ def execution_context(
44
44
  *,
45
45
  json_mode: bool | None = None,
46
46
  quiet: bool | None = None,
47
- ) -> Iterator[None]:
47
+ ) -> Generator[None, None, None]:
48
48
  """Temporarily set invocation flags and restore their previous values."""
49
49
  json_token = _JSON_MODE.set(json_mode) if json_mode is not None else None
50
50
  quiet_token = _QUIET.set(quiet) if quiet is not None else None
@@ -2,16 +2,11 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import sys
5
+ import tomllib
6
6
  from importlib.metadata import PackageNotFoundError, metadata
7
7
  from pathlib import Path
8
8
  from typing import Any
9
9
 
10
- if sys.version_info >= (3, 11):
11
- import tomllib
12
- else:
13
- import tomli as tomllib # pragma: no cover - only on Python < 3.11
14
-
15
10
  from rich.console import Console
16
11
 
17
12
  from usecli.cli.config.colors import COLOR
@@ -0,0 +1,143 @@
1
+ """Interactive input for rich prompts that stays put.
2
+
3
+ rich's ``Console.input`` prints the prompt itself and then calls builtin
4
+ ``input()`` without one. The system line editor therefore thinks the line
5
+ starts at column 0: cursor keys beep or redraw over the prompt and history
6
+ lands in the wrong place.
7
+
8
+ Handing the prompt to ``input()`` fixes that only on GNU readline. macOS uses
9
+ libedit, which moves ANSI escapes out of the prompt (dropping the colors) and
10
+ still counts their bytes as visible width. prompt_toolkit measures the
11
+ rich-rendered prompt itself, so patching ``Console.input`` -- the seam used by
12
+ every rich prompt method (``Prompt``, ``Confirm``, ``IntPrompt``, direct
13
+ ``console.input``) -- gives correct colors, wrapping, cursor keys and history
14
+ everywhere.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import sys
20
+ from typing import Any, TextIO
21
+
22
+ # One session per process so answers can be recalled with the up arrow across
23
+ # consecutive prompts. prompt_toolkit is imported lazily: a non-interactive
24
+ # invocation must not pay its import cost.
25
+ _session: Any = None
26
+ _installed = False
27
+
28
+
29
+ def _prompt_session() -> Any:
30
+ """Return the process-wide prompt_toolkit session."""
31
+ global _session
32
+ if _session is None:
33
+ from prompt_toolkit import PromptSession
34
+ from prompt_toolkit.history import InMemoryHistory
35
+
36
+ # No completion menu is shown, so reserving screen rows for one only
37
+ # forces a cursor-position query some terminals answer slowly or not at
38
+ # all.
39
+ _session = PromptSession(
40
+ history=InMemoryHistory(),
41
+ reserve_space_for_menu=0,
42
+ )
43
+ return _session
44
+
45
+
46
+ def _is_tty(stream: Any) -> bool:
47
+ isatty = getattr(stream, "isatty", None)
48
+ return bool(isatty is not None and isatty())
49
+
50
+
51
+ def _can_prompt_inline(console: Any) -> bool:
52
+ """Return whether prompt_toolkit can own the terminal for this prompt.
53
+
54
+ Its renderer reads stdin and writes stdout, so the console must be printing
55
+ to the same stdout: a console aimed elsewhere, redirected output, or a
56
+ piped stdin falls back to rich's own prompt handling.
57
+ """
58
+ stdin = sys.stdin
59
+ stdout = sys.stdout
60
+ if stdin is None or stdout is None:
61
+ return False
62
+ if getattr(console, "file", None) is not stdout:
63
+ return False
64
+ return _is_tty(stdin) and _is_tty(stdout)
65
+
66
+
67
+ def _render_prompt(
68
+ console: Any,
69
+ prompt: Any,
70
+ *,
71
+ markup: bool,
72
+ emoji: bool,
73
+ ) -> str:
74
+ """Render rich's prompt (markup, styles, emoji) to a single ANSI string.
75
+
76
+ ``soft_wrap`` leaves line breaking to prompt_toolkit, which knows the
77
+ terminal width and accounts for the ANSI sequences.
78
+ """
79
+ with console.capture() as capture:
80
+ console.print(prompt, markup=markup, emoji=emoji, end="", soft_wrap=True)
81
+ return capture.get()
82
+
83
+
84
+ def _ask_inline(
85
+ console: Any,
86
+ prompt: Any,
87
+ *,
88
+ markup: bool,
89
+ emoji: bool,
90
+ ) -> str:
91
+ from prompt_toolkit.formatted_text import ANSI
92
+
93
+ rendered = _render_prompt(console, prompt, markup=markup, emoji=emoji)
94
+ return _prompt_session().prompt(ANSI(rendered))
95
+
96
+
97
+ def install_prompt_input() -> None:
98
+ """Patch rich's ``Console.input`` once for correct interactive editing."""
99
+ global _installed
100
+ if _installed:
101
+ return
102
+
103
+ from rich.console import Console
104
+
105
+ original_input = Console.input
106
+
107
+ def prompt_input(
108
+ self: Console,
109
+ prompt: Any = "",
110
+ *,
111
+ markup: bool = True,
112
+ emoji: bool = True,
113
+ password: bool = False,
114
+ stream: TextIO | None = None,
115
+ ) -> str:
116
+ if password or stream is not None or not _can_prompt_inline(self):
117
+ return original_input(
118
+ self,
119
+ prompt,
120
+ markup=markup,
121
+ emoji=emoji,
122
+ password=password,
123
+ stream=stream,
124
+ )
125
+ try:
126
+ return _ask_inline(self, prompt, markup=markup, emoji=emoji)
127
+ except ImportError: # pragma: no cover - prompt_toolkit always installed
128
+ # A bundle that did not collect prompt_toolkit still gets a usable
129
+ # prompt, just without line editing.
130
+ return original_input(
131
+ self,
132
+ prompt,
133
+ markup=markup,
134
+ emoji=emoji,
135
+ password=password,
136
+ stream=stream,
137
+ )
138
+
139
+ _installed = True
140
+ setattr(Console, "input", prompt_input) # noqa: B010
141
+
142
+
143
+ __all__ = ["install_prompt_input"]
@@ -6,7 +6,7 @@ from types import TracebackType
6
6
  from typing import TYPE_CHECKING
7
7
 
8
8
  if TYPE_CHECKING:
9
- from typing_extensions import Self
9
+ from typing import Self
10
10
 
11
11
  from rich.console import Console
12
12
  from rich.progress import (
@@ -32,14 +32,9 @@ def _get_path():
32
32
 
33
33
  # Lazy tomllib import - only loaded when actually needed
34
34
  def _get_tomllib():
35
- if sys.version_info >= (3, 11):
36
- import tomllib
35
+ import tomllib
37
36
 
38
- return tomllib
39
- else:
40
- import tomli as tomllib
41
-
42
- return tomllib
37
+ return tomllib
43
38
 
44
39
 
45
40
  # Depth cap for rglob - prevents scanning massive trees like ~/ghq.
@@ -509,6 +504,9 @@ class ConfigManager:
509
504
  def _find_usecli_config(cls, start_dir: Path) -> Path | None:
510
505
  current = start_dir.resolve()
511
506
  command_name = cls._get_command_name()
507
+ command_is_framework = (
508
+ command_name == _get_package_name() if command_name else True
509
+ )
512
510
 
513
511
  # Check cache first to avoid repeated expensive searches.
514
512
  cache_key = str(start_dir.resolve())
@@ -528,6 +526,24 @@ class ConfigManager:
528
526
  break
529
527
  current = parent
530
528
 
529
+ # The framework binary is generic scaffolding: running `usecli` inside a
530
+ # downstream project must target that project, never the framework's own
531
+ # installed package. Search the enclosing project before any
532
+ # distribution fallback, and do not filter by `command_name` — the
533
+ # project config names the project's CLI (e.g. "cogrep"), not the
534
+ # framework binary writing into it.
535
+ if command_is_framework and not cls._is_within_usecli_package(start_dir):
536
+ project_root = find_project_root(start_dir)
537
+ if project_root is not None:
538
+ local_match = cls._find_usecli_config_in_tree(
539
+ project_root,
540
+ start_dir,
541
+ skip_venv=True,
542
+ match_command=False,
543
+ )
544
+ _config_search_cache[cache_key] = local_match
545
+ return local_match
546
+
531
547
  # Try fast lookups before expensive rglob (perf: global tools).
532
548
  console_match = cls._find_usecli_config_for_console_script()
533
549
  if console_match:
@@ -553,9 +569,8 @@ class ConfigManager:
553
569
  _config_search_cache[cache_key] = None
554
570
  return None
555
571
 
556
- is_framework = command_name == "usecli" if command_name else True
557
572
  recursive_match = cls._find_usecli_config_in_tree(
558
- search_root, start_dir, skip_venv=is_framework
573
+ search_root, start_dir, skip_venv=command_is_framework
559
574
  )
560
575
  _config_search_cache[cache_key] = recursive_match
561
576
  if recursive_match:
@@ -566,13 +581,17 @@ class ConfigManager:
566
581
 
567
582
  @staticmethod
568
583
  def _find_usecli_config_in_tree(
569
- root_dir: Path, start_dir: Path, *, skip_venv: bool
584
+ root_dir: Path,
585
+ start_dir: Path,
586
+ *,
587
+ skip_venv: bool,
588
+ match_command: bool = True,
570
589
  ) -> Path | None:
571
590
  if not root_dir.exists() or not root_dir.is_dir():
572
591
  return None
573
592
 
574
593
  candidates = _rglob_limited(root_dir, USECLI_CONFIG_TOML, skip_venv=skip_venv)
575
- command_name = ConfigManager._get_command_name()
594
+ command_name = ConfigManager._get_command_name() if match_command else None
576
595
  if command_name:
577
596
  candidates = [
578
597
  path
@@ -62,11 +62,7 @@ def _get_path():
62
62
 
63
63
 
64
64
  def _get_tomllib():
65
- if sys.version_info >= (3, 11):
66
- import tomllib
67
-
68
- return tomllib
69
- import tomli as tomllib
65
+ import tomllib
70
66
 
71
67
  return tomllib
72
68
 
@@ -12,9 +12,14 @@ from rich.text import Text
12
12
 
13
13
  from usecli.cli.config.colors import COLOR
14
14
  from usecli.cli.core.runtime import NonInteractiveError, is_json_mode
15
+ from usecli.cli.utils.interactive.prompt_input import install_prompt_input
15
16
 
16
17
  console = Console()
17
18
 
19
+ # Any rich prompt method (Prompt, Confirm, IntPrompt, console.input) gets
20
+ # interactive line editing as soon as the framework's UI module is imported.
21
+ install_prompt_input()
22
+
18
23
 
19
24
  class Prompt:
20
25
  """Wrapper around Rich Prompt for user input."""
@@ -0,0 +1,44 @@
1
+ # Runtime configuration for usecli.
2
+ # Paths are relative to this file.
3
+
4
+ [usecli]
5
+ command_name = "usecli"
6
+ title = "usecli"
7
+ description = "A powerful Python CLI framework for building beautiful, developer-friendly command-line tools."
8
+
9
+ [usecli.paths]
10
+ commands = "cli/commands/custom"
11
+ templates = "cli/templates"
12
+ # One directory or a list of directories; the first is where `make:theme`
13
+ # writes new themes.
14
+ themes = ["cli/themes"]
15
+
16
+ [usecli.theme]
17
+ # Theme TOML file to load, by name or path.
18
+ name = "default"
19
+
20
+ [usecli.banner]
21
+ # Optional: a text file whose contents replace the rendered title.
22
+ # Relative paths resolve against the project root.
23
+ file = "cli/core/ui/title.txt"
24
+ # Optional: a figlet font for the title (requires the `figlet` extra).
25
+ # font = "ansi_shadow"
26
+ top_space = true
27
+ bottom_space = true
28
+ # Whether the version and description follow the title.
29
+ show_version = false
30
+ show_description = false
31
+
32
+ [usecli.commands]
33
+ # Built-in commands to leave unregistered, for example ["inspire"].
34
+ hidden = []
35
+
36
+ [usecli.upgrade]
37
+ enabled = true
38
+ # Where upgrades come from: "auto" (detect from install metadata), "pypi", or "git".
39
+ source = "auto"
40
+ # Git only: repository URL. Falls back to the URL in the install metadata.
41
+ # url = "https://github.com/owner/repo.git"
42
+ # Optional: distribution name and Git ref (branch, tag, or commit) overrides.
43
+ # package = "my-cli"
44
+ # ref = "main"
@@ -1,21 +0,0 @@
1
- # Runtime configuration for usecli.
2
- # Paths are relative to this file.
3
-
4
- [usecli]
5
- command_name = "usecli"
6
- title = "usecli"
7
- description = "A powerful Python CLI framework for building beautiful, developer-friendly command-line tools."
8
-
9
- [usecli.paths]
10
- commands = "cli/commands/custom"
11
- templates = "cli/templates"
12
- themes = ["cli/themes"]
13
-
14
- [usecli.theme]
15
- name = "default"
16
-
17
- [usecli.banner]
18
- file = "cli/core/ui/title.txt"
19
- font = "ansi_shadow"
20
- top_space = true
21
- bottom_space = false
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes