Skip to content

Commit

Permalink
Merge pull request #319 from cortex/replace-cli-clipboard-with-arboard
Browse files Browse the repository at this point in the history
replace cli-clipboard with arboard
  • Loading branch information
alexanderkjall authored Oct 6, 2023
2 parents 8001be2 + 02e83c3 commit cabeaad
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 34 deletions.
153 changes: 127 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "GPL-3.0-only"
edition = '2021'

[dependencies]
arboard = "3.2.1"
glob = "0.3.1"
gpgme = "0.11.0"
chrono = { version = "0.4", default_features = false, features = ["clock"] }
Expand Down
2 changes: 1 addition & 1 deletion cursive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build = "build.rs"

[dependencies]
cursive = { version = "0.20.0", default-features = false, features = ["toml", "crossterm-backend"]}
cli-clipboard = "0.4.0"
arboard = { version = "3.2.1", features = ["wayland-data-control"]}
ripasso = { path = "../", version = "0.7.0-alpha" }
locale_config = "0.3.0"
unic-langid = "0.9.1"
Expand Down
14 changes: 9 additions & 5 deletions cursive/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use cli_clipboard::{ClipboardContext, ClipboardProvider};
use std::sync::{Arc, Mutex};

use arboard::Clipboard;
use cursive::{
event::Key,
views::{Checkbox, Dialog, EditView, OnEventView, RadioButton, TextView},
Cursive,
};
use lazy_static::lazy_static;
use pass::Result;
use ripasso::{crypto::CryptoImpl, pass};

lazy_static! {
static ref CLIPBOARD: Arc<Mutex<Clipboard>> = Arc::new(Mutex::new(Clipboard::new().unwrap()));
}

/// Displays an error in a cursive dialog
pub fn errorbox(ui: &mut Cursive, err: &pass::Error) {
let text = match err {
Expand All @@ -46,10 +53,7 @@ pub fn errorbox(ui: &mut Cursive, err: &pass::Error) {

/// Copies content to the clipboard.
pub fn set_clipboard(content: String) -> Result<()> {
let mut ctx = ClipboardContext::new()?;
ctx.set_contents(content)?;

Ok(())
Ok(CLIPBOARD.lock().unwrap().set_text(content)?)
}

pub fn get_value_from_input(s: &mut Cursive, input_name: &str) -> Option<std::rc::Rc<String>> {
Expand Down
8 changes: 8 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::pass::PasswordStore;
#[non_exhaustive]
#[derive(Debug)]
pub enum Error {
Clipboard(arboard::Error),
Io(io::Error),
Git(git2::Error),
Gpg(gpgme::Error),
Expand All @@ -33,6 +34,12 @@ pub enum Error {
SystemTimeError(std::time::SystemTimeError),
}

impl From<arboard::Error> for Error {
fn from(err: arboard::Error) -> Self {
Self::Clipboard(err)
}
}

impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::Io(err)
Expand Down Expand Up @@ -189,6 +196,7 @@ impl From<PoisonError<MutexGuard<'_, Arc<Mutex<PasswordStore>>>>> for Error {
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Clipboard(err) => write!(f, "{err}"),
Self::Io(err) => write!(f, "{err}"),
Self::Git(err) => write!(f, "{err}"),
Self::Gpg(err) => write!(f, "{err}"),
Expand Down
8 changes: 6 additions & 2 deletions src/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,12 @@ impl PasswordStore {
let keys = self
.all_recipients()?
.into_iter()
.map(|s| format!("0x{}, ", s.key_id))
.collect::<String>();
.fold(String::new(), |mut acc, r| {
use std::fmt::Write;
let _ = write!(acc, ", 0x{}", r.key_id);
acc
});

let message = format!("Reencrypt password store with new GPG ids {keys}");

self.add_and_commit(&names, &message)?;
Expand Down

0 comments on commit cabeaad

Please sign in to comment.