-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from FMotalleb/refactor
major: refactor codebase without a breaking change
- Loading branch information
Showing
19 changed files
with
428 additions
and
392 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use super::error_mapper::map_arboard_err_to_label; | ||
use nu_protocol::LabeledError; | ||
pub(crate) fn with_clipboard_instance< | ||
U, | ||
F: FnOnce(&mut arboard::Clipboard) -> Result<U, arboard::Error>, | ||
>( | ||
op: F, | ||
) -> Result<U, LabeledError> { | ||
let mut clipboard = arboard::Clipboard::new().map_err(map_arboard_err_to_label)?; | ||
|
||
op(&mut clipboard).map_err(map_arboard_err_to_label) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::io::Error; | ||
|
||
use nu_protocol::LabeledError; | ||
|
||
use super::arboard_provider::with_clipboard_instance; | ||
|
||
pub enum CheckResult { | ||
Continue, | ||
Exit(String, i32), | ||
} | ||
|
||
fn no_daemon(config: Option<nu_protocol::Value>) -> Result<bool, Error> { | ||
match config { | ||
None => Ok(false), | ||
Some(nu_protocol::Value::Record { val, .. }) => { | ||
return no_daemon(val.get("NO_DAEMON").cloned()); | ||
} | ||
Some(nu_protocol::Value::Bool { val, .. }) => Ok(val), | ||
Some(nu_protocol::Value::String { val, .. }) => match val.as_str() { | ||
"true" | "True" | "1" => Ok(true), | ||
_ => Ok(false), | ||
}, | ||
Some(nu_protocol::Value::Int { val, .. }) => Ok(val == 1), | ||
_ => Ok(true), | ||
} | ||
} | ||
|
||
pub fn create_clipboard(config: Option<nu_protocol::Value>) -> impl Clipboard { | ||
#[cfg(target_os = "linux")] | ||
{ | ||
crate::clipboard::linux::ClipBoardLinux::new(!no_daemon(config).unwrap_or(false)) | ||
} | ||
#[cfg(target_os = "macos")] | ||
{ | ||
crate::clipboard::mac_os::ClipboardMacOs::new() | ||
} | ||
#[cfg(target_os = "windows")] | ||
{ | ||
crate::clipboard::windows::ClipboardWindows::new() | ||
} | ||
} | ||
|
||
pub trait Clipboard { | ||
fn pre_execute_check(&self) -> CheckResult { | ||
CheckResult::Continue | ||
} | ||
fn copy_text(&self, text: &str) -> Result<(), LabeledError> { | ||
with_clipboard_instance(|clip| clip.set_text(text)) | ||
} | ||
fn get_text(&self) -> Result<String, LabeledError> { | ||
with_clipboard_instance(|clip| clip.get_text()) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub(crate) fn map_arboard_err_to_label(err: arboard::Error) -> nu_protocol::LabeledError { | ||
nu_protocol::LabeledError::new(format!("Clipboard Error: {}", err.to_string())) | ||
} |
Oops, something went wrong.