Merge branch 'main' of https://git.notnull.click/psw/wm_tools
This commit is contained in:
commit
656fd5a88f
3 changed files with 15 additions and 11 deletions
|
@ -12,7 +12,7 @@ const low_fg = red
|
|||
const alert_fg = black
|
||||
const alert_bg = yellow
|
||||
const med_fg = green
|
||||
const med_bg = black
|
||||
#const med_bg = black
|
||||
|
||||
|
||||
proc batteryExists(): bool =
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import ../../globurrl
|
||||
import std/[strutils,os,db_sqlite,osproc]
|
||||
|
||||
const CLIP_DB = WM_TOOLS_DIR & ".clipurr_cache.sqlite"
|
||||
const CLIP_DB = WM_TOOLS_DIR & "clipurr_cache.sqlite"
|
||||
const KEEP_ITEMS = 20
|
||||
|
||||
proc openDBConn(): DBConn
|
||||
let db = openDBConn()
|
||||
|
||||
proc addClip(str: var string)
|
||||
|
||||
|
@ -45,9 +44,8 @@ proc openDBConn(): DBConn =
|
|||
return db
|
||||
|
||||
proc clearHistory() =
|
||||
# let db = openDBConn()
|
||||
let db = openDBConn()
|
||||
|
||||
defer: db.close()
|
||||
try:
|
||||
db.exec(sql"drop table if exists clip_items")
|
||||
except:
|
||||
|
@ -56,8 +54,9 @@ proc clearHistory() =
|
|||
proc maintainDB() =
|
||||
return # order by and offset doesn't work unless certain sqlite compile time options set
|
||||
# will create a different way to do this
|
||||
let db = openDBConn()
|
||||
try:
|
||||
let db = openDBConn()
|
||||
defer: db.close()
|
||||
db.exec(sql"""BEGIN""")
|
||||
db.exec(sql"delete from clip_items order by timestamp desc offset ?", KEEP_ITEMS)
|
||||
db.exec(sql"""COMMIT""")
|
||||
|
@ -67,6 +66,7 @@ proc maintainDB() =
|
|||
proc escapeClip(str: string): string =
|
||||
var clip = str
|
||||
clip = clip.replace("`","\\`")
|
||||
clip = clip.replace("\\n`","\\\\n`")
|
||||
clip = escape(clip)
|
||||
return strip(clip)
|
||||
|
||||
|
@ -82,8 +82,9 @@ proc unescapeClip(str: string): string =
|
|||
proc readClipFile(): seq[string] =
|
||||
var clips: seq[string] = @[]
|
||||
# let db = openDBConn()
|
||||
defer: db.close()
|
||||
try:
|
||||
let db = openDBConn()
|
||||
defer: db.close()
|
||||
for row in db.fastRows(sql"select distinct(clip) from clip_items order by timestamp desc LIMIT ?", KEEP_ITEMS):
|
||||
var str = unescapeClip(row[0])
|
||||
clips.add(str)
|
||||
|
@ -98,12 +99,15 @@ proc addClip(str: var string) =
|
|||
var t = str[1..3]
|
||||
echo "Is a ", $t, " file , not storing"
|
||||
str = "[" & t & " Image] (not stored)"
|
||||
defer: db.close()
|
||||
try:
|
||||
str = escapeClip(str)
|
||||
echo "clipboard content : ", str
|
||||
let db = openDBConn()
|
||||
defer: db.close()
|
||||
db.exec(sql"""BEGIN""")
|
||||
db.exec(sql"""insert into clip_items (timestamp, clip)
|
||||
values (CURRENT_TIMESTAMP, ?)
|
||||
""", escapeClip(str))
|
||||
""", str)
|
||||
db.exec(sql"""COMMIT""")
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import ../../globurrl
|
||||
import std/[os,strutils,sequtils,times]
|
||||
import std/[os,sequtils,times]
|
||||
|
||||
const note_dir = WM_TOOLS_DIR & ".notes.dmenu/" # Putting it in Nextcloud so it can sync :-)
|
||||
const note_dir = WM_TOOLS_DIR & ".notes.wm_tools/" # Putting it in Nextcloud so it can sync :-)
|
||||
const default_bg = white
|
||||
const default_fg = black
|
||||
|
||||
|
|
Loading…
Reference in a new issue