fix: unable to build on android using termux (#222)

pull/224/head
sigoden 8 months ago committed by GitHub
parent d40f104f66
commit 534733b77c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -35,7 +35,6 @@ base64 = "0.21.0"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
bstr = "1.3.0" bstr = "1.3.0"
nu-ansi-term = "0.47.0" nu-ansi-term = "0.47.0"
arboard = { version = "3.2.0", default-features = false }
async-trait = "0.1.74" async-trait = "0.1.74"
textwrap = "0.16.0" textwrap = "0.16.0"
ansi_colours = "1.2.2" ansi_colours = "1.2.2"
@ -53,6 +52,9 @@ version = "5.0.0"
default-features = false default-features = false
features = ["parsing", "regex-onig", "plist-load"] features = ["parsing", "regex-onig", "plist-load"]
[target.'cfg(not(any(target_os = "android", target_os = "emscripten")))'.dependencies]
arboard = { version = "3.2.0", default-features = false }
[profile.release] [profile.release]
lto = true lto = true
strip = true strip = true

@ -11,10 +11,9 @@ use self::validator::ReplValidator;
use crate::client::init_client; use crate::client::init_client;
use crate::config::GlobalConfig; use crate::config::GlobalConfig;
use crate::render::{render_error, render_stream}; use crate::render::{render_error, render_stream};
use crate::utils::{create_abort_signal, AbortSignal}; use crate::utils::{create_abort_signal, set_text, AbortSignal};
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use arboard::Clipboard;
use crossbeam::sync::WaitGroup; use crossbeam::sync::WaitGroup;
use fancy_regex::Regex; use fancy_regex::Regex;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -24,7 +23,6 @@ use reedline::{
ColumnarMenu, EditMode, Emacs, KeyCode, KeyModifiers, Keybindings, Reedline, ReedlineEvent, ColumnarMenu, EditMode, Emacs, KeyCode, KeyModifiers, Keybindings, Reedline, ReedlineEvent,
ReedlineMenu, Vi, ReedlineMenu, Vi,
}; };
use std::cell::RefCell;
use std::io::Read; use std::io::Read;
const MENU_NAME: &str = "completion_menu"; const MENU_NAME: &str = "completion_menu";
@ -56,7 +54,6 @@ pub struct Repl {
editor: Reedline, editor: Reedline,
prompt: ReplPrompt, prompt: ReplPrompt,
abort: AbortSignal, abort: AbortSignal,
clipboard: std::result::Result<RefCell<Clipboard>, arboard::Error>,
} }
impl Repl { impl Repl {
@ -67,13 +64,10 @@ impl Repl {
let abort = create_abort_signal(); let abort = create_abort_signal();
let clipboard = Clipboard::new().map(RefCell::new);
Ok(Self { Ok(Self {
config: config.clone(), config: config.clone(),
editor, editor,
prompt, prompt,
clipboard,
abort, abort,
}) })
} }
@ -315,13 +309,8 @@ Type ".help" for more information.
if text.is_empty() { if text.is_empty() {
bail!("No text") bail!("No text")
} }
match self.clipboard.as_ref() { set_text(text)?;
Err(err) => bail!("{}", err), Ok(())
Ok(clip) => {
clip.borrow_mut().set_text(text)?;
Ok(())
}
}
} }
} }

@ -0,0 +1,20 @@
#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
lazy_static::lazy_static! {
static ref CLIPBOARD: std::sync::Arc<std::sync::Mutex<Option<arboard::Clipboard>>> =
std::sync::Arc::new(std::sync::Mutex::new(arboard::Clipboard::new().ok()));
}
#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
pub fn set_text(text: &str) -> anyhow::Result<()> {
let mut clipboard = CLIPBOARD.lock().unwrap();
match clipboard.as_mut() {
Some(clipboard) => clipboard.set_text(text)?,
None => anyhow::bail!("No available clipboard"),
}
Ok(())
}
#[cfg(any(target_os = "android", target_os = "emscripten"))]
pub fn set_text(_text: &str) -> anyhow::Result<()> {
anyhow::bail!("No available clipboard")
}

@ -1,9 +1,11 @@
mod abort_signal; mod abort_signal;
mod clipboard;
mod prompt_input; mod prompt_input;
mod split_line; mod split_line;
mod tiktoken; mod tiktoken;
pub use self::abort_signal::{create_abort_signal, AbortSignal}; pub use self::abort_signal::{create_abort_signal, AbortSignal};
pub use self::clipboard::set_text;
pub use self::prompt_input::*; pub use self::prompt_input::*;
pub use self::split_line::*; pub use self::split_line::*;
pub use self::tiktoken::cl100k_base_singleton; pub use self::tiktoken::cl100k_base_singleton;

Loading…
Cancel
Save