diff --git a/src/.prototype/run.sh b/src/.prototype/run.sh index d1ab6b6..2a7b040 100644 --- a/src/.prototype/run.sh +++ b/src/.prototype/run.sh @@ -7,8 +7,6 @@ main() { } trap cleanup EXIT - local pipe=/tmp/breel.pipe - test -e "$pipe" || mkfifo $pipe while true; do read -s v echo "$v" diff --git a/src/input.py b/src/input.py new file mode 100644 index 0000000..410c247 --- /dev/null +++ b/src/input.py @@ -0,0 +1,17 @@ +class Input: + def __init__(self, reader): + self.reader = reader + + def get(self): + return self.reader.read() + +class StdinReader: + def read(self): + return input() + +class FileReader: + def __init__(self, path): + self.f = open(path, "r") + + def read(self): + return self.f.readline() diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..0d49abf --- /dev/null +++ b/src/main.py @@ -0,0 +1,5 @@ +def main(): + raise Exception("not impl") + +if __name__ == "__main__": + main() diff --git a/src/output.py b/src/output.py new file mode 100644 index 0000000..ad9a74f --- /dev/null +++ b/src/output.py @@ -0,0 +1,30 @@ +import time + +class Output: + def __init__(self): + self.previous = None + + def write(self, latest): + chosen = Line.choose(self.previous, latest) + if chosen.v != self.previous.v: + print(chosen) + self.previous = chosen + +class Line: + def __init__(self, v): + self.t = time.time() + self.v = v + + def __str__(self): + return f'@{self.t} | {self.v}' + + def choose(a, b): + if not a: + return b + if not b: + return a + latest = max([a,b], key=lambda x:x.t) + oldest = min([a,b], key=lambda x:x.t) + if not latest.v and time.time() - oldest.t < 1: + return oldest + return latest