refactor: drop cligen and update hwylterm

This commit is contained in:
Daylin Morgan 2024-09-30 18:13:55 -05:00
parent 46d4dfd010
commit 07dd5a5238
Signed by: daylin
GPG key ID: 950D13E9719334AD
6 changed files with 52 additions and 32 deletions

View file

@ -1,24 +1,14 @@
{ {
"version": 2, "version": 2,
"packages": { "packages": {
"cligen": {
"version": "1.7.5",
"vcsRevision": "85daafd76b0104387f50ff3f75c829b4c2804412",
"url": "https://github.com/c-blake/cligen.git",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "f3ffe7329c8db755677d3ca377d02ff176cec8b1"
}
},
"hwylterm": { "hwylterm": {
"version": "0.1.0", "version": "0.1.0",
"vcsRevision": "c2bcfd1f73dda97bd3e209c89e2abfe588f0977c", "vcsRevision": "337083afe13bf0f1bd024b870c2174a901e8ce06",
"url": "https://github.com/daylinmorgan/hwylterm", "url": "https://github.com/daylinmorgan/hwylterm",
"downloadMethod": "git", "downloadMethod": "git",
"dependencies": [], "dependencies": [],
"checksums": { "checksums": {
"sha1": "1932229840c893c39acca0b50def19913678f5f0" "sha1": "a995a81f5e4af2991c79ed04b02f17d47dd509e0"
} }
}, },
"illwill": { "illwill": {

View file

@ -43,7 +43,7 @@
pname = "tsm"; pname = "tsm";
version = "2024.1001-unstable"; version = "2024.1001-unstable";
src = ../.; src = ../.;
nimbleDepsHash = "sha256-8noTwYwtaPaF9iGq4EZhWMi709l9e66CJn8vm4aIyO4="; nimbleDepsHash = "sha256-YtW7jv2D/o6z6vgx8cKfqGzs/Yyd6s/Cl5Xs7yavA18=";
nimFlags = [ nimFlags = [
"-d:TsmVersion=v${version}" "-d:TsmVersion=v${version}"
]; ];

View file

@ -10,7 +10,7 @@ type
open*: bool open*: bool
matched*: bool matched*: bool
proc pathToName(path: string): string = proc pathToName*(path: string): string =
splitPath(path)[1].replace(".", "_") splitPath(path)[1].replace(".", "_")
proc newProject*(path: string, open: bool, name = "", named: bool = false): Project = proc newProject*(path: string, open: bool, name = "", named: bool = false): Project =
@ -19,7 +19,7 @@ proc newProject*(path: string, open: bool, name = "", named: bool = false): Proj
if name != "": if name != "":
name name
else: else:
path.pathToName() pathToName(path)
result.updated = getLastModificationTime(path) result.updated = getLastModificationTime(path)
result.open = open result.open = open
result.named = named result.named = named

View file

@ -1,4 +1,4 @@
import std/[enumerate, os, strformat, strutils, terminal, sequtils] import std/[enumerate, os, strformat, strutils, terminal]
from illwill import illwillDeinit, illwillInit, getKey, Key from illwill import illwillDeinit, illwillInit, getKey, Key
import term, project import term, project
@ -44,7 +44,12 @@ func addDivider(b: var Buffer) =
b.addLine "".repeat(b.width - 2) b.addLine "".repeat(b.width - 2)
proc addInput(b: var Buffer) = proc addInput(b: var Buffer) =
b.addLine "$ " & state.input var line = "$ "
if state.input != "":
line.add state.input
else:
line.add $pathToName(getCurrentDir()).bb("faint")
b.addLine line
func numLines(b: Buffer): int = func numLines(b: Buffer): int =
b.buffer.count '\n' b.buffer.count '\n'

View file

@ -1,6 +1,4 @@
import std/[tables] import ./[selector, project, tmuxutils]
import selector, project, tmuxutils
# TODO: add option to only opened configured sessions # TODO: add option to only opened configured sessions
proc tsm(open: bool = false) = proc tsm(open: bool = false) =
@ -14,16 +12,44 @@ proc tsm(open: bool = false) =
else: else:
tmux.attach project.name tmux.attach project.name
proc getVersion(): string =
const tsmVersion {.strdefine.} = "unknown"
const gitVersion = staticExec "git describe --tags --always HEAD --match 'v*'"
when tsmVersion != "unknown": tsmVersion
else: gitVersion
when isMainModule: when isMainModule:
import cligen, hwylterm, hwylterm/cli import std/parseopt
clCfg.version = getVersion() import hwylterm, hwylterm/cli
hwylCli(clCfg)
let clUse* = $bb("$command $args\n${doc}[bold]Options[/]:\n$options") const tsmVersion {.strdefine.} = staticExec "git describe --tags --always HEAD --match 'v*'"
dispatch(tsm, usage = clUse, short = {"version": 'v'}) proc help() =
echo newHwylCli(
"""tmux session manager
[bold]tsm[/] [[[faint]-h|-v|-o[/]]""",
flags = [
("h","help","show this help"),
("v","version", "print version"),
("o","open", "only search open sessions")
]
)
var open: bool
var p = initOptParser(
shortNoVal = {'h', 'v', 'o'},
longNoVal = @["open"]
)
for kind, key, val in p.getOpt():
case kind:
of cmdEnd:
break
of cmdArgument:
echo bb"[red]Error[/]: unexpected positional argument ", bbfmt"[bold]{key}[/]"
of cmdShortOption, cmdLongOption:
case key:
of "help", "h":
help(); quit 0
of "version", "v":
echo "tsm: " & tsmVersion; quit 0
of "open", "o":
open = true
else:
echo bbfmt"[red]Error[/]: unknown key value pair", bbfmt"[b]key[/]: {key}, [b]value[/]: {val}"
tsm(open)

View file

@ -12,7 +12,6 @@ binDir = "bin"
requires "nim >= 2.0.0" requires "nim >= 2.0.0"
requires "illwill >= 0.4.1" requires "illwill >= 0.4.1"
requires "cligen"
requires "https://github.com/daylinmorgan/hwylterm#HEAD" requires "https://github.com/daylinmorgan/hwylterm#HEAD"
requires "https://github.com/usu-dev/usu-nim" requires "https://github.com/usu-dev/usu-nim"