mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-27 07:34:27 +02:00
Update to newer version of crates
This commit is contained in:
parent
483d338493
commit
b7a7ae1a17
@ -17,19 +17,19 @@ path = "src/main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.10"
|
chrono = "0.4.10"
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
crossterm = "0.13"
|
crossterm = "0.14"
|
||||||
failure = "0.1.6"
|
failure = "0.1.6"
|
||||||
fern = "0.5"
|
fern = "0.5"
|
||||||
futures-timer = "0.3"
|
futures-timer = "0.3"
|
||||||
futures-preview = "0.3.0-alpha.18"
|
futures-preview = "0.3.0-alpha.18"
|
||||||
heim = "0.0.8"
|
heim = "0.0.8"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
rayon = "1.2"
|
rayon = "1.3"
|
||||||
regex = "1.3.1"
|
regex = "1.3.1"
|
||||||
sysinfo = "0.10"
|
sysinfo = "0.10"
|
||||||
tokio = "0.2.4"
|
tokio = "0.2.6"
|
||||||
winapi = "0.3"
|
winapi = "0.3"
|
||||||
tui = {version = "0.7", features = ["crossterm"], default-features = false }
|
tui = {version = "0.8", features = ["crossterm"], default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_cmd = "0.10"
|
assert_cmd = "0.10"
|
||||||
|
129
src/main.rs
129
src/main.rs
@ -6,11 +6,14 @@ extern crate clap;
|
|||||||
extern crate failure;
|
extern crate failure;
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
input::{input, InputEvent, KeyEvent, MouseButton, MouseEvent},
|
event::{self, Event as CEvent, KeyCode, KeyEvent, KeyModifiers, MouseEvent},
|
||||||
screen::AlternateScreen,
|
execute,
|
||||||
|
terminal::LeaveAlternateScreen,
|
||||||
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen},
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::stdout,
|
io::{stdout, Write},
|
||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
thread,
|
thread,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
@ -103,10 +106,12 @@ fn main() -> error::Result<()> {
|
|||||||
let mut app = app::App::new(show_average_cpu, temperature_type, update_rate_in_milliseconds as u64, use_dot);
|
let mut app = app::App::new(show_average_cpu, temperature_type, update_rate_in_milliseconds as u64, use_dot);
|
||||||
|
|
||||||
// Set up up tui and crossterm
|
// Set up up tui and crossterm
|
||||||
let screen = AlternateScreen::to_alternate(true)?;
|
let mut stdout = stdout();
|
||||||
let stdout = stdout();
|
enable_raw_mode()?;
|
||||||
|
execute!(stdout, EnterAlternateScreen)?;
|
||||||
|
|
||||||
|
let backend = CrosstermBackend::new(stdout);
|
||||||
|
|
||||||
let backend = CrosstermBackend::with_alternate_screen(stdout, screen)?;
|
|
||||||
let mut terminal = Terminal::new(backend)?;
|
let mut terminal = Terminal::new(backend)?;
|
||||||
terminal.hide_cursor()?;
|
terminal.hide_cursor()?;
|
||||||
terminal.clear()?;
|
terminal.clear()?;
|
||||||
@ -116,49 +121,19 @@ fn main() -> error::Result<()> {
|
|||||||
{
|
{
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let input = input();
|
|
||||||
input.enable_mouse_mode().unwrap();
|
|
||||||
let mut mouse_timer = Instant::now();
|
let mut mouse_timer = Instant::now();
|
||||||
let mut keyboard_timer = Instant::now();
|
let mut keyboard_timer = Instant::now();
|
||||||
|
|
||||||
// TODO: I don't like this... seems odd async doesn't work on linux (then again, sync didn't work on windows)
|
|
||||||
if cfg!(target_os = "linux") {
|
|
||||||
let reader = input.read_sync();
|
|
||||||
for event in reader {
|
|
||||||
match event {
|
|
||||||
InputEvent::Keyboard(key) => {
|
|
||||||
if Instant::now().duration_since(keyboard_timer).as_millis() >= 30 {
|
|
||||||
if tx.send(Event::KeyInput(key)).is_err() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
keyboard_timer = Instant::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
InputEvent::Mouse(mouse) => {
|
|
||||||
if Instant::now().duration_since(mouse_timer).as_millis() >= 30 {
|
|
||||||
if tx.send(Event::MouseInput(mouse)).is_err() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mouse_timer = Instant::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let mut reader = input.read_async();
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(event) = reader.next() {
|
if let Ok(event) = event::read() {
|
||||||
match event {
|
if let CEvent::Key(key) = event {
|
||||||
InputEvent::Keyboard(key) => {
|
|
||||||
if Instant::now().duration_since(keyboard_timer).as_millis() >= 30 {
|
if Instant::now().duration_since(keyboard_timer).as_millis() >= 30 {
|
||||||
if tx.send(Event::KeyInput(key)).is_err() {
|
if tx.send(Event::KeyInput(key)).is_err() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keyboard_timer = Instant::now();
|
keyboard_timer = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
} else if let CEvent::Mouse(mouse) = event {
|
||||||
InputEvent::Mouse(mouse) => {
|
|
||||||
if Instant::now().duration_since(mouse_timer).as_millis() >= 30 {
|
if Instant::now().duration_since(mouse_timer).as_millis() >= 30 {
|
||||||
if tx.send(Event::MouseInput(mouse)).is_err() {
|
if tx.send(Event::MouseInput(mouse)).is_err() {
|
||||||
return;
|
return;
|
||||||
@ -166,9 +141,6 @@ fn main() -> error::Result<()> {
|
|||||||
mouse_timer = Instant::now();
|
mouse_timer = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -213,26 +185,56 @@ fn main() -> error::Result<()> {
|
|||||||
if let Ok(recv) = rx.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) {
|
if let Ok(recv) = rx.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) {
|
||||||
match recv {
|
match recv {
|
||||||
Event::KeyInput(event) => {
|
Event::KeyInput(event) => {
|
||||||
|
if event.modifiers.is_empty() {
|
||||||
|
// If only a code, and no modifiers, don't bother...
|
||||||
|
match event.code {
|
||||||
|
KeyCode::Char('q') => break,
|
||||||
|
KeyCode::Char('h') => app.on_left(),
|
||||||
|
KeyCode::Char('l') => app.on_right(),
|
||||||
|
KeyCode::Char('k') => app.on_up(),
|
||||||
|
KeyCode::Char('j') => app.on_down(),
|
||||||
|
KeyCode::Up => app.decrement_position_count(),
|
||||||
|
KeyCode::Down => app.increment_position_count(),
|
||||||
|
KeyCode::Char(uncaught_char) => app.on_key(uncaught_char),
|
||||||
|
KeyCode::Esc => app.on_esc(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise, track the modifier as well...
|
||||||
match event {
|
match event {
|
||||||
KeyEvent::Ctrl('c') | KeyEvent::Char('q') => break,
|
KeyEvent {
|
||||||
KeyEvent::Char('h') | KeyEvent::CtrlLeft => app.on_left(),
|
modifiers: KeyModifiers::CONTROL,
|
||||||
KeyEvent::Char('l') | KeyEvent::CtrlRight => app.on_right(),
|
code: KeyCode::Char('c'),
|
||||||
KeyEvent::Char('k') | KeyEvent::CtrlUp => app.on_up(),
|
} => break,
|
||||||
KeyEvent::Char('j') | KeyEvent::CtrlDown => app.on_down(),
|
KeyEvent {
|
||||||
KeyEvent::Ctrl('r') => {
|
modifiers: KeyModifiers::CONTROL,
|
||||||
|
code: KeyCode::Left,
|
||||||
|
} => app.on_left(),
|
||||||
|
KeyEvent {
|
||||||
|
modifiers: KeyModifiers::CONTROL,
|
||||||
|
code: KeyCode::Right,
|
||||||
|
} => app.on_right(),
|
||||||
|
KeyEvent {
|
||||||
|
modifiers: KeyModifiers::CONTROL,
|
||||||
|
code: KeyCode::Up,
|
||||||
|
} => app.on_up(),
|
||||||
|
KeyEvent {
|
||||||
|
modifiers: KeyModifiers::CONTROL,
|
||||||
|
code: KeyCode::Down,
|
||||||
|
} => app.on_down(),
|
||||||
|
KeyEvent {
|
||||||
|
modifiers: KeyModifiers::CONTROL,
|
||||||
|
code: KeyCode::Char('r'),
|
||||||
|
} => {
|
||||||
while rtx.send(ResetEvent::Reset).is_err() {
|
while rtx.send(ResetEvent::Reset).is_err() {
|
||||||
debug!("Sent reset message.");
|
debug!("Sent reset message.");
|
||||||
}
|
}
|
||||||
debug!("Resetting begins...");
|
debug!("Resetting begins...");
|
||||||
app.reset();
|
app.reset();
|
||||||
}
|
}
|
||||||
KeyEvent::Up => app.decrement_position_count(),
|
|
||||||
KeyEvent::Down => app.increment_position_count(),
|
|
||||||
KeyEvent::Char(c) => app.on_key(c),
|
|
||||||
//KeyEvent::Enter => app.on_enter(),
|
|
||||||
KeyEvent::Esc => app.on_esc(),
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if app.to_be_resorted {
|
if app.to_be_resorted {
|
||||||
data_collection::processes::sort_processes(
|
data_collection::processes::sort_processes(
|
||||||
@ -245,17 +247,8 @@ fn main() -> error::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::MouseInput(event) => match event {
|
Event::MouseInput(event) => match event {
|
||||||
MouseEvent::Press(e, _x, _y) => match e {
|
MouseEvent::ScrollUp(_x, _y, _modifiers) => app.decrement_position_count(),
|
||||||
MouseButton::WheelUp => {
|
MouseEvent::ScrollDown(_x, _y, _modifiers) => app.increment_position_count(),
|
||||||
app.decrement_position_count();
|
|
||||||
}
|
|
||||||
MouseButton::WheelDown => {
|
|
||||||
app.increment_position_count();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
MouseEvent::Hold(_x, _y) => {}
|
|
||||||
MouseEvent::Release(_x, _y) => {}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
Event::Update(data) => {
|
Event::Update(data) => {
|
||||||
@ -289,12 +282,16 @@ fn main() -> error::Result<()> {
|
|||||||
}
|
}
|
||||||
// Draw!
|
// Draw!
|
||||||
if let Err(err) = canvas::draw_data(&mut terminal, &mut app, &canvas_data) {
|
if let Err(err) = canvas::draw_data(&mut terminal, &mut app, &canvas_data) {
|
||||||
input().disable_mouse_mode()?;
|
disable_raw_mode()?;
|
||||||
|
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
|
||||||
|
terminal.show_cursor()?;
|
||||||
error!("{}", err);
|
error!("{}", err);
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
input().disable_mouse_mode()?;
|
disable_raw_mode()?;
|
||||||
|
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
|
||||||
|
terminal.show_cursor()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user