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_fg = black
|
||||||
const alert_bg = yellow
|
const alert_bg = yellow
|
||||||
const med_fg = green
|
const med_fg = green
|
||||||
const med_bg = black
|
#const med_bg = black
|
||||||
|
|
||||||
|
|
||||||
proc batteryExists(): bool =
|
proc batteryExists(): bool =
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import ../../globurrl
|
import ../../globurrl
|
||||||
import std/[strutils,os,db_sqlite,osproc]
|
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
|
const KEEP_ITEMS = 20
|
||||||
|
|
||||||
proc openDBConn(): DBConn
|
proc openDBConn(): DBConn
|
||||||
let db = openDBConn()
|
|
||||||
|
|
||||||
proc addClip(str: var string)
|
proc addClip(str: var string)
|
||||||
|
|
||||||
|
@ -45,9 +44,8 @@ proc openDBConn(): DBConn =
|
||||||
return db
|
return db
|
||||||
|
|
||||||
proc clearHistory() =
|
proc clearHistory() =
|
||||||
# let db = openDBConn()
|
let db = openDBConn()
|
||||||
|
|
||||||
defer: db.close()
|
|
||||||
try:
|
try:
|
||||||
db.exec(sql"drop table if exists clip_items")
|
db.exec(sql"drop table if exists clip_items")
|
||||||
except:
|
except:
|
||||||
|
@ -56,8 +54,9 @@ proc clearHistory() =
|
||||||
proc maintainDB() =
|
proc maintainDB() =
|
||||||
return # order by and offset doesn't work unless certain sqlite compile time options set
|
return # order by and offset doesn't work unless certain sqlite compile time options set
|
||||||
# will create a different way to do this
|
# will create a different way to do this
|
||||||
let db = openDBConn()
|
|
||||||
try:
|
try:
|
||||||
|
let db = openDBConn()
|
||||||
|
defer: db.close()
|
||||||
db.exec(sql"""BEGIN""")
|
db.exec(sql"""BEGIN""")
|
||||||
db.exec(sql"delete from clip_items order by timestamp desc offset ?", KEEP_ITEMS)
|
db.exec(sql"delete from clip_items order by timestamp desc offset ?", KEEP_ITEMS)
|
||||||
db.exec(sql"""COMMIT""")
|
db.exec(sql"""COMMIT""")
|
||||||
|
@ -67,6 +66,7 @@ proc maintainDB() =
|
||||||
proc escapeClip(str: string): string =
|
proc escapeClip(str: string): string =
|
||||||
var clip = str
|
var clip = str
|
||||||
clip = clip.replace("`","\\`")
|
clip = clip.replace("`","\\`")
|
||||||
|
clip = clip.replace("\\n`","\\\\n`")
|
||||||
clip = escape(clip)
|
clip = escape(clip)
|
||||||
return strip(clip)
|
return strip(clip)
|
||||||
|
|
||||||
|
@ -82,8 +82,9 @@ proc unescapeClip(str: string): string =
|
||||||
proc readClipFile(): seq[string] =
|
proc readClipFile(): seq[string] =
|
||||||
var clips: seq[string] = @[]
|
var clips: seq[string] = @[]
|
||||||
# let db = openDBConn()
|
# let db = openDBConn()
|
||||||
defer: db.close()
|
|
||||||
try:
|
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):
|
for row in db.fastRows(sql"select distinct(clip) from clip_items order by timestamp desc LIMIT ?", KEEP_ITEMS):
|
||||||
var str = unescapeClip(row[0])
|
var str = unescapeClip(row[0])
|
||||||
clips.add(str)
|
clips.add(str)
|
||||||
|
@ -98,12 +99,15 @@ proc addClip(str: var string) =
|
||||||
var t = str[1..3]
|
var t = str[1..3]
|
||||||
echo "Is a ", $t, " file , not storing"
|
echo "Is a ", $t, " file , not storing"
|
||||||
str = "[" & t & " Image] (not stored)"
|
str = "[" & t & " Image] (not stored)"
|
||||||
defer: db.close()
|
|
||||||
try:
|
try:
|
||||||
|
str = escapeClip(str)
|
||||||
|
echo "clipboard content : ", str
|
||||||
|
let db = openDBConn()
|
||||||
|
defer: db.close()
|
||||||
db.exec(sql"""BEGIN""")
|
db.exec(sql"""BEGIN""")
|
||||||
db.exec(sql"""insert into clip_items (timestamp, clip)
|
db.exec(sql"""insert into clip_items (timestamp, clip)
|
||||||
values (CURRENT_TIMESTAMP, ?)
|
values (CURRENT_TIMESTAMP, ?)
|
||||||
""", escapeClip(str))
|
""", str)
|
||||||
db.exec(sql"""COMMIT""")
|
db.exec(sql"""COMMIT""")
|
||||||
except:
|
except:
|
||||||
echo getCurrentExceptionMsg()
|
echo getCurrentExceptionMsg()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import ../../globurrl
|
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_bg = white
|
||||||
const default_fg = black
|
const default_fg = black
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue