diff --git a/CHANGES.md b/CHANGES.md index 79fc705..a4eb224 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ Next Release v0.3.0 -- Add Mac supoprt. +- Add Mac support. - Add `--one-shot` mode to allow copying data as it is from stdin. v0.2.1 diff --git a/README.md b/README.md index 3909e5c..59480e6 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ command line utility as an alternative to [xclip](https://github.com/astrand/xcl [xsel](https://github.com/astrand/xclip), [wl-clipboard](https://github.com/bugaevc/wl-clipboard) or other command line clipboard tools. -- Supports Multiple environments. Xorg, Wayland and MacOS are supported by the current +- Supports Multiple environments. Xorg, Wayland and macOS are supported by the current version. Windows is planned. - Recognizes the environment automatically, and choose the right clipboard to use. @@ -22,7 +22,7 @@ or other command line clipboard tools. Install `richclip` from the [AUR](https://aur.archlinux.org/packages/richclip). -### MacOS & Other Linux Distributions +### macOS & Other Linux Distributions Download the static linked binary from the [release page](https://github.com/beeender/richclip/releases). diff --git a/src/clipboard/mac.rs b/src/clipboard/mac.rs index ae18757..79a61e2 100644 --- a/src/clipboard/mac.rs +++ b/src/clipboard/mac.rs @@ -95,7 +95,7 @@ unsafe fn copy_mac(config: CopyConfig) -> Result<()> { unsafe fn paste_mac(config: PasteConfig) -> Result<()> { let _pool = NSAutoreleasePool::new(nil); - let mut writer = config.writter; + let mut writer = config.writer; let mut type_list: Vec = vec![]; let pb = NSPasteboard::generalPasteboard(nil); diff --git a/src/clipboard/mod.rs b/src/clipboard/mod.rs index 261a364..c533be6 100644 --- a/src/clipboard/mod.rs +++ b/src/clipboard/mod.rs @@ -21,7 +21,7 @@ pub struct PasteConfig { pub list_types_only: bool, pub use_primary: bool, pub expected_mime_type: String, - pub writter: Box, + pub writer: Box, } pub struct CopyConfig { diff --git a/src/clipboard/wayland.rs b/src/clipboard/wayland.rs index 82edebe..b61589e 100644 --- a/src/clipboard/wayland.rs +++ b/src/clipboard/wayland.rs @@ -28,7 +28,7 @@ struct WaylandClient { } struct CopyEventState { - finishied: bool, + finished: bool, source_data: Box, } @@ -74,7 +74,7 @@ fn create_wayland_client() -> Result> { fn paste_wayland(cfg: PasteConfig) -> Result<()> { let mut client = - create_wayland_client::().context("Faild to create wayland client")?; + create_wayland_client::().context("Failed to create wayland client")?; let _data_control_device = client.data_ctl_mgr.get_data_device_with_cb( &mut client.conn, @@ -106,7 +106,7 @@ fn paste_wayland(cfg: PasteConfig) -> Result<()> { // with "-l", list the mime-types and return if state.config.list_types_only { for mt in supported_types { - writeln!(state.config.writter, "{mt}")?; + writeln!(state.config.writer, "{mt}")?; } return Ok(()); } @@ -125,14 +125,14 @@ fn paste_wayland(cfg: PasteConfig) -> Result<()> { client.conn.flush(IoMode::Blocking)?; let mut pipe_read = File::from(pipe_read); - std::io::copy(&mut pipe_read, &mut state.config.writter)?; + std::io::copy(&mut pipe_read, &mut state.config.writer)?; Ok(()) } fn copy_wayland(config: CopyConfig) -> Result<()> { let mut client = - create_wayland_client::().context("Faild to create wayland client")?; + create_wayland_client::().context("Failed to create wayland client")?; let source = client .data_ctl_mgr @@ -152,13 +152,13 @@ fn copy_wayland(config: CopyConfig) -> Result<()> { } let mut state = CopyEventState { - finishied: false, + finished: false, source_data: config.source_data, }; client.conn.flush(IoMode::Blocking).unwrap(); loop { - if state.finishied { + if state.finished { break; } client.conn.recv_events(IoMode::Blocking).unwrap(); @@ -239,7 +239,7 @@ fn wl_source_cb_for_copy(ctx: EventCtx) zwlr_data_control_source_v1::Event::Cancelled => { log::debug!("Received 'Cancelled' event"); ctx.conn.break_dispatch_loop(); - ctx.state.finishied = true; + ctx.state.finished = true; } _ => unreachable!("Unexpected event for source callback"), } diff --git a/src/clipboard/x.rs b/src/clipboard/x.rs index 1168099..ab365d9 100644 --- a/src/clipboard/x.rs +++ b/src/clipboard/x.rs @@ -437,11 +437,11 @@ fn mime_types_to_targets(conn: &RustConnection, mime_types: &Vec) -> Vec fn decide_mime_type_with_atom( conn: &RustConnection, - prefered_atom: Atom, + preferred_atom: Atom, supported: &Vec, ) -> Result { - let prefered = get_atom_name(conn, prefered_atom)?; - let mime_type = decide_mime_type(&prefered, supported)?; + let preferred = get_atom_name(conn, preferred_atom)?; + let mime_type = decide_mime_type(&preferred, supported)?; Ok(mime_type) } @@ -548,7 +548,7 @@ fn paste_x(config: PasteConfig) -> Result<()> { } if state.config.list_types_only { for line in mime_types { - writeln!(&mut state.config.writter, "{}", line) + writeln!(&mut state.config.writer, "{}", line) .context("Failed to write to the output")?; } break; @@ -580,7 +580,7 @@ fn paste_x(config: PasteConfig) -> Result<()> { } else { match &mut state.receiver { Some(receiver) => { - if receiver.receive_and_write(&client, &mut state.config.writter)? + if receiver.receive_and_write(&client, &mut state.config.writer)? == TransferResult::Done { break; @@ -607,7 +607,7 @@ fn paste_x(config: PasteConfig) -> Result<()> { }; match &mut state.receiver { Some(receiver) => { - if receiver.receive_and_write_incr(&client, &mut state.config.writter)? + if receiver.receive_and_write_incr(&client, &mut state.config.writer)? == TransferResult::Done { break; diff --git a/src/main.rs b/src/main.rs index 2abce8f..7c606c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -197,7 +197,7 @@ fn do_paste(paste_args: &PasteArgs) -> Result<()> { use_primary: paste_args.primary, #[cfg(not(target_os = "linux"))] use_primary: false, - writter: Box::new(stdout()), + writer: Box::new(stdout()), expected_mime_type: paste_args.type_.clone(), }; clipboard::create_backend()? diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 2a72c2b..0112ff6 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -2,7 +2,7 @@ mod recv; mod source_data; #[allow(unused_imports)] -pub use recv::PROTOCAL_VER; +pub use recv::PROTOCOL_VER; pub use recv::receive_data_bulk; pub use recv::receive_data_oneshot; pub use source_data::SourceData; diff --git a/src/protocol/recv.rs b/src/protocol/recv.rs index c5ab6cd..c6be7ab 100644 --- a/src/protocol/recv.rs +++ b/src/protocol/recv.rs @@ -1,7 +1,7 @@ use anyhow::{Context, Result, bail}; use std::io::Read; -pub static PROTOCAL_VER: u8 = 0; +pub static PROTOCOL_VER: u8 = 0; static MAGIC: [u8; 4] = [0x20, 0x09, 0x02, 0x14]; use super::source_data::SourceDataItem; @@ -46,8 +46,8 @@ pub fn receive_data_bulk(mut reader: impl Read) -> Result> { let mut ver = [0u8; 1]; reader .read_exact(&mut ver) - .context("Failed to read protocal version")?; - if ver[0] != PROTOCAL_VER { + .context("Failed to read protocol version")?; + if ver[0] != PROTOCOL_VER { bail!("Failed to match protoal version: {}", ver[0]); } @@ -201,7 +201,7 @@ mod tests { #[test] fn test_receive_data_bulk() { // Wrong magic - let buf = [0x02, 0x09, 0x02, 0x14, PROTOCAL_VER, b'M']; + let buf = [0x02, 0x09, 0x02, 0x14, PROTOCOL_VER, b'M']; let r = receive_data_bulk(&mut &buf[..]); assert!(r.is_err()); @@ -213,7 +213,7 @@ mod tests { // correct #[rustfmt::skip] let buf = - [0x20, 0x09, 0x02, 0x14, PROTOCAL_VER, + [0x20, 0x09, 0x02, 0x14, PROTOCOL_VER, b'M', 0, 0, 0, 10, b't', b'e', b'x', b't', b'/', b'p', b'l', b'a', b'i', b'n', b'M', 0, 0, 0, 4, b'T', b'E', b'X', b'T', b'C', 0, 0, 0, 4, b'G', b'O', b'O', b'D', diff --git a/src/protocol/source_data.rs b/src/protocol/source_data.rs index d464272..90488a1 100644 --- a/src/protocol/source_data.rs +++ b/src/protocol/source_data.rs @@ -56,14 +56,14 @@ impl SourceData for Vec { #[cfg(test)] mod tests { use super::*; - use crate::protocol::PROTOCAL_VER; + use crate::protocol::PROTOCOL_VER; use crate::protocol::receive_data_bulk; #[test] fn test_content_by_mime_type() { #[rustfmt::skip] let buf = - [0x20, 0x09, 0x02, 0x14, PROTOCAL_VER, + [0x20, 0x09, 0x02, 0x14, PROTOCOL_VER, b'M', 0, 0, 0, 10, b't', b'e', b'x', b't', b'/', b'p', b'l', b'a', b'i', b'n', b'M', 0, 0, 0, 4, b'T', b'E', b'X', b'T', b'C', 0, 0, 0, 4, b'G', b'O', b'O', b'D', diff --git a/test/bats/wayland/wayland.bats b/test/bats/wayland/wayland.bats index aa05ee5..7e51d8f 100755 --- a/test/bats/wayland/wayland.bats +++ b/test/bats/wayland/wayland.bats @@ -42,8 +42,8 @@ teardown() { [ "$output" = "" ] } -@test "wayland paste with empty clipbaord" { - # Empty clipbaord +@test "wayland paste with empty clipboard" { + # Empty clipboard wl-copy -c run -0 --separate-stderr "$RICHCLIP" paste [ "$output" = "" ] diff --git a/test/bats/x/x.bats b/test/bats/x/x.bats index 2f9df9e..8d9040e 100755 --- a/test/bats/x/x.bats +++ b/test/bats/x/x.bats @@ -31,10 +31,10 @@ teardown() { [ "$output" = "" ] } -@test "X paste with empty clipbaord" { - # NOTE: This test fails with gnome, it seems the clipbaord is not empty after xclip getting +@test "X paste with empty clipboard" { + # NOTE: This test fails with gnome, it seems the clipboard is not empty after xclip getting # killed - # Empty clipbaord + # Empty clipboard echo "TestDaTA" | xclip -i -selection clipboard 3>&- killall xclip run -0 --separate-stderr "$RICHCLIP" paste