added drop disable
This commit is contained in:
parent
cc55c190d8
commit
ce15004975
@ -19,6 +19,5 @@ use std::io::Write;
|
|||||||
use std::{thread,time};
|
use std::{thread,time};
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
terminal::raw_mode::print_wait_screen_on_alternate_window();
|
|
||||||
thread::sleep(time::Duration::from_millis(2000));
|
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ pub fn read_async_demo() {
|
|||||||
|
|
||||||
// get the next pressed key
|
// get the next pressed key
|
||||||
let pressed_key = stdin.next();
|
let pressed_key = stdin.next();
|
||||||
terminal.write(format!("\r{:?} <- Character pressed", pressed_key));
|
terminal.write(format!("{:?} <- Character pressed", pressed_key));
|
||||||
|
|
||||||
// check if pressed key is enter (\r)
|
// check if pressed key is enter (\r)
|
||||||
if let Some(Ok(b'\r')) = pressed_key {
|
if let Some(Ok(b'\r')) = pressed_key {
|
||||||
@ -123,7 +123,7 @@ pub fn async_reading_on_alternate_screen() {
|
|||||||
// get the next pressed key
|
// get the next pressed key
|
||||||
let pressed_key = stdin.next();
|
let pressed_key = stdin.next();
|
||||||
|
|
||||||
terminal.write(format!("\r{:?} <- Character pressed", pressed_key));
|
terminal.write(format!("{:?} <- Character pressed", pressed_key));
|
||||||
|
|
||||||
// check if pressed key is enter (\r)
|
// check if pressed key is enter (\r)
|
||||||
if let Some(Ok(b'\r')) = pressed_key {
|
if let Some(Ok(b'\r')) = pressed_key {
|
||||||
|
@ -45,6 +45,7 @@ pub struct Screen
|
|||||||
{
|
{
|
||||||
buffer: Vec<u8>,
|
buffer: Vec<u8>,
|
||||||
pub stdout: Arc<TerminalOutput>,
|
pub stdout: Arc<TerminalOutput>,
|
||||||
|
drop: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screen
|
impl Screen
|
||||||
@ -90,13 +91,19 @@ impl Screen
|
|||||||
self.stdout.write_buf(&self.buffer);
|
self.stdout.write_buf(&self.buffer);
|
||||||
self.stdout.flush()
|
self.stdout.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this will disable the drop which will cause raw modes not to be undone on drop of `Screen`.
|
||||||
|
pub fn disable_drop(&self)
|
||||||
|
{
|
||||||
|
self.drop = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TerminalOutput> for Screen
|
impl From<TerminalOutput> for Screen
|
||||||
{
|
{
|
||||||
/// Create an screen with the given `Stdout`
|
/// Create an screen with the given `Stdout`
|
||||||
fn from(stdout: TerminalOutput) -> Self {
|
fn from(stdout: TerminalOutput) -> Self {
|
||||||
return Screen { stdout: Arc::new(stdout), buffer: Vec::new() };
|
return Screen { stdout: Arc::new(stdout), buffer: Vec::new(), drop: true};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +111,7 @@ impl From<Arc<TerminalOutput>> for Screen
|
|||||||
{
|
{
|
||||||
/// Create an screen with the given 'Arc<Stdout>'
|
/// Create an screen with the given 'Arc<Stdout>'
|
||||||
fn from(stdout: Arc<TerminalOutput>) -> Self {
|
fn from(stdout: Arc<TerminalOutput>) -> Self {
|
||||||
return Screen { stdout: stdout, buffer: Vec::new() };
|
return Screen { stdout: stdout, buffer: Vec::new() drop: true};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +119,7 @@ impl Default for Screen
|
|||||||
{
|
{
|
||||||
/// Create an new screen which will not be in raw mode or alternate mode.
|
/// Create an new screen which will not be in raw mode or alternate mode.
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
return Screen { stdout: Arc::new(TerminalOutput::new(false)), buffer: Vec::new() };
|
return Screen { stdout: Arc::new(TerminalOutput::new(false)), buffer: Vec::new(), drop: true};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +127,7 @@ impl Drop for Screen
|
|||||||
{
|
{
|
||||||
/// If the current screen is in raw mode whe need to disable it when the instance goes out of scope.
|
/// If the current screen is in raw mode whe need to disable it when the instance goes out of scope.
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.stdout.is_in_raw_mode
|
if self.stdout.is_in_raw_mode && self.drop
|
||||||
{
|
{
|
||||||
RawScreen::disable_raw_modes();
|
RawScreen::disable_raw_modes();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user