Skip to content

Commit

Permalink
fix: attempt to fix termux raw mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Beastwick18 committed Aug 14, 2024
1 parent f4a5c47 commit ab45266
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
49 changes: 47 additions & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ nix = { version = "0.29.0", features = ["signal"] }
[target.'cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))'.dependencies]
arboard = { version = "3.4", default-features = false }

[target.'cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))'.dependencies]
ratatui = { version = "0.28.0", default-features = false, features = ["termion"] }

[package.metadata.deb]
maintainer = "Steven Culwell <[email protected]>"
copyright = "2024, Steven Culwell <[email protected]>"
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use config::{AppConfig, ConfigManager};
use ratatui::{backend::CrosstermBackend, Terminal};
use sync::AppSync;

#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
use ratatui::termion::raw::IntoRawMode;

pub mod app;
pub mod client;
pub mod clip;
Expand Down Expand Up @@ -58,7 +61,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let args = parse_args()?;
util::term::setup_terminal()?;

#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
let backend = CrosstermBackend::new(stdout());
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
let backend = CrosstermBackend::new(stdout().into_raw_mode()?);

let mut terminal = Terminal::new(backend)?;

let mut app = App::default();
Expand Down
21 changes: 16 additions & 5 deletions src/util/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,36 @@ use std::io::{self, stdout};
use crossterm::{
cursor::SetCursorStyle,
event::{DisableBracketedPaste, EnableBracketedPaste},
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
terminal::{disable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
ExecutableCommand as _,
};

#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
use crossterm::terminal::enable_raw_mode;

#[cfg(unix)]
use nix::{
sys::signal::{self, Signal},
unistd::Pid,
};
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
use ratatui::termion::raw::IntoRawMode;
#[cfg(unix)]
use ratatui::{backend::Backend, Terminal};
#[cfg(unix)]
use std::error::Error;

pub fn setup_terminal() -> io::Result<()> {
enable_raw_mode()?;
stdout().execute(EnableBracketedPaste)?;
stdout().execute(EnterAlternateScreen)?;
stdout().execute(SetCursorStyle::SteadyBar)?;
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
let out = &mut stdout().into_raw_mode()?;
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
let out = {
enable_raw_mode()?;
&mut stdout()
};
out.execute(EnableBracketedPaste)?;
out.execute(EnterAlternateScreen)?;
out.execute(SetCursorStyle::SteadyBar)?;
Ok(())
}

Expand Down

0 comments on commit ab45266

Please sign in to comment.