mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-04 10:35:06 +02:00
Disable mouse in the list
This commit is contained in:
parent
2baa140615
commit
b678bd8ed2
20
src/list.rs
20
src/list.rs
@ -1,14 +1,14 @@
|
||||
use anyhow::Result;
|
||||
use anyhow::{Context, Result};
|
||||
use ratatui::{
|
||||
backend::CrosstermBackend,
|
||||
crossterm::{
|
||||
event::{self, Event, KeyCode, KeyEventKind},
|
||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
ExecutableCommand,
|
||||
QueueableCommand,
|
||||
},
|
||||
Terminal,
|
||||
};
|
||||
use std::io;
|
||||
use std::io::{self, Write};
|
||||
|
||||
use crate::app_state::AppState;
|
||||
|
||||
@ -18,7 +18,10 @@ mod state;
|
||||
|
||||
pub fn list(app_state: &mut AppState) -> Result<()> {
|
||||
let mut stdout = io::stdout().lock();
|
||||
stdout.execute(EnterAlternateScreen)?;
|
||||
stdout
|
||||
.queue(EnterAlternateScreen)?
|
||||
.queue(EnableMouseCapture)?
|
||||
.flush()?;
|
||||
enable_raw_mode()?;
|
||||
|
||||
let mut terminal = Terminal::new(CrosstermBackend::new(&mut stdout))?;
|
||||
@ -30,7 +33,7 @@ pub fn list(app_state: &mut AppState) -> Result<()> {
|
||||
terminal.try_draw(|frame| ui_state.draw(frame).map_err(io::Error::other))?;
|
||||
|
||||
let key = loop {
|
||||
match event::read()? {
|
||||
match event::read().context("Failed to read terminal event")? {
|
||||
Event::Key(key) => match key.kind {
|
||||
KeyEventKind::Press | KeyEventKind::Repeat => break key,
|
||||
KeyEventKind::Release => (),
|
||||
@ -86,7 +89,10 @@ pub fn list(app_state: &mut AppState) -> Result<()> {
|
||||
}
|
||||
|
||||
drop(terminal);
|
||||
stdout.execute(LeaveAlternateScreen)?;
|
||||
stdout
|
||||
.queue(LeaveAlternateScreen)?
|
||||
.queue(DisableMouseCapture)?
|
||||
.flush()?;
|
||||
disable_raw_mode()?;
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user