Skip to content

Commit

Permalink
Allow opting out of clipboard features
Browse files Browse the repository at this point in the history
  • Loading branch information
YS-L committed Mar 25, 2024
1 parent 93d11e5 commit 5a42e34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ jobs:
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run tests (no default features)
run: cargo test --verbose --no-default-features
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ csv-sniffer = "0.3.1"
tui-input = { version = "0.8", features = ["crossterm"] }
arrow = {version = "50.0.0", default-features = false, features = ["csv"]}
sorted-vec = "0.8.3"
arboard = { version = "3.3.2", features = ["wayland-data-control"] }
arboard = { version = "3.3.2", features = ["wayland-data-control"], optional = true }

[target.'cfg(windows)'.dependencies]
crossterm = "0.27.0"

[features]
default = ["clipboard"]
clipboard = ["dep:arboard"]

# The profile that 'cargo dist' will build with
[profile.dist]
inherits = "release"
Expand Down
6 changes: 6 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::ui::{CsvTable, CsvTableState, FilterColumnsState, FinderState};
use crate::view;

use anyhow::ensure;
#[cfg(feature = "clipboard")]
use arboard::Clipboard;
use ratatui::backend::Backend;
use ratatui::{Frame, Terminal};
Expand Down Expand Up @@ -142,6 +143,7 @@ pub struct App {
help_page_state: help::HelpPageState,
sorter: Option<Arc<sort::Sorter>>,
line_wrap_state: LineWrapState,
#[cfg(feature = "clipboard")]
clipboard: Result<Clipboard>,
}

Expand Down Expand Up @@ -201,10 +203,12 @@ impl App {
let transient_message: Option<String> = None;
let help_page_state = help::HelpPageState::new();

#[cfg(feature = "clipboard")]
let clipboard = match Clipboard::new() {
Ok(clipboard) => Ok(clipboard),
Err(e) => Err(anyhow::anyhow!(e)),
};

let mut app = App {
input_handler,
num_rows_not_visible,
Expand All @@ -221,6 +225,7 @@ impl App {
help_page_state,
sorter: None,
line_wrap_state: LineWrapState::default(),
#[cfg(feature = "clipboard")]
clipboard,
};

Expand Down Expand Up @@ -461,6 +466,7 @@ impl App {
Control::DecreaseWidth => {
self.adjust_column_width(-4);
}
#[cfg(feature = "clipboard")]
Control::CopySelection => {
if let Some(selected) = self.rows_view.get_cell_value_from_selection() {
match self.clipboard.as_mut().map(|c| c.set_text(&selected)) {
Expand Down

0 comments on commit 5a42e34

Please sign in to comment.