# tickwatch # Author: Euxane TRAN-GIRARD # Licence: EUPL-1.2 import std/paths import std/strutils type FileValueMonitor = ref object path: Path FileChangeMonitor = ref object path: Path lastValue: int proc readValue(path: Path): int = readFile(path.string).strip.parseInt proc initFileValueMonitor*(path: Path): FileValueMonitor = FileValueMonitor(path: path) proc readValue*(mon: FileValueMonitor): int = mon.path.readValue() proc initFileChangeMonitor*(path: Path): FileChangeMonitor = FileChangeMonitor( path: path, lastValue: path.readValue(), ) proc readValue*(mon: FileChangeMonitor): int = let newValue = mon.path.readValue() result = abs(mon.lastValue - newValue) mon.lastValue = newValue