From 0c22852e3958797ce482f96ad19f7b5df34a32a2 Mon Sep 17 00:00:00 2001 From: Rui Jiang Date: Fri, 8 Nov 2024 17:45:05 -0600 Subject: [PATCH 1/5] added support for weather location --- config/config.toml | 1 + scripts/test_config.toml | 1 + src/catnaplib/platform/fetch.nim | 2 +- src/catnaplib/platform/probe.nim | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/config.toml b/config/config.toml index 897b2f8..6bb0c79 100644 --- a/config/config.toml +++ b/config/config.toml @@ -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_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..fe4a289 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.misc["location"].getStr()) 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..7330c70 100644 --- a/src/catnaplib/platform/probe.nim +++ b/src/catnaplib/platform/probe.nim @@ -351,7 +351,7 @@ proc getGpu*(): string = writeCache(cacheFile, result, initDuration(days=1)) -proc getWeather*(): string = +proc getWeather*(location: string): string = # Returns current weather let cacheFile = "weather".toCachePath @@ -360,7 +360,7 @@ proc getWeather*(): string = 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() From 0130ad7a86078a51a4451f1a8cadcdde39f3830d Mon Sep 17 00:00:00 2001 From: Rui Jiang Date: Fri, 8 Nov 2024 17:47:15 -0600 Subject: [PATCH 2/5] updated sample config --- config/config.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.toml b/config/config.toml index 6bb0c79..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 = ""} From f3bef74a406184a48102f3e543e05811b695a55d Mon Sep 17 00:00:00 2001 From: Rui Jiang Date: Sun, 10 Nov 2024 10:06:51 -0600 Subject: [PATCH 3/5] fixed mac install script (#1) --- config.nims | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config.nims b/config.nims index 50ec081..73a7145 100644 --- a/config.nims +++ b/config.nims @@ -49,12 +49,18 @@ proc configure() = else: cpFile(thisDir() & "/config/distros.toml", configpath & "distros.toml") +task clean, "Cleans existing build": + echo "\e[36;1mCleaning\e[0;0m existing build" + rmFile("{thisDir()}/bin/catnap") + task release, "Builds the project in release mode": + cleanTask() echo "\e[36;1mBuilding\e[0;0m in release mode" exec &"./scripts/git-commit-id.sh" compile(true) task debug, "Builds the project in debug mode": + cleanTask() echo "\e[36;1mBuilding\e[0;0m in debug mode" exec &"./scripts/git-commit-id.sh" compile(false) From 24a71c0b61362fa2323425ac4062eb670295b108 Mon Sep 17 00:00:00 2001 From: Rui Jiang Date: Sun, 10 Nov 2024 11:20:45 -0600 Subject: [PATCH 4/5] handles missing location info --- src/catnaplib/platform/fetch.nim | 2 +- src/catnaplib/platform/probe.nim | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/catnaplib/platform/fetch.nim b/src/catnaplib/platform/fetch.nim index fe4a289..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(config.misc["location"].getStr()) + 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 7330c70..d5183fc 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,9 +352,12 @@ proc getGpu*(): string = writeCache(cacheFile, result, initDuration(days=1)) -proc getWeather*(location: string): 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() result = readCache(cacheFile) if result != "": From eadcb21f9871779cb1d3ef150eae5b0a7e73d2e4 Mon Sep 17 00:00:00 2001 From: Rui Jiang Date: Sun, 10 Nov 2024 19:34:18 -0600 Subject: [PATCH 5/5] fixed space in city names --- scripts/test-commandline-args.sh | 23 ++++++++++++----------- src/catnaplib/platform/probe.nim | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) 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/src/catnaplib/platform/probe.nim b/src/catnaplib/platform/probe.nim index d5183fc..07c1e85 100644 --- a/src/catnaplib/platform/probe.nim +++ b/src/catnaplib/platform/probe.nim @@ -357,7 +357,7 @@ proc getWeather*(config: Config): string = let cacheFile = "weather".toCachePath var location = ""; if config.misc.contains("location"): - location = config.misc["location"].getStr() + location = config.misc["location"].getStr().replace(" ", "+") result = readCache(cacheFile) if result != "":