update: feature flag

This commit is contained in:
GreasrySlug 2023-02-02 14:38:09 +09:00
parent abff062d90
commit 281ca62be5
5 changed files with 33 additions and 22 deletions

2
Cargo.lock generated
View file

@ -130,12 +130,10 @@ dependencies = [
name = "erg"
version = "0.6.3"
dependencies = [
"crossterm",
"els",
"erg_common",
"erg_compiler",
"erg_parser",
"wl-clipboard-rs",
]
[[package]]

View file

@ -59,7 +59,7 @@ large_thread = [
]
py_compatible = ["erg_compiler/py_compatible", "els/py_compatible"]
els = ["erg_common/els", "erg_compiler/els", "dep:els"]
full-repl = ["crossterm", "wl-clipboard-rs"]
full-repl = ["erg_common/full-repl"]
[workspace.dependencies]
@ -74,16 +74,6 @@ erg_parser = { workspace = true }
erg_compiler = { workspace = true }
els = { workspace = true, optional = true }
[dependencies.crossterm]
default-features = false
optional = true
version = "0.26.0"
[target.'cfg(linux)'.dependencies.wl-clipboard-rs]
default-features = false
optional = true
version = "0.7.0"
[build-dependencies]
erg_common = { workspace = true }

View file

@ -20,7 +20,7 @@ large_thread = []
els = []
py_compatible = []
no_std = []
full-repl = []
full-repl = ["crossterm", "wl-clipboard-rs"]
[target.'cfg(unix)'.dependencies]
libc = { version = "0.2", default-features = false }
@ -32,12 +32,10 @@ version = "0.3"
features = ["consoleapi"]
[dependencies.crossterm]
default-features = false
optional = true
version = "0.26.0"
[target.'cfg(linux)'.dependencies.wl-clipboard-rs]
default-features = false
optional = true
version = "0.7.0"

View file

@ -1,8 +1,12 @@
use std::cell::RefCell;
use std::process::Command;
use std::process::Output;
use std::thread::LocalKey;
#[cfg(not(feature = "full-repl"))]
use std::io::{stdin, BufRead, BufReader};
#[cfg(feature = "full-repl")]
use std::process::{Command, Output};
#[cfg(feature = "full-repl")]
use crossterm::{
cursor::{MoveToColumn, SetCursorStyle},
event::{read, Event, KeyCode, KeyEvent, KeyModifiers},
@ -28,12 +32,13 @@ pub struct StdinReader {
block_begin: usize,
lineno: usize,
buf: Vec<String>,
#[cfg(feature = "full-repl")]
history_input_position: usize,
indent: u16,
}
impl StdinReader {
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "full-repl"))]
fn access_clipboard() -> Option<Output> {
if let Ok(str) = std::fs::read("/proc/sys/kernel/osrelease") {
if let Ok(str) = std::str::from_utf8(&str) {
@ -52,7 +57,7 @@ impl StdinReader {
.output()
.ok()
}
#[cfg(target_os = "macos")]
#[cfg(all(target_os = "macos", feature = "full-repl"))]
fn access_clipboard() -> Option<Output> {
Some(
Command::new("pbpast")
@ -61,7 +66,7 @@ impl StdinReader {
)
}
#[cfg(target_os = "windows")]
#[cfg(all(target_os = "windows", feature = "full-repl"))]
fn access_clipboard() -> Option<Output> {
Some(
Command::new("powershell")
@ -71,6 +76,18 @@ impl StdinReader {
)
}
#[cfg(not(feature = "full-repl"))]
pub fn read(&mut self) -> String {
let mut line = "".to_string();
let stdin = stdin();
let mut reader = BufReader::new(stdin.lock());
reader.read_line(&mut line).unwrap();
self.lineno += 1;
self.buf.push(line.trim_end().to_string());
self.buf.last().cloned().unwrap_or_default()
}
#[cfg(feature = "full-repl")]
pub fn read(&mut self) -> String {
enable_raw_mode().unwrap();
let mut output = std::io::stdout();
@ -84,6 +101,7 @@ impl StdinReader {
self.buf.last().cloned().unwrap_or_default()
}
#[cfg(feature = "full-repl")]
fn input(&mut self, line: &mut String) -> std::io::Result<()> {
let mut position = 0;
let mut consult_history = false;
@ -231,7 +249,13 @@ impl StdinReader {
}
thread_local! {
static READER: RefCell<StdinReader> = RefCell::new(StdinReader{ block_begin: 1, lineno: 1, buf: vec![], history_input_position: 1, indent: 1 });
static READER: RefCell<StdinReader> = RefCell::new(StdinReader{ block_begin: 1,
lineno: 1,
buf: vec![],
#[cfg(feature = "full-repl")]
history_input_position: 1,
indent: 1
});
}
#[derive(Debug)]

View file

@ -37,6 +37,7 @@ large_thread = [
py_compatible = ["erg_common/py_compatible"]
els = ["erg_common/els"]
no_std = ["erg_common/no_std"]
full-repl = ["erg_common/full-repl"]
[dependencies]
erg_common = { workspace = true, path = "../erg_common" }