Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update crossterm to v0.10 #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 36 additions & 46 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ serde_json = "1.0.39"
serde_yaml = "0.8.8"
chrono = { version = "0.4.6", features = ["serde"] }
regex = "1.1.2"
crossterm = "0.8.2"
crossterm = "0.10"
lazy_static = "1.3.0"
textwrap = "0.11.0"
structopt = "0.2.15"
Expand Down
26 changes: 15 additions & 11 deletions src/renderer/interactive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::mpsc::Receiver;
use std::thread::{self, JoinHandle};
use std::time::{Duration, Instant};

use crossterm::{Crossterm, Screen, TerminalInput, InputEvent};
use crossterm::{Crossterm, AlternateScreen, InputEvent, RawScreen};

use crate::config::Config;
use crate::renderer::types::*;
Expand Down Expand Up @@ -41,25 +41,30 @@ pub enum InputAction {

pub fn interactive_renderer(config: Arc<Config>, rx: Receiver<LogEntry>) -> JoinHandle<()> {
thread::Builder::new().name("interactive".to_string()).spawn(move || {
let mut rs = Rc::new(RenderState::new(config));

let screen = Screen::default();
let alt = match screen.enable_alternate_modes(true) {
Ok(alternate) => alternate,
// can't drop _screen or we'll leave raw mode
let _screen = match RawScreen::into_raw_mode() {
Ok(screen) => screen,
Err(e) => {
eprintln!("error opening alternate mode: {:?}", e);
eprintln!("error opening raw mode: {:?}", e);
return;
}
};

let crossterm = Crossterm::from_screen(&alt.screen);
// we don't enable raw mode here via to_alternate(true) as it can mask the
// source of errors (opening alternate screen vs opening raw)
if let Err(e) = AlternateScreen::to_alternate(false) {
eprintln!("error opening alternate mode: {:?}", e);
return;
};

let crossterm = Crossterm::new();
let cursor = crossterm.cursor();
let terminal = crossterm.terminal();

let input = TerminalInput::from_output(&alt.screen.stdout);
let input = crossterm.input();

let mut stdin = input.read_async();

let mut rs = Rc::new(RenderState::new(config));
let mut last_render: Option<Instant> = None;
let (mut last_width, mut last_height) = (0, 0);
'outer: loop {
Expand Down Expand Up @@ -117,7 +122,6 @@ pub fn interactive_renderer(config: Arc<Config>, rx: Receiver<LogEntry>) -> Join
};

if dirty || force_refresh {
// TODO actually render
rs = log::render(rs.clone(), &terminal, &cursor).unwrap();
rs = bar::render(rs.clone(), &terminal, &cursor).unwrap();

Expand Down