From 69918d3dfe49ec7c1740c5f83fe84114388fe48a Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Thu, 23 Nov 2023 12:29:08 +0000 Subject: [PATCH] added calc --- src/dispatcher.nim | 3 +++ src/model/tool.nim | 3 ++- src/parser.nim | 2 ++ src/util/{calculaturr/src => }/calculaturr.nim | 18 ++++++++++-------- src/util/calculaturr/calculaturr.nimble | 13 ------------- 5 files changed, 17 insertions(+), 22 deletions(-) rename src/util/{calculaturr/src => }/calculaturr.nim (83%) delete mode 100644 src/util/calculaturr/calculaturr.nimble diff --git a/src/dispatcher.nim b/src/dispatcher.nim index ed59021..3435421 100644 --- a/src/dispatcher.nim +++ b/src/dispatcher.nim @@ -12,6 +12,7 @@ import util/passwurrd import util/pw_generaturr import util/temperaturr import util/screenshurrt +import util/calculaturr proc dispatch*(cfg: Config) = case cfg.run @@ -39,5 +40,7 @@ proc dispatch*(cfg: Config) = temperaturr.go() of Screenshurrt: screenshurrt.go() + of Calculaturr: + calculaturr.go() else: echo "No valid run command given" diff --git a/src/model/tool.nim b/src/model/tool.nim index 9b1a794..a879016 100644 --- a/src/model/tool.nim +++ b/src/model/tool.nim @@ -13,4 +13,5 @@ type Passwurrd, PasswurrdGeneraturr, Temperaturr, - Screenshurrt + Screenshurrt, + Calculaturr diff --git a/src/parser.nim b/src/parser.nim index cf970f9..f3caec8 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -40,6 +40,8 @@ proc parseArgs*() = myConfig.run = Temperaturr of "screenshurrt", "screenshot", "screeny": myConfig.run = Screenshurrt + of "calculaturr", "calculator", "calc": + myConfig.run = Calculaturr else: echo p.help quit(1) diff --git a/src/util/calculaturr/src/calculaturr.nim b/src/util/calculaturr.nim similarity index 83% rename from src/util/calculaturr/src/calculaturr.nim rename to src/util/calculaturr.nim index b3085c7..18604f4 100644 --- a/src/util/calculaturr/src/calculaturr.nim +++ b/src/util/calculaturr.nim @@ -1,9 +1,14 @@ -import ../../globurrl -import std/[osproc,strutils,sequtils] +import osproc +import strutils +import sequtils + +import ../common +import ../output # using qalc as it has a lot of nice inbuilt features # may be nice to make it totally non-dependant on other things though +const exitSeq = @["---","exit"] proc doCalculation(calc: string) = var info = newInfo("Calculaturr") let ans_cmd_terse = "echo \"" & calc & "\" | qalc +u8 -terse -color=never | awk '!/^>/ && !/^$/ {gsub(/^[ \\t]+|[ \\t]+$/, \"\", $0); print}'" @@ -14,17 +19,16 @@ proc doCalculation(calc: string) = ans_terse.output.stripLineEnd() let answers = @[strip(ans_full.output), strip(ans_terse.output)] - let args = concat(answers,@["exit"]) + let args = concat(answers,exitSeq) var cmd = outputData(info, args) - cmd.stripLineEnd() if cmd in answers: copyToClipboard(cmd) - elif cmd == "exit" or cmd == "": + elif cmd in exitSeq or cmd == "": return else: doCalculation(cmd) -proc main() = +proc go*() = var info = newInfo("Calculaturr") let args = @["exit"] let cmd = outputData(info, args) @@ -32,5 +36,3 @@ proc main() = doCalculation(cmd) return -if isMainModule: - main() diff --git a/src/util/calculaturr/calculaturr.nimble b/src/util/calculaturr/calculaturr.nimble deleted file mode 100644 index 638d262..0000000 --- a/src/util/calculaturr/calculaturr.nimble +++ /dev/null @@ -1,13 +0,0 @@ -# Package - -version = "0.1.0" -author = "Paul Wilde" -description = "A simple dmenu calculator" -license = "MIT" -srcDir = "src" -bin = @["calculaturr"] - - -# Dependencies - -requires "nim >= 1.6.6"