added calc
This commit is contained in:
parent
9570461b13
commit
69918d3dfe
5 changed files with 17 additions and 22 deletions
|
@ -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"
|
||||
|
|
|
@ -13,4 +13,5 @@ type
|
|||
Passwurrd,
|
||||
PasswurrdGeneraturr,
|
||||
Temperaturr,
|
||||
Screenshurrt
|
||||
Screenshurrt,
|
||||
Calculaturr
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
|
@ -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"
|
Loading…
Reference in a new issue