b717d306c3
When you want to work with the 'alternate screen' you can call the following functions: terminal::from_screen etc. Which will give you an instance to the back of the module you are calling it in. So instead of: let color = color(Screen::default()); let cursor = cursor(Screen::default()); let input = input(Screen::default()); let terminal = terminal(Screen::default()); You can do: let color = color(); let cursor = cursor(); let input = input(); let terminal = terminal();
65 lines
1.5 KiB
Rust
65 lines
1.5 KiB
Rust
use modules::terminal::ansi_terminal::AnsiTerminal;
|
|
|
|
use modules::terminal::ITerminal;
|
|
|
|
use Screen;
|
|
|
|
/* ======================== WinApi =========================== */
|
|
#[cfg(windows)]
|
|
mod winapi_tests {
|
|
use modules::terminal::winapi_terminal::WinApiTerminal;
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn resize_winapi()
|
|
{
|
|
let screen = Screen::default();
|
|
let stdout = Some(&screen.stdout);
|
|
let terminal = WinApiTerminal::new();
|
|
|
|
terminal.set_size(10, 10, &stdout);
|
|
|
|
let (x, y) = terminal.terminal_size(&stdout);
|
|
|
|
assert_eq!(x, 10);
|
|
assert_eq!(y, 10);
|
|
}
|
|
}
|
|
|
|
/* ======================== ANSI =========================== */
|
|
#[test]
|
|
fn resize_ansi()
|
|
{
|
|
use std::{thread, time};
|
|
if try_enable_ansi() {
|
|
let screen = Screen::default();
|
|
let stdout = Some(&screen.stdout);
|
|
let terminal = AnsiTerminal::new();
|
|
|
|
terminal.set_size(50,50, &stdout);
|
|
|
|
// see issue: https://github.com/eminence/terminal-size/issues/11
|
|
thread::sleep(time::Duration::from_millis(30));
|
|
|
|
let (x, y) = terminal.terminal_size(&stdout);
|
|
|
|
assert_eq!(x, 50);
|
|
assert_eq!(y, 50);
|
|
}
|
|
}
|
|
|
|
fn try_enable_ansi() -> bool
|
|
{
|
|
#[cfg(windows)]
|
|
{
|
|
if cfg!(target_os = "windows") {
|
|
use kernel::windows_kernel::ansi_support::try_enable_ansi_support;
|
|
|
|
if !try_enable_ansi_support()
|
|
{ return false; }
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|