2022-05-09 20:56:26 +02:00
|
|
|
import base
|
|
|
|
import std/[osproc,strutils,sequtils]
|
|
|
|
|
|
|
|
#using qalc as it has a lot of nice inbuilt features
|
|
|
|
#
|
|
|
|
proc doCalculation(calc: string) =
|
|
|
|
var info = newInfo("Calculator")
|
|
|
|
let ans_cmd_terse = "echo \"" & calc & "\" | qalc +u8 -terse -color=never | awk '!/^>/ && !/^$/ {gsub(/^[ \\t]+|[ \\t]+$/, \"\", $0); print}'"
|
|
|
|
let ans_cmd_full = "echo \"" & calc & "\" | qalc +u8 -color=never | awk '!/^>/ && !/^$/ {gsub(/^[ \\t]+|[ \\t]+$/, \"\", $0); print}'"
|
2022-05-09 21:12:05 +02:00
|
|
|
var ans_full = execCmdEx(ans_cmd_full)
|
|
|
|
ans_full.output.stripLineEnd()
|
|
|
|
var ans_terse = execCmdEx(ans_cmd_terse)
|
|
|
|
ans_terse.output.stripLineEnd()
|
|
|
|
let answers = @[strip(ans_full.output),
|
|
|
|
strip(ans_terse.output)]
|
2022-05-09 20:56:26 +02:00
|
|
|
let args = concat(answers,@["exit"])
|
2022-05-09 21:12:05 +02:00
|
|
|
var cmd = outputData(info, args)
|
|
|
|
cmd.stripLineEnd()
|
2022-05-09 20:56:26 +02:00
|
|
|
if cmd in answers:
|
2022-05-09 22:08:54 +02:00
|
|
|
copyToClipboard(cmd)
|
2022-05-09 21:12:05 +02:00
|
|
|
elif cmd == "exit" or cmd == "":
|
2022-05-09 20:56:26 +02:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
doCalculation(cmd)
|
|
|
|
|
|
|
|
proc main() =
|
|
|
|
var info = newInfo("Calculator")
|
|
|
|
let args = @["exit"]
|
|
|
|
let cmd = outputData(info, args)
|
|
|
|
if cmd != "":
|
|
|
|
doCalculation(cmd)
|
|
|
|
return
|
|
|
|
|
|
|
|
if isMainModule:
|
|
|
|
main()
|