Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom location #147

Merged
merged 7 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""}

Expand All @@ -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
Expand Down
23 changes: 12 additions & 11 deletions scripts/test-commandline-args.sh
Original file line number Diff line number Diff line change
@@ -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
./../bin/catnap -c ../config/config.toml -a ../config/distros.toml -n

1 change: 1 addition & 0 deletions scripts/test_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/catnaplib/platform/fetch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 8 additions & 4 deletions src/catnaplib/platform/probe.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down