added calc

This commit is contained in:
Paul Wilde 2023-11-23 12:29:08 +00:00
parent 9570461b13
commit 69918d3dfe
5 changed files with 17 additions and 22 deletions

View file

@ -12,6 +12,7 @@ import util/passwurrd
import util/pw_generaturr import util/pw_generaturr
import util/temperaturr import util/temperaturr
import util/screenshurrt import util/screenshurrt
import util/calculaturr
proc dispatch*(cfg: Config) = proc dispatch*(cfg: Config) =
case cfg.run case cfg.run
@ -39,5 +40,7 @@ proc dispatch*(cfg: Config) =
temperaturr.go() temperaturr.go()
of Screenshurrt: of Screenshurrt:
screenshurrt.go() screenshurrt.go()
of Calculaturr:
calculaturr.go()
else: else:
echo "No valid run command given" echo "No valid run command given"

View file

@ -13,4 +13,5 @@ type
Passwurrd, Passwurrd,
PasswurrdGeneraturr, PasswurrdGeneraturr,
Temperaturr, Temperaturr,
Screenshurrt Screenshurrt,
Calculaturr

View file

@ -40,6 +40,8 @@ proc parseArgs*() =
myConfig.run = Temperaturr myConfig.run = Temperaturr
of "screenshurrt", "screenshot", "screeny": of "screenshurrt", "screenshot", "screeny":
myConfig.run = Screenshurrt myConfig.run = Screenshurrt
of "calculaturr", "calculator", "calc":
myConfig.run = Calculaturr
else: else:
echo p.help echo p.help
quit(1) quit(1)

View file

@ -1,9 +1,14 @@
import ../../globurrl import osproc
import std/[osproc,strutils,sequtils] import strutils
import sequtils
import ../common
import ../output
# using qalc as it has a lot of nice inbuilt features # using qalc as it has a lot of nice inbuilt features
# may be nice to make it totally non-dependant on other things though # may be nice to make it totally non-dependant on other things though
const exitSeq = @["---","exit"]
proc doCalculation(calc: string) = proc doCalculation(calc: string) =
var info = newInfo("Calculaturr") var info = newInfo("Calculaturr")
let ans_cmd_terse = "echo \"" & calc & "\" | qalc +u8 -terse -color=never | awk '!/^>/ && !/^$/ {gsub(/^[ \\t]+|[ \\t]+$/, \"\", $0); print}'" 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() ans_terse.output.stripLineEnd()
let answers = @[strip(ans_full.output), let answers = @[strip(ans_full.output),
strip(ans_terse.output)] strip(ans_terse.output)]
let args = concat(answers,@["exit"]) let args = concat(answers,exitSeq)
var cmd = outputData(info, args) var cmd = outputData(info, args)
cmd.stripLineEnd()
if cmd in answers: if cmd in answers:
copyToClipboard(cmd) copyToClipboard(cmd)
elif cmd == "exit" or cmd == "": elif cmd in exitSeq or cmd == "":
return return
else: else:
doCalculation(cmd) doCalculation(cmd)
proc main() = proc go*() =
var info = newInfo("Calculaturr") var info = newInfo("Calculaturr")
let args = @["exit"] let args = @["exit"]
let cmd = outputData(info, args) let cmd = outputData(info, args)
@ -32,5 +36,3 @@ proc main() =
doCalculation(cmd) doCalculation(cmd)
return return
if isMainModule:
main()

View file

@ -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"