Skip to content

revert clipboard feature on linux to fix static linux binary build #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 31, 2020
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
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ jobs:
run: |
sudo apt-get -qq install musl-tools
- name: Build Debug
run: cargo build --target=x86_64-unknown-linux-musl
run: |
make build-linux-musl-debug
./target/x86_64-unknown-linux-musl/debug/gitui --version
- name: Build Release
run: |
cargo build --release --target=x86_64-unknown-linux-musl
make build-linux-musl-release
./target/x86_64-unknown-linux-musl/release/gitui --version

rustfmt:
name: Rustfmt
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.10.1] - 2020-09-01

### Fixed
- static linux binaries broke due to new clipboard feature which is disabled on linux for now ([#259](https://github.com/extrawurst/gitui/issues/259))

## [0.10.0] - 2020-08-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gitui"
version = "0.10.0"
version = "0.10.1"
authors = ["Stephan Dilly <dilly.stephan@gmail.com>"]
description = "blazing fast terminal-ui for git"
edition = "2018"
Expand Down Expand Up @@ -40,7 +40,7 @@ serde = "1.0"
anyhow = "1.0.32"
unicode-width = "0.1"
textwrap = "0.12"
clipboard = "0.5"
clipboard = { version = "0.5", optional = true }

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

[features]
default=[]
default=["clipboard"]
timing=["scopetime/enabled"]

[workspace]
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ release-win: build-release
mkdir -p release
tar -C ./target/release/ -czvf ./release/gitui-win.tar.gz ./gitui.exe

release-linux-musl:
cargo build --release --target=x86_64-unknown-linux-musl
release-linux-musl: build-linux-musl-release
strip target/x86_64-unknown-linux-musl/release/gitui
mkdir -p release
tar -C ./target/x86_64-unknown-linux-musl/release/ -czvf ./release/gitui-linux-musl.tar.gz ./gitui

build-linux-musl-debug:
cargo build --target=x86_64-unknown-linux-musl --no-default-features

build-linux-musl-release:
cargo build --release --target=x86_64-unknown-linux-musl --no-default-features

test:
cargo test --workspace

Expand Down
30 changes: 30 additions & 0 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use anyhow::Result;
#[cfg(feature = "clipboard")]
use clipboard::{ClipboardContext, ClipboardProvider};

#[cfg(feature = "clipboard")]
pub fn copy_string(string: String) -> Result<()> {
use anyhow::anyhow;

let mut ctx: ClipboardContext = ClipboardProvider::new()
.map_err(|_| anyhow!("failed to get access to clipboard"))?;
ctx.set_contents(string)
.map_err(|_| anyhow!("failed to set clipboard contents"))?;

Ok(())
}

#[cfg(not(feature = "clipboard"))]
pub fn copy_string(_string: String) -> Result<()> {
Ok(())
}

#[cfg(feature = "clipboard")]
pub fn is_supported() -> bool {
true
}

#[cfg(not(feature = "clipboard"))]
pub fn is_supported() -> bool {
false
}
36 changes: 14 additions & 22 deletions src/components/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::{
strings, try_or_popup,
ui::{self, calc_scroll_top, style::SharedTheme},
};
use anyhow::Result;
use asyncgit::{hash, sync, DiffLine, DiffLineType, FileDiff, CWD};
use bytesize::ByteSize;
use clipboard::{ClipboardContext, ClipboardProvider};
use crossterm::event::Event;
use std::{borrow::Cow, cell::Cell, cmp, path::Path};
use tui::{
Expand All @@ -21,8 +21,6 @@ use tui::{
Frame,
};

use anyhow::{anyhow, Result};

#[derive(Default)]
struct Current {
path: String,
Expand Down Expand Up @@ -244,18 +242,6 @@ impl DiffComponent {
Ok(())
}

fn copy_string(string: String) -> Result<()> {
let mut ctx: ClipboardContext = ClipboardProvider::new()
.map_err(|_| {
anyhow!("failed to get access to clipboard")
})?;
ctx.set_contents(string).map_err(|_| {
anyhow!("failed to set clipboard contents")
})?;

Ok(())
}

fn copy_selection(&self) -> Result<()> {
if let Some(diff) = &self.diff {
let lines_to_copy: Vec<&str> = diff
Expand All @@ -281,7 +267,9 @@ impl DiffComponent {
try_or_popup!(
self,
"copy to clipboard error:",
Self::copy_string(lines_to_copy.join("\n"))
crate::clipboard::copy_string(
lines_to_copy.join("\n")
)
);
}

Expand Down Expand Up @@ -616,11 +604,13 @@ impl Component for DiffComponent {
self.focused,
));

out.push(CommandInfo::new(
strings::commands::copy(&self.key_config),
true,
self.focused,
));
if crate::clipboard::is_supported() {
out.push(CommandInfo::new(
strings::commands::copy(&self.key_config),
true,
self.focused,
));
}

out.push(
CommandInfo::new(
Expand Down Expand Up @@ -700,7 +690,9 @@ impl Component for DiffComponent {
}
}
Ok(true)
} else if e == self.key_config.copy {
} else if e == self.key_config.copy
&& crate::clipboard::is_supported()
{
self.copy_selection()?;
Ok(true)
} else {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![warn(clippy::missing_const_for_fn)]

mod app;
mod clipboard;
mod cmdbar;
mod components;
mod input;
Expand Down