Skip to content

Commit

Permalink
Merge pull request #335 from Vap0r1ze/feat/virt-input
Browse files Browse the repository at this point in the history
Allow virtual term input in raw mode
  • Loading branch information
kaikalii authored Dec 28, 2023
2 parents 9b88513 + e8c4e11 commit 31d2638
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ toml = "0.8.8"
unicode-segmentation = "1.10"

# Native dependencies
crossterm = {version = "0.27.0", optional = true}
rawrrr = {version = "0.1.0", optional = true}
httparse = {version = "1.8.0", optional = true}
open = {version = "5", optional = true}
rustls = {version = "0.22.1", optional = true, default-features = false, features = [
Expand Down Expand Up @@ -109,7 +109,7 @@ invoke = ["open"]
lsp = ["tower-lsp", "tokio", "native_sys"]
native_sys = []
profile = ["serde_yaml", "indexmap"]
raw_mode = ["crossterm", "native_sys"]
raw_mode = ["rawrrr", "native_sys"]
stand = ["native_sys"]
terminal_image = ["viuer", "image"]

Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ fn main() {
}
});

// This makes sure the terminal's original mode flags are remembered when disabling raw mode
#[cfg(feature = "raw_mode")]
rawrrr::save_term();

if let Err(e) = run() {
println!("{}", e.report());
exit(1);
Expand Down Expand Up @@ -684,9 +688,7 @@ fn uiua_files() -> Vec<PathBuf> {
const WATCHING: &str = "watching for changes...";
fn print_watching() {
#[cfg(feature = "raw_mode")]
{
_ = crossterm::terminal::disable_raw_mode();
}
rawrrr::disable_raw();
eprint!("{}", WATCHING);
stderr().flush().unwrap();
}
Expand Down
12 changes: 4 additions & 8 deletions src/sys_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ impl SysBackend for NativeSys {

match b {
#[cfg(feature = "raw_mode")]
b'\r'
if crossterm::terminal::is_raw_mode_enabled().map_err(|e| e.to_string())? =>
{
break
}
b'\r' if rawrrr::is_raw() => break,
b'\r' => continue,
b'\n' | 3 => break,
b => buffer.push(b),
Expand All @@ -154,11 +150,11 @@ impl SysBackend for NativeSys {
#[cfg(feature = "raw_mode")]
fn set_raw_mode(&self, raw_mode: bool) -> Result<(), String> {
if raw_mode {
crossterm::terminal::enable_raw_mode()
rawrrr::enable_raw()
} else {
crossterm::terminal::disable_raw_mode()
rawrrr::disable_raw()
}
.map_err(|e| e.to_string())
Ok(())
}
fn var(&self, name: &str) -> Option<String> {
env::var(name).ok()
Expand Down

0 comments on commit 31d2638

Please sign in to comment.