diff --git a/clipurr/src/clipurr.nim b/clipurr/src/clipurr.nim index 2a7e8b3..f36e101 100644 --- a/clipurr/src/clipurr.nim +++ b/clipurr/src/clipurr.nim @@ -2,7 +2,7 @@ import ../../globurrl import std/[strutils,os,db_sqlite,osproc] const CLIP_DB = WM_TOOLS_DIR & "clipurr_cache.sqlite" -const KEEP_ITEMS = 20 +const KEEP_ITEMS = 15 proc openDBConn(): DBConn @@ -22,6 +22,8 @@ proc runDaemon() = else: var run = true while run: + # TODO; + # Check if WM is running otherwise the TTY will be spammed with "Using Clipnotify" text echo "Using Clipnotify" let outp = execCmdEx("clipnotify") if outp.exitcode == 0: @@ -67,13 +69,19 @@ proc escapeClip(str: string): string = var clip = str clip = clip.replace("`","\\`") clip = clip.replace("\\n`","\\\\n`") + clip = clip.replace("\x0A","\\x0A") clip = escape(clip) + echo "CLIP : ", clip return strip(clip) proc unescapeClip(str: string): string = var clip = str try: clip = unescape(clip) + if contains(clip,"\\x0A"): + echo "NEWLINE FOUND" + let idx = find(clip, "\\x0A") - 1 + clip = clip[0 .. idx] & " ... more ..." except: echo getCurrentExceptionMsg() @@ -113,12 +121,43 @@ proc addClip(str: var string) = echo getCurrentExceptionMsg() return +proc getFullClipboardContent(str: string): string = + var full = "" + try: + let db = openDBConn() + defer: db.close() + let text = "\"" & replace(str," ... more ...", "%") & "\"" + let stmt = """ + select clip + from clip_items + where clip like ? + order by timestamp desc + LIMIT 1""" + var prep = db.prepare(stmt) + prep.bindParams(text) + let res = db.getAllRows(prep) + for r in res: + # may need to switch to a getRow or getValue method here as this is messy + full = unescape(r[0]) + full = replace(full, "\\x0A","\x0A") + break + finalize(prep) + except: + echo "Error Reading Clip File : " & getCurrentExceptionMsg() + + + return full + proc showClips() = let clips = readClipFile() let info = newInfo("Clipurr") let option = outputData(info, clips) if option != "": - copyToClipboard(option) + if contains(option, "... more ..."): + let full = getFullClipboardContent(option) + copyToClipboard(full) + else: + copyToClipboard(option) return proc main() =