code-puppy 1.0.2__tar.gz → 1.0.3__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 (40) hide show
  1. {code_puppy-1.0.2 → code_puppy-1.0.3}/PKG-INFO +1 -1
  2. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/splash/__init__.py +65 -3
  3. {code_puppy-1.0.2 → code_puppy-1.0.3}/pyproject.toml +1 -1
  4. {code_puppy-1.0.2 → code_puppy-1.0.3}/.gitignore +0 -0
  5. {code_puppy-1.0.2 → code_puppy-1.0.3}/LICENSE +0 -0
  6. {code_puppy-1.0.2 → code_puppy-1.0.3}/README.md +0 -0
  7. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/__init__.py +0 -0
  8. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/__main__.py +0 -0
  9. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/_art.py +0 -0
  10. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/api_keys.py +0 -0
  11. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/branding.py +0 -0
  12. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/builtin_plugins.py +0 -0
  13. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/callbacks.py +0 -0
  14. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/colors.py +0 -0
  15. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/compat/__init__.py +0 -0
  16. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/compat/bridge.py +0 -0
  17. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/compat/tools.py +0 -0
  18. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/config.py +0 -0
  19. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/distribution.py +0 -0
  20. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/first_run.py +0 -0
  21. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/former_name.py +0 -0
  22. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/i18n/__init__.py +0 -0
  23. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/identity.py +0 -0
  24. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/legacy_sessions.py +0 -0
  25. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/legacy_store.py +0 -0
  26. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/main.py +0 -0
  27. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/messaging/__init__.py +0 -0
  28. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/messaging/bus.py +0 -0
  29. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/migrate/__init__.py +0 -0
  30. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/migrate/runner.py +0 -0
  31. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/migrate/sources.py +0 -0
  32. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/migrate/translate.py +0 -0
  33. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/personality.py +0 -0
  34. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/plugins/__init__.py +0 -0
  35. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/plugins/source_only.py +0 -0
  36. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/plugins/trust.py +0 -0
  37. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/splash/__main__.py +0 -0
  38. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/splash/canvas.py +0 -0
  39. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/splash/scenes.py +0 -0
  40. {code_puppy-1.0.2 → code_puppy-1.0.3}/code_puppy/update.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: code-puppy
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Code generation agent
5
5
  Project-URL: repository, https://github.com/mpfaffenberger/code_puppy
6
6
  Project-URL: HomePage, https://github.com/mpfaffenberger/code_puppy
@@ -8,6 +8,7 @@ Each launch plays one of :data:`SCENES`, picked at random.
8
8
 
9
9
  from __future__ import annotations
10
10
 
11
+ import atexit
11
12
  import codecs
12
13
  import contextlib
13
14
  import io
@@ -16,6 +17,7 @@ import random
16
17
  import shutil
17
18
  import sys
18
19
  import threading
20
+ from collections.abc import Callable
19
21
 
20
22
  from code_puppy.splash.canvas import Canvas, truecolor
21
23
  from code_puppy.splash.scenes import SCENES, Scene, caption
@@ -46,6 +48,58 @@ def _speaks_unicode(stream: object) -> bool:
46
48
  return False
47
49
 
48
50
 
51
+ def _nothing() -> None:
52
+ """Nothing to undo."""
53
+
54
+
55
+ def _enable_windows_vt(fd: int) -> Callable[[], None] | None:
56
+ """Switch on escape handling for the Windows console behind ``fd``.
57
+
58
+ Windows 10 and later understand escapes once virtual terminal processing
59
+ is on; Windows Terminal turns it on by itself. Returns what switches it
60
+ off again, or None if ``fd`` is not a console or it refuses.
61
+ """
62
+ import ctypes
63
+ import msvcrt
64
+
65
+ enable_virtual_terminal_processing = 0x0004
66
+ kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
67
+ handle = msvcrt.get_osfhandle(fd)
68
+ mode = ctypes.c_ulong()
69
+ if not kernel32.GetConsoleMode(handle, ctypes.byref(mode)):
70
+ return None
71
+ original = mode.value
72
+ if original & enable_virtual_terminal_processing:
73
+ return _nothing
74
+ if not kernel32.SetConsoleMode(
75
+ handle, original | enable_virtual_terminal_processing
76
+ ):
77
+ return None
78
+
79
+ def restore() -> None:
80
+ """Switch escapes off, keeping whatever else changed the mode since."""
81
+ if kernel32.GetConsoleMode(handle, ctypes.byref(mode)):
82
+ kernel32.SetConsoleMode(
83
+ handle, mode.value & ~enable_virtual_terminal_processing
84
+ )
85
+
86
+ return restore
87
+
88
+
89
+ def _switch_on_escapes(stream: object) -> Callable[[], None] | None:
90
+ """Make ``stream``'s terminal act on escapes; return what undoes that.
91
+
92
+ POSIX terminals always do, so there is nothing to undo. None if the
93
+ terminal would print escapes instead of acting on them.
94
+ """
95
+ if sys.platform != "win32":
96
+ return _nothing
97
+ try:
98
+ return _enable_windows_vt(stream.fileno()) # type: ignore[attr-defined]
99
+ except (AttributeError, ImportError, OSError, ValueError):
100
+ return None
101
+
102
+
49
103
  class Splash:
50
104
  """Own the alternate screen and animate a scene until :meth:`stop`."""
51
105
 
@@ -67,7 +121,6 @@ class Splash:
67
121
  and os.getenv("TERM") != "dumb"
68
122
  and size.columns >= MIN_COLUMNS
69
123
  and size.lines >= MIN_LINES
70
- and sys.platform != "win32"
71
124
  and _speaks_unicode(self._stream)
72
125
  )
73
126
 
@@ -84,18 +137,27 @@ class Splash:
84
137
  def start(self) -> None:
85
138
  """Start one animation thread and hold back output until :meth:`stop`.
86
139
 
87
- Output is held back only once the thread runs: if it cannot start,
88
- startup carries on without the animation and with its streams intact.
140
+ Output is held back only once the thread runs: if the terminal cannot
141
+ act on escapes or the thread cannot start, startup carries on without
142
+ the animation, with its streams and terminal intact.
143
+
144
+ Escapes switched on stay on until exit, not just until :meth:`stop`:
145
+ whatever draws after the splash chose how to draw while they were on.
89
146
  """
90
147
  if not self._enabled or self._thread is not None:
91
148
  return
149
+ undo = _switch_on_escapes(self._stream)
150
+ if undo is None:
151
+ return
92
152
  thread = threading.Thread(
93
153
  target=self._run, name="code-puppy-splash", daemon=True
94
154
  )
95
155
  try:
96
156
  thread.start()
97
157
  except RuntimeError: # "can't start new thread": no animation, that's all
158
+ undo()
98
159
  return
160
+ atexit.register(undo)
99
161
  self._thread = thread
100
162
  sys.stdout, sys.stderr = self._buffers
101
163
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "code-puppy"
7
- version = "1.0.2"
7
+ version = "1.0.3"
8
8
  description = "Code generation agent"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11,<3.15"
File without changes
File without changes
File without changes