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

This commit is contained in:
Stephan Dilly 2020-09-01 01:36:38 +02:00 committed by GitHub
parent 9be119a2f0
commit e5c38e8d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 30 deletions

View File

@ -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

View File

@ -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

2
Cargo.lock generated
View File

@ -419,7 +419,7 @@ dependencies = [
[[package]]
name = "gitui"
version = "0.10.0"
version = "0.10.1"
dependencies = [
"anyhow",
"asyncgit",

View File

@ -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"
@ -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 }
@ -49,7 +49,7 @@ pprof = { version = "0.3", features = ["flamegraph"], optional = true }
maintenance = { status = "actively-developed" }
[features]
default=[]
default=["clipboard"]
timing=["scopetime/enabled"]
[workspace]

View File

@ -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

30
src/clipboard.rs Normal file
View File

@ -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
}

View File

@ -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::{
@ -21,8 +21,6 @@ use tui::{
Frame,
};
use anyhow::{anyhow, Result};
#[derive(Default)]
struct Current {
path: String,
@ -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
@ -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")
)
);
}
@ -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(
@ -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 {

View File

@ -10,6 +10,7 @@
#![warn(clippy::missing_const_for_fn)]
mod app;
mod clipboard;
mod cmdbar;
mod components;
mod input;