fix: resolve terminal display wobble and effect dimension stability
- Fix TerminalDisplay: add screen clear each frame (cursor home + erase down) - Fix CameraStage: use set_canvas_size instead of read-only viewport properties - Fix Glitch effect: preserve visible line lengths, remove cursor positioning - Fix Fade effect: return original line when fade=0 instead of empty string - Fix Noise effect: use input line length instead of terminal_width - Remove HUD effect from all presets (redundant with border FPS display) - Add regression tests for effect dimension stability - Add docs/ARCHITECTURE.md with Mermaid diagrams - Add mise tasks: diagram-ascii, diagram-validate, diagram-check - Move markdown docs to docs/ (ARCHITECTURE, Refactor, hardware specs) - Remove redundant requirements files (use pyproject.toml) - Add *.dot and *.png to .gitignore Closes #25
This commit is contained in:
@@ -21,17 +21,33 @@ class GlitchEffect(EffectPlugin):
|
||||
n_hits = int(n_hits * intensity)
|
||||
|
||||
if random.random() < glitch_prob:
|
||||
# Store original visible lengths before any modifications
|
||||
# Strip ANSI codes to get visible length
|
||||
import re
|
||||
|
||||
ansi_pattern = re.compile(r"\x1b\[[0-9;]*[a-zA-Z]")
|
||||
original_lengths = [len(ansi_pattern.sub("", line)) for line in result]
|
||||
for _ in range(min(n_hits, len(result))):
|
||||
gi = random.randint(0, len(result) - 1)
|
||||
scr_row = gi + 1
|
||||
result[gi] = f"\033[{scr_row};1H{self._glitch_bar(ctx.terminal_width)}"
|
||||
original_line = result[gi]
|
||||
target_len = original_lengths[gi] # Use stored original length
|
||||
glitch_bar = self._glitch_bar(target_len)
|
||||
result[gi] = glitch_bar
|
||||
return result
|
||||
|
||||
def _glitch_bar(self, w: int) -> str:
|
||||
def _glitch_bar(self, target_len: int) -> str:
|
||||
c = random.choice(["░", "▒", "─", "\xc2"])
|
||||
n = random.randint(3, w // 2)
|
||||
o = random.randint(0, w - n)
|
||||
return " " * o + f"{G_LO}{DIM}" + c * n + RST
|
||||
n = random.randint(3, max(3, target_len // 2))
|
||||
o = random.randint(0, max(0, target_len - n))
|
||||
|
||||
glitch_chars = c * n
|
||||
trailing_spaces = target_len - o - n
|
||||
trailing_spaces = max(0, trailing_spaces)
|
||||
|
||||
glitch_part = f"{G_LO}{DIM}" + glitch_chars + RST
|
||||
result = " " * o + glitch_part + " " * trailing_spaces
|
||||
|
||||
return result
|
||||
|
||||
def configure(self, config: EffectConfig) -> None:
|
||||
self.config = config
|
||||
|
||||
Reference in New Issue
Block a user