Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).

Expand Down
2 changes: 1 addition & 1 deletion src/clipboard/mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = vec![];

let pb = NSPasteboard::generalPasteboard(nil);
Expand Down
2 changes: 1 addition & 1 deletion src/clipboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct PasteConfig {
pub list_types_only: bool,
pub use_primary: bool,
pub expected_mime_type: String,
pub writter: Box<dyn Write>,
pub writer: Box<dyn Write>,
}

pub struct CopyConfig {
Expand Down
16 changes: 8 additions & 8 deletions src/clipboard/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct WaylandClient<T> {
}

struct CopyEventState {
finishied: bool,
finished: bool,
source_data: Box<dyn SourceData>,
}

Expand Down Expand Up @@ -74,7 +74,7 @@ fn create_wayland_client<T>() -> Result<WaylandClient<T>> {

fn paste_wayland(cfg: PasteConfig) -> Result<()> {
let mut client =
create_wayland_client::<PasteEventState>().context("Faild to create wayland client")?;
create_wayland_client::<PasteEventState>().context("Failed to create wayland client")?;

let _data_control_device = client.data_ctl_mgr.get_data_device_with_cb(
&mut client.conn,
Expand Down Expand Up @@ -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(());
}
Expand All @@ -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::<CopyEventState>().context("Faild to create wayland client")?;
create_wayland_client::<CopyEventState>().context("Failed to create wayland client")?;

let source = client
.data_ctl_mgr
Expand All @@ -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();
Expand Down Expand Up @@ -239,7 +239,7 @@ fn wl_source_cb_for_copy(ctx: EventCtx<CopyEventState, ZwlrDataControlSourceV1>)
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"),
}
Expand Down
12 changes: 6 additions & 6 deletions src/clipboard/x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ fn mime_types_to_targets(conn: &RustConnection, mime_types: &Vec<String>) -> Vec

fn decide_mime_type_with_atom(
conn: &RustConnection,
prefered_atom: Atom,
preferred_atom: Atom,
supported: &Vec<String>,
) -> Result<String> {
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)
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
10 changes: 5 additions & 5 deletions src/protocol/recv.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -46,8 +46,8 @@ pub fn receive_data_bulk(mut reader: impl Read) -> Result<Vec<SourceDataItem>> {
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]);
}

Expand Down Expand Up @@ -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());

Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/source_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ impl SourceData for Vec<SourceDataItem> {
#[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',
Expand Down
4 changes: 2 additions & 2 deletions test/bats/wayland/wayland.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "" ]
Expand Down
6 changes: 3 additions & 3 deletions test/bats/x/x.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading