allowed exit on escape

This commit is contained in:
Paul Wilde 2022-05-09 20:12:05 +01:00
parent bd899ebbf3
commit dced0c0438
2 changed files with 13 additions and 10 deletions

View file

@ -174,9 +174,9 @@ proc runDMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
#echo cmd #echo cmd
# #
# Run command and get output # Run command and get output
let output = execCmdEx(cmd) var output = execCmdEx(cmd)
let option:string = strip(output[0]) output.output.stripLineEnd()
return option return output.output
proc outputData*(data: Info, args: varargs[string]): string {.discardable.} = proc outputData*(data: Info, args: varargs[string]): string {.discardable.} =
var output = "" var output = ""

View file

@ -7,15 +7,18 @@ proc doCalculation(calc: string) =
var info = newInfo("Calculator") var info = newInfo("Calculator")
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}'"
let ans_cmd_full = "echo \"" & calc & "\" | qalc +u8 -color=never | awk '!/^>/ && !/^$/ {gsub(/^[ \\t]+|[ \\t]+$/, \"\", $0); print}'" let ans_cmd_full = "echo \"" & calc & "\" | qalc +u8 -color=never | awk '!/^>/ && !/^$/ {gsub(/^[ \\t]+|[ \\t]+$/, \"\", $0); print}'"
let ans_full = execCmdEx(ans_cmd_full) var ans_full = execCmdEx(ans_cmd_full)
let ans_terse = execCmdEx(ans_cmd_terse) ans_full.output.stripLineEnd()
let answers = @[strip(ans_terse.output), var ans_terse = execCmdEx(ans_cmd_terse)
strip(ans_full.output)] ans_terse.output.stripLineEnd()
let answers = @[strip(ans_full.output),
strip(ans_terse.output)]
let args = concat(answers,@["exit"]) let args = concat(answers,@["exit"])
let cmd = outputData(info, args) var cmd = outputData(info, args)
cmd.stripLineEnd()
if cmd in answers: if cmd in answers:
discard execCmd("echo \"" & strip(cmd) & "\" | xclip") discard execCmd("echo " & quote(cmd) & " | xclip")
elif cmd == "exit": elif cmd == "exit" or cmd == "":
return return
else: else:
doCalculation(cmd) doCalculation(cmd)