Skip to content

Commit e5c38e8

Browse files
author
Stephan Dilly
authored
revert clipboard feature on linux to fix static linux binary build (#261)
1 parent 9be119a commit e5c38e8

File tree

8 files changed

+66
-30
lines changed

8 files changed

+66
-30
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ jobs:
7070
run: |
7171
sudo apt-get -qq install musl-tools
7272
- name: Build Debug
73-
run: cargo build --target=x86_64-unknown-linux-musl
73+
run: |
74+
make build-linux-musl-debug
75+
./target/x86_64-unknown-linux-musl/debug/gitui --version
7476
- name: Build Release
7577
run: |
76-
cargo build --release --target=x86_64-unknown-linux-musl
78+
make build-linux-musl-release
79+
./target/x86_64-unknown-linux-musl/release/gitui --version
7780
7881
rustfmt:
7982
name: Rustfmt

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.10.1] - 2020-09-01
9+
10+
### Fixed
11+
- static linux binaries broke due to new clipboard feature which is disabled on linux for now ([#259](https://github.com/extrawurst/gitui/issues/259))
12+
813
## [0.10.0] - 2020-08-29
914

1015
### Added

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gitui"
3-
version = "0.10.0"
3+
version = "0.10.1"
44
authors = ["Stephan Dilly <[email protected]>"]
55
description = "blazing fast terminal-ui for git"
66
edition = "2018"
@@ -40,7 +40,7 @@ serde = "1.0"
4040
anyhow = "1.0.32"
4141
unicode-width = "0.1"
4242
textwrap = "0.12"
43-
clipboard = "0.5"
43+
clipboard = { version = "0.5", optional = true }
4444

4545
[target.'cfg(not(windows))'.dependencies]
4646
pprof = { version = "0.3", features = ["flamegraph"], optional = true }
@@ -49,7 +49,7 @@ pprof = { version = "0.3", features = ["flamegraph"], optional = true }
4949
maintenance = { status = "actively-developed" }
5050

5151
[features]
52-
default=[]
52+
default=["clipboard"]
5353
timing=["scopetime/enabled"]
5454

5555
[workspace]

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ release-win: build-release
2020
mkdir -p release
2121
tar -C ./target/release/ -czvf ./release/gitui-win.tar.gz ./gitui.exe
2222

23-
release-linux-musl:
24-
cargo build --release --target=x86_64-unknown-linux-musl
23+
release-linux-musl: build-linux-musl-release
2524
strip target/x86_64-unknown-linux-musl/release/gitui
2625
mkdir -p release
2726
tar -C ./target/x86_64-unknown-linux-musl/release/ -czvf ./release/gitui-linux-musl.tar.gz ./gitui
2827

28+
build-linux-musl-debug:
29+
cargo build --target=x86_64-unknown-linux-musl --no-default-features
30+
31+
build-linux-musl-release:
32+
cargo build --release --target=x86_64-unknown-linux-musl --no-default-features
33+
2934
test:
3035
cargo test --workspace
3136

src/clipboard.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use anyhow::Result;
2+
#[cfg(feature = "clipboard")]
3+
use clipboard::{ClipboardContext, ClipboardProvider};
4+
5+
#[cfg(feature = "clipboard")]
6+
pub fn copy_string(string: String) -> Result<()> {
7+
use anyhow::anyhow;
8+
9+
let mut ctx: ClipboardContext = ClipboardProvider::new()
10+
.map_err(|_| anyhow!("failed to get access to clipboard"))?;
11+
ctx.set_contents(string)
12+
.map_err(|_| anyhow!("failed to set clipboard contents"))?;
13+
14+
Ok(())
15+
}
16+
17+
#[cfg(not(feature = "clipboard"))]
18+
pub fn copy_string(_string: String) -> Result<()> {
19+
Ok(())
20+
}
21+
22+
#[cfg(feature = "clipboard")]
23+
pub fn is_supported() -> bool {
24+
true
25+
}
26+
27+
#[cfg(not(feature = "clipboard"))]
28+
pub fn is_supported() -> bool {
29+
false
30+
}

src/components/diff.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::{
88
strings, try_or_popup,
99
ui::{self, calc_scroll_top, style::SharedTheme},
1010
};
11+
use anyhow::Result;
1112
use asyncgit::{hash, sync, DiffLine, DiffLineType, FileDiff, CWD};
1213
use bytesize::ByteSize;
13-
use clipboard::{ClipboardContext, ClipboardProvider};
1414
use crossterm::event::Event;
1515
use std::{borrow::Cow, cell::Cell, cmp, path::Path};
1616
use tui::{
@@ -21,8 +21,6 @@ use tui::{
2121
Frame,
2222
};
2323

24-
use anyhow::{anyhow, Result};
25-
2624
#[derive(Default)]
2725
struct Current {
2826
path: String,
@@ -244,18 +242,6 @@ impl DiffComponent {
244242
Ok(())
245243
}
246244

247-
fn copy_string(string: String) -> Result<()> {
248-
let mut ctx: ClipboardContext = ClipboardProvider::new()
249-
.map_err(|_| {
250-
anyhow!("failed to get access to clipboard")
251-
})?;
252-
ctx.set_contents(string).map_err(|_| {
253-
anyhow!("failed to set clipboard contents")
254-
})?;
255-
256-
Ok(())
257-
}
258-
259245
fn copy_selection(&self) -> Result<()> {
260246
if let Some(diff) = &self.diff {
261247
let lines_to_copy: Vec<&str> = diff
@@ -281,7 +267,9 @@ impl DiffComponent {
281267
try_or_popup!(
282268
self,
283269
"copy to clipboard error:",
284-
Self::copy_string(lines_to_copy.join("\n"))
270+
crate::clipboard::copy_string(
271+
lines_to_copy.join("\n")
272+
)
285273
);
286274
}
287275

@@ -616,11 +604,13 @@ impl Component for DiffComponent {
616604
self.focused,
617605
));
618606

619-
out.push(CommandInfo::new(
620-
strings::commands::copy(&self.key_config),
621-
true,
622-
self.focused,
623-
));
607+
if crate::clipboard::is_supported() {
608+
out.push(CommandInfo::new(
609+
strings::commands::copy(&self.key_config),
610+
true,
611+
self.focused,
612+
));
613+
}
624614

625615
out.push(
626616
CommandInfo::new(
@@ -700,7 +690,9 @@ impl Component for DiffComponent {
700690
}
701691
}
702692
Ok(true)
703-
} else if e == self.key_config.copy {
693+
} else if e == self.key_config.copy
694+
&& crate::clipboard::is_supported()
695+
{
704696
self.copy_selection()?;
705697
Ok(true)
706698
} else {

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![warn(clippy::missing_const_for_fn)]
1111

1212
mod app;
13+
mod clipboard;
1314
mod cmdbar;
1415
mod components;
1516
mod input;

0 commit comments

Comments
 (0)