forked from genewildish/Mainline
- Add EffectPlugin ABC with @abstractmethod decorators for interface enforcement - Add runtime interface checking in discover_plugins() with issubclass() - Add EffectContext factory with sensible defaults - Standardize Display __init__ (remove redundant init in TerminalDisplay) - Document effect behavior when ticker_height=0 - Evaluate legacy effects: document coexistence, no deprecation needed - Research plugin patterns (VST, Python entry points) - Fix pysixel dependency (removed broken dependency) Test coverage improvements: - Add DisplayRegistry tests - Add MultiDisplay tests - Add SixelDisplay tests - Add controller._get_display tests - Add effects controller command handling tests - Add benchmark regression tests (@pytest.mark.benchmark) - Add pytest marker for benchmark tests in pyproject.toml Documentation updates: - Update AGENTS.md with 56% coverage stats and effect plugin docs - Update README.md with Sixel display mode and benchmark commands - Add new modules to architecture section
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import random
|
|
|
|
from engine import config
|
|
from engine.effects.types import EffectConfig, EffectContext, EffectPlugin
|
|
from engine.terminal import C_DIM, DIM, G_DIM, G_LO, RST
|
|
|
|
|
|
class GlitchEffect(EffectPlugin):
|
|
name = "glitch"
|
|
config = EffectConfig(enabled=True, intensity=1.0)
|
|
|
|
def process(self, buf: list[str], ctx: EffectContext) -> list[str]:
|
|
if not buf:
|
|
return buf
|
|
result = list(buf)
|
|
intensity = self.config.intensity
|
|
|
|
glitch_prob = 0.32 + min(0.9, ctx.mic_excess * 0.16)
|
|
glitch_prob = glitch_prob * intensity
|
|
n_hits = 4 + int(ctx.mic_excess / 2)
|
|
n_hits = int(n_hits * intensity)
|
|
|
|
if random.random() < glitch_prob:
|
|
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)}"
|
|
return result
|
|
|
|
def _glitch_bar(self, w: 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
|
|
|
|
def configure(self, config: EffectConfig) -> None:
|
|
self.config = config
|