refactor!: switch from ini to usu

This commit is contained in:
Daylin Morgan 2024-03-19 11:57:34 -05:00
parent bada89d821
commit f9ea275eb0
Signed by: daylin
GPG key ID: 950D13E9719334AD
5 changed files with 61 additions and 39 deletions

View file

@ -26,6 +26,7 @@ task bundle, "package build assets":
exec cmd exec cmd
# begin Nimble config (version 2) # begin Nimble config (version 2)
--noNimblePath --noNimblePath
when withDir(thisDir(), system.fileExists("nimble.paths")): when withDir(thisDir(), system.fileExists("nimble.paths")):

View file

@ -1,16 +1,6 @@
{ {
"version": 2, "version": 2,
"packages": { "packages": {
"bbansi": {
"version": "0.1.0",
"vcsRevision": "a7eb31407d50bb773bebc8b590ae25fa5af1bbec",
"url": "https://github.com/daylinmorgan/bbansi",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "1a4ea3d954edf4d76202237e4848ed56e468a0f2"
}
},
"cligen": { "cligen": {
"version": "1.7.0", "version": "1.7.0",
"vcsRevision": "4193f802796f15559c81c6dd56724d6f20345917", "vcsRevision": "4193f802796f15559c81c6dd56724d6f20345917",
@ -23,12 +13,32 @@
}, },
"illwill": { "illwill": {
"version": "0.3.3", "version": "0.3.3",
"vcsRevision": "6ba6045038a01d1855208c4a9be7d4826d774001", "vcsRevision": "449ae5d2f05aba125d5a71823ff1da55b1766d70",
"url": "https://github.com/inv2004/illwill/", "url": "https://github.com/inv2004/illwill/",
"downloadMethod": "git", "downloadMethod": "git",
"dependencies": [], "dependencies": [],
"checksums": { "checksums": {
"sha1": "c1971885588771d9c413d5b6ade93237e8f1635a" "sha1": "7109f26fc632ceed85e0c48afe55051948c1bc61"
}
},
"bbansi": {
"version": "0.1.0",
"vcsRevision": "e77ad85cd3a68cabd6ef66727fa1a0cd14c4d0d3",
"url": "https://github.com/daylinmorgan/bbansi",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "f47cade0fa02ef944d76e31199762b26389bb9a9"
}
},
"usu": {
"version": "0.1.0",
"vcsRevision": "25574d165bb7f60900b36590bc49f3d90e47cea4",
"url": "https://github.com/usu-dev/usu-nim",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "61a8c13946e3eea9dbe04a6141ed93811563026c"
} }
} }
}, },

View file

@ -2,16 +2,28 @@
"depends": [ "depends": [
{ {
"method": "fetchzip", "method": "fetchzip",
"path": "/nix/store/x91md8lmrxxdd4xizg0r9gcbl8sqn8vk-source", "path": "/nix/store/86prp3nzb853d7isbhgrixw6b8l55gdn-source",
"rev": "6ba6045038a01d1855208c4a9be7d4826d774001", "rev": "449ae5d2f05aba125d5a71823ff1da55b1766d70",
"sha256": "13hrcvpynlyr8hqx1h6qkfd32ihg255yd8wmk6l4q6bmiw8frw09", "sha256": "1vmp1wamfzwcb1rnwvrwsz53sd3k3bqgcpg9c9x29p6q27d1ffdz",
"srcDir": "", "srcDir": "",
"url": "https://github.com/inv2004/illwill/archive/6ba6045038a01d1855208c4a9be7d4826d774001.tar.gz", "url": "https://github.com/inv2004/illwill/archive/449ae5d2f05aba125d5a71823ff1da55b1766d70.tar.gz",
"subDir": "", "subDir": "",
"packages": [ "packages": [
"illwill" "illwill"
] ]
}, },
{
"method": "fetchzip",
"path": "/nix/store/pgajs406yg0ffw099np6fca3psf8zlvr-source",
"rev": "25574d165bb7f60900b36590bc49f3d90e47cea4",
"sha256": "0qf162bagcgnxjsjpg560cz6kdshhsyrkzq3j471a8pxrhwp608i",
"srcDir": "src",
"url": "https://github.com/usu-dev/usu-nim/archive/25574d165bb7f60900b36590bc49f3d90e47cea4.tar.gz",
"subDir": "",
"packages": [
"usu"
]
},
{ {
"method": "fetchzip", "method": "fetchzip",
"path": "/nix/store/4h59kkd5db97j5m92szryjydxyr9bnwg-source", "path": "/nix/store/4h59kkd5db97j5m92szryjydxyr9bnwg-source",
@ -26,11 +38,11 @@
}, },
{ {
"method": "fetchzip", "method": "fetchzip",
"path": "/nix/store/8ilhirvpc8qi3jbbh1fi3a8psr780cz4-source", "path": "/nix/store/m086yq0f29cg98w3b12d70cw7xki1j39-source",
"rev": "a7eb31407d50bb773bebc8b590ae25fa5af1bbec", "rev": "e77ad85cd3a68cabd6ef66727fa1a0cd14c4d0d3",
"sha256": "06s4198pbqjga7nqrvajyxqxx3df83fk3qn21pv7axshl19kh9bq", "sha256": "1l5a5kwviq76kxzagljzpwzc3p43qz7wzs5zvrqi5c59klw1967c",
"srcDir": "src", "srcDir": "src",
"url": "https://github.com/daylinmorgan/bbansi/archive/a7eb31407d50bb773bebc8b590ae25fa5af1bbec.tar.gz", "url": "https://github.com/daylinmorgan/bbansi/archive/e77ad85cd3a68cabd6ef66727fa1a0cd14c4d0d3.tar.gz",
"subDir": "", "subDir": "",
"packages": [ "packages": [
"bbansi" "bbansi"

View file

@ -1,4 +1,5 @@
import std/[os, parsecfg, sequtils, tables, strutils] import std/[os, sequtils, tables, strutils]
import usu
import term import term
@ -10,18 +11,19 @@ type
Session = object Session = object
name*, dir*: string name*, dir*: string
# TODO: update when the API for usu is complete
proc loadConfigFile(): TsmConfig = proc loadConfigFile(): TsmConfig =
let configPath = getHomeDir() / ".config/tsm/config.ini" let configPath = getConfigDir() / "tsm" / "config.usu"
if configPath.fileExists(): if fileExists configPath:
let iniTable = loadConfig(configPath) let usuNode = parseUsu(readFile configPath)
if "sessions" in iniTable: let topFields = usuNode.fields
for key, value in iniTable["sessions"].pairs: if "dirs" in topFields:
result.sessions.add Session(name: key, dir: value) for dir in usuNode.fields["dirs"].elems:
if "dirs" in iniTable: result.dirs.add dir.value
for key, value in iniTable["dirs"].pairs: if "sessions" in topFields:
if value != "": for session in usuNode.fields["sessions"].elems:
termError "[dirs] table should only contain a list of paths" result.sessions.add Session(name: session.fields["name"].value,
result.dirs.add key dir: session.fields["dir"].value)
proc loadTsmConfig*(): TsmConfig = proc loadTsmConfig*(): TsmConfig =
result = loadConfigFile() result = loadConfigFile()
@ -30,10 +32,5 @@ proc loadTsmConfig*(): TsmConfig =
result.dirs = tsmDirs.split(":") result.dirs = tsmDirs.split(":")
when isMainModule: when isMainModule:
let dict = loadConfig(getHomeDir() / ".config/tsm/config.ini") echo loadConfigFile()
let sections = dict.sections().toSeq()
if "sessions" in sections:
for key, value in dict["sessions"].pairs:
echo key, value
echo loadTsmConfig()

View file

@ -11,8 +11,10 @@ binDir = "bin"
# Dependencies # Dependencies
requires "nim >= 2.0.0" requires "nim >= 2.0.0"
requires "https://github.com/inv2004/illwill/#6ba6045038a01d1855208c4a9be7d4826d774001" # illwill PR 47
requires "https://github.com/inv2004/illwill/#449ae5d2f05aba125d5a71823ff1da55b1766d70"
# requires "illwill == 0.3.2", # requires "illwill == 0.3.2",
requires "cligen" requires "cligen"
requires "https://github.com/daylinmorgan/bbansi >= 0.1.0" requires "https://github.com/daylinmorgan/bbansi >= 0.1.0"
requires "https://github.com/usu-dev/usu-nim"