mirror of
https://github.com/NotAShelf/stash.git
synced 2026-04-13 06:23:47 +00:00
commands/list: add include_expired parameter for filtering
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ia1ab13345cfa5e2cf9a92f8b32a6a9826a6a6964
This commit is contained in:
parent
b070d4d93d
commit
2e555ee043
1 changed files with 23 additions and 8 deletions
|
|
@ -6,8 +6,12 @@ use unicode_width::UnicodeWidthStr;
|
||||||
use crate::db::{ClipboardDb, SqliteClipboardDb, StashError};
|
use crate::db::{ClipboardDb, SqliteClipboardDb, StashError};
|
||||||
|
|
||||||
pub trait ListCommand {
|
pub trait ListCommand {
|
||||||
fn list(&self, out: impl Write, preview_width: u32)
|
fn list(
|
||||||
-> Result<(), StashError>;
|
&self,
|
||||||
|
out: impl Write,
|
||||||
|
preview_width: u32,
|
||||||
|
include_expired: bool,
|
||||||
|
) -> Result<(), StashError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListCommand for SqliteClipboardDb {
|
impl ListCommand for SqliteClipboardDb {
|
||||||
|
|
@ -15,14 +19,21 @@ impl ListCommand for SqliteClipboardDb {
|
||||||
&self,
|
&self,
|
||||||
out: impl Write,
|
out: impl Write,
|
||||||
preview_width: u32,
|
preview_width: u32,
|
||||||
|
include_expired: bool,
|
||||||
) -> Result<(), StashError> {
|
) -> Result<(), StashError> {
|
||||||
self.list_entries(out, preview_width).map(|_| ())
|
self
|
||||||
|
.list_entries(out, preview_width, include_expired)
|
||||||
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SqliteClipboardDb {
|
impl SqliteClipboardDb {
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub fn list_tui(&self, preview_width: u32) -> Result<(), StashError> {
|
pub fn list_tui(
|
||||||
|
&self,
|
||||||
|
preview_width: u32,
|
||||||
|
include_expired: bool,
|
||||||
|
) -> Result<(), StashError> {
|
||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
|
|
@ -53,12 +64,16 @@ impl SqliteClipboardDb {
|
||||||
use wl_clipboard_rs::copy::{MimeType, Options, Source};
|
use wl_clipboard_rs::copy::{MimeType, Options, Source};
|
||||||
|
|
||||||
// Query entries from DB
|
// Query entries from DB
|
||||||
|
let query = if include_expired {
|
||||||
|
"SELECT id, contents, mime FROM clipboard ORDER BY last_accessed DESC, \
|
||||||
|
id DESC"
|
||||||
|
} else {
|
||||||
|
"SELECT id, contents, mime FROM clipboard WHERE (is_expired IS NULL OR \
|
||||||
|
is_expired = 0) ORDER BY last_accessed DESC, id DESC"
|
||||||
|
};
|
||||||
let mut stmt = self
|
let mut stmt = self
|
||||||
.conn
|
.conn
|
||||||
.prepare(
|
.prepare(query)
|
||||||
"SELECT id, contents, mime FROM clipboard ORDER BY last_accessed \
|
|
||||||
DESC, id DESC",
|
|
||||||
)
|
|
||||||
.map_err(|e| StashError::ListDecode(e.to_string().into()))?;
|
.map_err(|e| StashError::ListDecode(e.to_string().into()))?;
|
||||||
let mut rows = stmt
|
let mut rows = stmt
|
||||||
.query([])
|
.query([])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue