update to hwylcli and drop cligen
This commit is contained in:
parent
8a866a8082
commit
d55e8834fd
5 changed files with 54 additions and 58 deletions
|
@ -48,7 +48,7 @@
|
|||
pname = "hyprman";
|
||||
version = "${self.shortRev or "dirty"}";
|
||||
src = cleanSource ./.;
|
||||
nimbleDepsHash = "sha256-72FYXiYIgEDX2j/bBADGvwX6+kd+7py0RHTz2WeyXO8=";
|
||||
nimbleDepsHash = "sha256-hZ7aDy8mqfWxZqdCxB+z7OTc38u14fQaEwMqERSYqV0=";
|
||||
};
|
||||
});
|
||||
formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
|
||||
|
|
|
@ -11,7 +11,6 @@ bin = @["hyprman"]
|
|||
# Dependencies
|
||||
|
||||
requires "nim >= 2.0.8"
|
||||
requires "cligen"
|
||||
requires "yaml"
|
||||
requires "jsony"
|
||||
requires "https://github.com/daylinmorgan/hwylterm#HEAD"
|
||||
requires "https://github.com/daylinmorgan/hwylterm#b6202f4f"
|
||||
|
|
14
nimble.lock
14
nimble.lock
|
@ -1,24 +1,14 @@
|
|||
{
|
||||
"version": 2,
|
||||
"packages": {
|
||||
"cligen": {
|
||||
"version": "1.7.6",
|
||||
"vcsRevision": "54f1da5d63cf7e116625e2392e85ae54c2b70719",
|
||||
"url": "https://github.com/c-blake/cligen.git",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "853785ddace4ee4f3c6c21bdf7f5e9ff0358eb3f"
|
||||
}
|
||||
},
|
||||
"hwylterm": {
|
||||
"version": "0.1.0",
|
||||
"vcsRevision": "5c71355b5f319a9c174ea88132c7c67a78d00030",
|
||||
"vcsRevision": "b6202f4f51edadd041d2b5f2aed1d75abcd4ee51",
|
||||
"url": "https://github.com/daylinmorgan/hwylterm",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "30f8f61787c36b63d484f3d5e149995fad16c63c"
|
||||
"sha1": "eb38b434419ec70f080f79b7826c3c3989a2c74a"
|
||||
}
|
||||
},
|
||||
"jsony": {
|
||||
|
|
|
@ -1,42 +1,52 @@
|
|||
## hyprman, the hyprland companion
|
||||
|
||||
import std/[osproc, strformat]
|
||||
import hwylterm/cligen, cligen
|
||||
import hwylterm/hwylcli
|
||||
import ./[
|
||||
hyprland,
|
||||
lib,
|
||||
mako,
|
||||
]
|
||||
|
||||
hwylCli(clCfg)
|
||||
hwylCli:
|
||||
name "hyprman"
|
||||
subcommands:
|
||||
--- mako
|
||||
... "interact with mako"
|
||||
flags:
|
||||
count:
|
||||
T int
|
||||
? "# of notifications"
|
||||
* 10
|
||||
- c
|
||||
json:
|
||||
T bool
|
||||
? "output as json"
|
||||
- j
|
||||
reverse:
|
||||
T bool
|
||||
? "swap notification order"
|
||||
- r
|
||||
run:
|
||||
let history = getHistory(reverse, count)
|
||||
if json: echo $(%* history)
|
||||
else:
|
||||
for n in history.notifications:
|
||||
echo $bb(n)
|
||||
|
||||
proc start() =
|
||||
## launch eww
|
||||
notify("starting eww")
|
||||
for i in 0..<getMonitors().len:
|
||||
let code = execCmd fmt"eww open bar{i}"
|
||||
if code != 0:
|
||||
notify(fmt"failed to open eww bar{i}")
|
||||
--- start
|
||||
... "launch eww"
|
||||
run:
|
||||
notify("starting eww")
|
||||
for i in 0..<getMonitors().len:
|
||||
let code = execCmd fmt"eww open bar{i}"
|
||||
if code != 0:
|
||||
notify(fmt"failed to open eww bar{i}")
|
||||
|
||||
proc eww() =
|
||||
## watch hyprland events for eww class changes
|
||||
streamEwwClasses()
|
||||
--- watch
|
||||
... "handle monitor changes on hyprland"
|
||||
run: watchHyprland()
|
||||
|
||||
proc watch() =
|
||||
## handle monitor changes on hyprland
|
||||
watchHyprland()
|
||||
|
||||
when isMainModule:
|
||||
const
|
||||
config = //{"config": "path/to/config"}
|
||||
makoHelp = config // {
|
||||
"count" : "# of notifications",
|
||||
"json" : "output as json",
|
||||
"reverse": "swap notification order"
|
||||
}
|
||||
dispatchMulti(
|
||||
[makoCmd, usage = clCfg.use, help = makoHelp, cmdName = "mako",],
|
||||
[start , usage = clCfg.use],
|
||||
[eww , usage = clCfg.use],
|
||||
[watch , usage = clCfg.use],
|
||||
)
|
||||
--- eww
|
||||
... "watch hyprland events for eww class changes"
|
||||
run: streamEwwClasses()
|
||||
|
|
23
src/mako.nim
23
src/mako.nim
|
@ -1,5 +1,8 @@
|
|||
import std/[algorithm, strutils, json, osproc, wordwrap, terminal]
|
||||
import hwylterm
|
||||
export hwylterm, json
|
||||
|
||||
# TODO: use jsony in this module
|
||||
|
||||
type
|
||||
MakoNotificationData = object
|
||||
|
@ -12,14 +15,14 @@ type
|
|||
Notification = object
|
||||
appName, summary, body: string
|
||||
History = object
|
||||
notifications: seq[Notification]
|
||||
notifications*: seq[Notification]
|
||||
|
||||
func toNotification(mn: MakoNotification): Notification =
|
||||
result.appName = mn.`app-name`.data
|
||||
result.summary = mn.summary.data
|
||||
result.body = mn.body.data
|
||||
|
||||
func toHistory(mh: MakoHistory): History =
|
||||
func toHistory*(mh: MakoHistory): History =
|
||||
for mn in mh.data[0]:
|
||||
result.notifications.add mn.toNotification()
|
||||
|
||||
|
@ -31,12 +34,15 @@ func filter(h: History, reverse: bool, count: int): History =
|
|||
result.notifications =
|
||||
result.notifications[0..high]
|
||||
|
||||
proc getMakoHistory(): MakoHistory =
|
||||
proc getMakoHistory*(): MakoHistory =
|
||||
let (output, errCode) = execCmdEx("makoctl history")
|
||||
if errCode != 0: quit output, errCode
|
||||
result = parseJson(output).to(MakoHistory)
|
||||
|
||||
proc bb(n: Notification): BbString =
|
||||
proc getHistory*(reverse: bool, count: int): History =
|
||||
getMakoHistory().toHistory().filter(reverse, count)
|
||||
|
||||
proc bb*(n: Notification): BbString =
|
||||
template border(style: string): untyped = "[" & style & "]" & "┃ [/]"
|
||||
var raw: string
|
||||
raw.add border("magenta") & "[yellow]" & n.appName & "[/]\n"
|
||||
|
@ -45,12 +51,3 @@ proc bb(n: Notification): BbString =
|
|||
raw.add border("default") & line & "\n"
|
||||
result = bb(raw)
|
||||
|
||||
proc makoCmd*(config = "", count = 10, json = false, reverse = false) =
|
||||
## interact with mako
|
||||
let history = getMakoHistory().toHistory().filter(reverse, count)
|
||||
if json:
|
||||
echo $(%* history)
|
||||
else:
|
||||
for n in history.notifications:
|
||||
echo $bb(n)
|
||||
|
||||
|
|
Loading…
Reference in a new issue