diff --git a/src/model/config.nim b/src/model/config.nim index 9dd4174..8cc65f1 100644 --- a/src/model/config.nim +++ b/src/model/config.nim @@ -10,6 +10,7 @@ type run*: Tool max_lines*: int prepend*: bool + to_stdout*: bool screenshot_tool*: ScreenshotTool let config_dir* = getHomeDir() & ".config/wm_tools/" diff --git a/src/output.nim b/src/output.nim index cf3a9f1..00a9e11 100644 --- a/src/output.nim +++ b/src/output.nim @@ -25,8 +25,18 @@ proc copyToClipboard*(str: string): bool {.discardable.} = let ok = execCmd("echo -n " & quote(str) & " | xclip -selection clipboard") return ok == 0 +proc listify(data:Info, opts: varargs[string]): string = + var text = data.full_text + if opts.len > 0: + text &= "\n" + for opt in opts: + text &= markup text + text &= "\n" + return text + proc genMenuCmd(data: Info, opts: varargs[string]): string = var cmd = "" + # length of the list of opts, plus the full text var x_lines = len(opts) + 1 # if the text is empty, we don't want to create a menu item of it if data.full_text != "": @@ -52,11 +62,14 @@ proc genMenuCmd(data: Info, opts: varargs[string]): string = return cmd proc runExec(data: Info, opts: varargs[string]): string = - let cmd = genMenuCmd(data, opts) - var output = execCmdEx(cmd) - echo "Output:\n" & $output - output.output.stripLineEnd() - return output.output + if not myConfig.to_stdout: + let cmd = genMenuCmd(data, opts) + var output = execCmdEx(cmd) + echo "Output:\n" & $output + output.output.stripLineEnd() + return output.output + else: + stdout.writeLine listify(data,opts) proc outputData*(data: Info, args: varargs[string,`$`]): string {.discardable.} = var output = runExec(data,args) diff --git a/src/parser.nim b/src/parser.nim index 8d54493..b77cd27 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -15,8 +15,11 @@ proc parseArgs*() = help("WMTools : a set of tools to output option to your program of choice i.e. Rofi") arg("input",help="the tool to run, i.e. furrytime, pingclock, volurrme, etc.") arg("others", nargs = -1) + flag("-o","--output",help="outputs to stdout instead of something else") try: var opts = p.parse(params) + # TODO sort this but out, handle args for all modules, etc. + myConfig.to_stdout = opts.output case opts.input of "furrytime", "fuzzytime", "time": myConfig.run = FurryTime