Name the loop's states with one transition function, and inject its side effects

This commit is contained in:
2026-10-01 23:12:37 +02:00
parent d0ce3b2690
commit f385b563f0
16 changed files with 469 additions and 126 deletions
+27
View File
@@ -0,0 +1,27 @@
import dataclasses
import os
import subprocess
import sys
import time
import typing
@dataclasses.dataclass(frozen=True)
class Effects:
execv: typing.Callable[[str, list[str]], None]
input: typing.Callable[[str], str]
on_terminal: typing.Callable[[], bool]
popen: typing.Callable[..., subprocess.Popen]
run: typing.Callable[..., subprocess.CompletedProcess]
sleep: typing.Callable[[float], None]
def system_effects() -> Effects:
return Effects(
execv=os.execv,
input=input,
on_terminal=lambda: sys.stdin.isatty() and sys.stdout.isatty(),
popen=subprocess.Popen,
run=subprocess.run,
sleep=time.sleep,
)