Gate crossterm_winapi with cfg(windows) (#244)
This commit is contained in:
parent
3b444d077f
commit
4e1fe5a625
@ -28,5 +28,5 @@ script:
|
||||
- rustc --version
|
||||
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then cargo fmt --all -- --check; fi
|
||||
- cargo build
|
||||
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then cargo test --all -- --nocapture --test-threads 1; else cargo test --all --exclude crossterm_winapi -- --nocapture --test-threads 1; fi
|
||||
- cargo test --all -- --nocapture --test-threads 1
|
||||
- scripts/test-examples.sh
|
||||
|
@ -11,5 +11,8 @@ exclude = ["target", "Cargo.lock"]
|
||||
readme = "README.md"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version = "0.3.7", features = ["winbase","consoleapi","processenv", "handleapi"] }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
default-target = "x86_64-pc-windows-msvc"
|
||||
|
@ -1,7 +1,10 @@
|
||||
#[cfg(windows)]
|
||||
use std::io::Result;
|
||||
|
||||
#[cfg(windows)]
|
||||
use crossterm_winapi::{Console, ScreenBuffer};
|
||||
|
||||
#[cfg(windows)]
|
||||
fn set_background_color() -> Result<()> {
|
||||
// background value
|
||||
const BLUE_BACKGROUND: u16 = 0x0010;
|
||||
@ -23,6 +26,7 @@ fn set_background_color() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn set_foreground_color() -> Result<()> {
|
||||
// background value
|
||||
const BLUE_FOREGROUND: u16 = 0x0001;
|
||||
@ -48,7 +52,13 @@ fn set_foreground_color() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn main() -> Result<()> {
|
||||
set_background_color()?;
|
||||
set_foreground_color()
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn main() {
|
||||
println!("This example is for the Windows platform only.");
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
#[cfg(windows)]
|
||||
use std::io::Result;
|
||||
|
||||
#[cfg(windows)]
|
||||
use crossterm_winapi::ConsoleMode;
|
||||
|
||||
#[cfg(windows)]
|
||||
fn change_console_mode() -> Result<()> {
|
||||
let console_mode = ConsoleMode::new()?;
|
||||
|
||||
@ -12,6 +15,12 @@ fn change_console_mode() -> Result<()> {
|
||||
console_mode.set_mode(10)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn main() -> Result<()> {
|
||||
change_console_mode()
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn main() {
|
||||
println!("This example is for the Windows platform only.");
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
#[cfg(windows)]
|
||||
use std::io::Result;
|
||||
|
||||
#[cfg(windows)]
|
||||
use crossterm_winapi::{Handle, HandleType};
|
||||
|
||||
#[cfg(windows)]
|
||||
#[allow(unused_variables)]
|
||||
fn main() -> Result<()> {
|
||||
// see the description of the types to see what they do.
|
||||
@ -20,3 +23,8 @@ fn main() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn main() {
|
||||
println!("This example is for the Windows platform only.");
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[cfg(windows)]
|
||||
use std::io::Result;
|
||||
|
||||
#[cfg(windows)]
|
||||
use crossterm_winapi::ScreenBuffer;
|
||||
|
||||
#[cfg(windows)]
|
||||
fn print_screen_buffer_information() -> Result<()> {
|
||||
let screen_buffer = ScreenBuffer::current()?;
|
||||
|
||||
@ -18,6 +21,7 @@ fn print_screen_buffer_information() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn multiple_screen_buffers() -> Result<()> {
|
||||
// create new screen buffer
|
||||
let screen_buffer = ScreenBuffer::create();
|
||||
@ -26,6 +30,12 @@ fn multiple_screen_buffers() -> Result<()> {
|
||||
screen_buffer.show()
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn main() -> Result<()> {
|
||||
print_screen_buffer_information()
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn main() {
|
||||
println!("This example is for the Windows platform only.");
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#![cfg(windows)]
|
||||
#![deny(unused_imports)]
|
||||
|
||||
pub use self::{
|
||||
|
Loading…
Reference in New Issue
Block a user