From e14a7db4ffe3c4e0f15f6b37a980501a8d74d26b Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 13 Aug 2026 13:04:10 +0200 Subject: Initial commit: prognosis, the Go implementation An hour-by-hour forecast for the terminal, with official IMGW warnings for Polish locations. Replaces the Python version, whose cache file format it keeps so the two can coexist until this reaches parity. Open-Meteo provides the forecast, geocoding and pollen; GUGiK turns coordinates into a TERYT powiat code; IMGW supplies the warnings, filtered to that powiat rather than the whole country. Only the two lookups that never change are cached. Forecasts never are. Silence is never allowed to read as all-clear: "no warnings in force" and "the check failed" are reported as distinct states. Place names are resolved without guessing. A name matching several places is refused with a numbered list carrying each candidate's region and coordinates, and -pick N chooses one and remembers it. A stray positional beside -l is an error, so an unquoted "Wiry, PL" cannot silently resolve to somewhere else. The cache is written one entry per line with sorted keys, and treated as disposable but not worthless: an entry that will not parse is skipped and the rest kept, and a file that will not parse at all is moved to cache.json.bad rather than overwritten. No third-party dependencies. `make ci` is the gate: gofmt clean, vet, tests. --- cmd/prognosis/term_unix.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 cmd/prognosis/term_unix.go (limited to 'cmd/prognosis/term_unix.go') diff --git a/cmd/prognosis/term_unix.go b/cmd/prognosis/term_unix.go new file mode 100644 index 0000000..7cccf25 --- /dev/null +++ b/cmd/prognosis/term_unix.go @@ -0,0 +1,28 @@ +//go:build linux || darwin || freebsd || netbsd || openbsd + +package main + +import ( + "os" + "syscall" + "unsafe" +) + +// termCols asks the terminal for its width. +// +// This is an ioctl rather than golang.org/x/term because the spec keeps this +// binary free of third-party modules; it is a dozen lines and only needs to +// work on the platforms prognosis is built for. +func termCols() (int, bool) { + var ws struct{ Row, Col, Xpixel, Ypixel uint16 } + _, _, errno := syscall.Syscall( + syscall.SYS_IOCTL, + os.Stdout.Fd(), + uintptr(syscall.TIOCGWINSZ), + uintptr(unsafe.Pointer(&ws)), + ) + if errno != 0 || ws.Col == 0 { + return 0, false + } + return int(ws.Col), true +} -- cgit v1.3