Name the loop's states with one transition function, and inject its side effects
This commit is contained in:
@@ -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,
|
||||
)
|
||||
Reference in New Issue
Block a user