diff --git a/config/config.toml b/config/config.toml index 897b2f8..239f984 100644 --- a/config/config.toml +++ b/config/config.toml @@ -18,12 +18,12 @@ terminal = {icon = " ", name = "term", color = "(RD)"} shell = {icon = " ", name = "shell", color = "(MA)"} # packages = {icon = " ", name = "packages", color = "(RD)"} # WARNING: Resource Intensive # weather = {icon = " ", name = "weather", color = "(BE)"} # Requires curl and an emoji font. | WARNING: Resource Intensive -# The following stats do not work on MacOS and the BSDs. # gpu = {icon = "󱔐 ", name = "gpu", color = "(MA)"} # WARNING: Resource Intensive # cpu = {icon = " ", name = "cpu", color = "(RD)"} +# battery = {icon = " ", name = "battery", color = "(GN)"} +# The following stats do not work on MacOS and the BSDs. # disk_0 = {icon = " ", name = "disk", color = "(GN)"} # memory = {icon = " ", name = "memory", color = "(YW)"} -# battery = {icon = " ", name = "battery", color = "(GN)"} sep_color = "SEPARATOR" colors = {icon = " ", name = "colors", color = "!DT!", symbol = ""} @@ -34,6 +34,7 @@ colors = {icon = " ", name = "colors", color = "!DT!", symbol = ""} borderstyle = "line" layout = "Inline" # [Inline, ArtOnTop, StatsOnTop] stats_margin_top = 0 +location = "" # Used for fetching weather; leave empty to use the location of your IP; check https://wttr.in/:help for supported location types [misc.figletLogos] # Requires Figlet. enable = false diff --git a/scripts/test-commandline-args.sh b/scripts/test-commandline-args.sh index 2a6cbc5..d67aad5 100755 --- a/scripts/test-commandline-args.sh +++ b/scripts/test-commandline-args.sh @@ -1,43 +1,44 @@ # Test Normal run echo "[!] Testing: Normal Run" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -n # Test help echo "[!] Testing: Help" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -h +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -h -n # Test version echo "[!] Testing: Version" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -v +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -v -n # Test distroid echo "[!] Testing: DistroId" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -d arch +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -d arch -n # Test grep echo "[!] Testing: Grep" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -g kernel +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -g kernel -n # Test margin echo "[!] Testing: Margin" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -m 1,2,3 +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -m 1,2,3 -n # Test layout echo "[!] Testing: Layout" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -l ArtOnTop +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -l ArtOnTop -n # Test figletlogos mode echo "[!] Testing: FigletLogos" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -fe on +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -fe on -n # Test figletlogos margin echo "[!] Testing: FigletLogos Margin" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -fe on -fm 1,2,3 +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -fe on -fm 1,2,3 -n # Test figletlogos font with example figlet font file echo "[!] Testing: FigletLogos Font" -./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -fe on -ff basic.flf +./../bin/catnap -c ./test_config.toml -a ../config/distros.toml -fe on -ff basic.flf -n # Test default Config echo "[!] Testing: Default config" -./../bin/catnap -c ../config/config.toml -a ../config/distros.toml \ No newline at end of file +./../bin/catnap -c ../config/config.toml -a ../config/distros.toml -n + diff --git a/scripts/test_config.toml b/scripts/test_config.toml index 03eab5d..08d189c 100644 --- a/scripts/test_config.toml +++ b/scripts/test_config.toml @@ -26,6 +26,7 @@ colors = {icon = "> ", name = "colors", color = "!DT!", symbol = "#"} borderstyle = "doubleline" layout = "Inline" stats_margin_top = 0 +location = "San Francisco" [misc.figletLogos] enable = false diff --git a/src/catnaplib/platform/fetch.nim b/src/catnaplib/platform/fetch.nim index f57b9fb..f29be36 100644 --- a/src/catnaplib/platform/fetch.nim +++ b/src/catnaplib/platform/fetch.nim @@ -23,7 +23,7 @@ proc fetchSystemInfo*(config: Config, distroId: string = "nil"): FetchInfo = result.list["cpu"] = proc(): string = return probe.getCpu() result.list["gpu"] = proc(): string = return probe.getGpu() result.list["packages"] = proc(): string = return probe.getPackages() - result.list["weather"] = proc(): string = return probe.getWeather() + result.list["weather"] = proc(): string = return probe.getWeather(config) if defined(linux): # Add a disk stat for all mounts let mounts: seq[string] = probe.getMounts() diff --git a/src/catnaplib/platform/probe.nim b/src/catnaplib/platform/probe.nim index 1576bb5..07c1e85 100644 --- a/src/catnaplib/platform/probe.nim +++ b/src/catnaplib/platform/probe.nim @@ -2,15 +2,16 @@ import os import strformat import math import strutils -import parsecfg +from parsecfg import loadConfig, getSectionValue import posix_utils import times import tables import osproc import re from unicode import toLower -from "../global/definitions" import DistroId, PKGMANAGERS, PKGCOUNTCOMMANDS, toCachePath, toTmpPath +from "../global/definitions" import DistroId, PKGMANAGERS, PKGCOUNTCOMMANDS, toCachePath, toTmpPath, Config import "../terminal/logging" +import parsetoml import "caching" import algorithm @@ -351,16 +352,19 @@ proc getGpu*(): string = writeCache(cacheFile, result, initDuration(days=1)) -proc getWeather*(): string = +proc getWeather*(config: Config): string = # Returns current weather let cacheFile = "weather".toCachePath + var location = ""; + if config.misc.contains("location"): + location = config.misc["location"].getStr().replace(" ", "+") result = readCache(cacheFile) if result != "": return let tmpFile = "weather.txt".toTmpPath - if execCmd("curl -s wttr.in/?format=3 > " & tmpFile) != 0: + if execCmd("curl -s wttr.in/" & location & "?format=3 > " & tmpFile) != 0: logError("Failed to fetch weather!") result = readFile(tmpFile).strip()