mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 00:00:05 +03: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::{
|
use ratatui::{
|
||||||
backend::CrosstermBackend,
|
backend::CrosstermBackend,
|
||||||
crossterm::{
|
crossterm::{
|
||||||
event::{self, Event, KeyCode, KeyEventKind},
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
ExecutableCommand,
|
QueueableCommand,
|
||||||
},
|
},
|
||||||
Terminal,
|
Terminal,
|
||||||
};
|
};
|
||||||
use std::io;
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use crate::app_state::AppState;
|
use crate::app_state::AppState;
|
||||||
|
|
||||||
|
@ -18,7 +18,10 @@ mod state;
|
||||||
|
|
||||||
pub fn list(app_state: &mut AppState) -> Result<()> {
|
pub fn list(app_state: &mut AppState) -> Result<()> {
|
||||||
let mut stdout = io::stdout().lock();
|
let mut stdout = io::stdout().lock();
|
||||||
stdout.execute(EnterAlternateScreen)?;
|
stdout
|
||||||
|
.queue(EnterAlternateScreen)?
|
||||||
|
.queue(EnableMouseCapture)?
|
||||||
|
.flush()?;
|
||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
|
|
||||||
let mut terminal = Terminal::new(CrosstermBackend::new(&mut stdout))?;
|
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))?;
|
terminal.try_draw(|frame| ui_state.draw(frame).map_err(io::Error::other))?;
|
||||||
|
|
||||||
let key = loop {
|
let key = loop {
|
||||||
match event::read()? {
|
match event::read().context("Failed to read terminal event")? {
|
||||||
Event::Key(key) => match key.kind {
|
Event::Key(key) => match key.kind {
|
||||||
KeyEventKind::Press | KeyEventKind::Repeat => break key,
|
KeyEventKind::Press | KeyEventKind::Repeat => break key,
|
||||||
KeyEventKind::Release => (),
|
KeyEventKind::Release => (),
|
||||||
|
@ -86,7 +89,10 @@ pub fn list(app_state: &mut AppState) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(terminal);
|
drop(terminal);
|
||||||
stdout.execute(LeaveAlternateScreen)?;
|
stdout
|
||||||
|
.queue(LeaveAlternateScreen)?
|
||||||
|
.queue(DisableMouseCapture)?
|
||||||
|
.flush()?;
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue