-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from sunfishcode/main
Update the API for I/O safety
- Loading branch information
Showing
4 changed files
with
62 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,19 @@ | ||
#[cfg(windows)] | ||
fn run() { | ||
use std::os::windows::io::RawHandle; | ||
use windows_sys::Win32::System::Console::{ | ||
GetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, | ||
}; | ||
|
||
let stdout = unsafe { GetStdHandle(STD_OUTPUT_HANDLE) } as RawHandle; | ||
println!( | ||
"Size from terminal_size_using_handle(stdout): {:?}", | ||
terminal_size::terminal_size_using_handle(stdout) | ||
); | ||
|
||
let stderr = unsafe { GetStdHandle(STD_ERROR_HANDLE) } as RawHandle; | ||
println!( | ||
"Size from terminal_size_using_handle(stderr): {:?}", | ||
terminal_size::terminal_size_using_handle(stderr) | ||
); | ||
|
||
let stdin = unsafe { GetStdHandle(STD_INPUT_HANDLE) } as RawHandle; | ||
fn main() { | ||
println!( | ||
"Size from terminal_size_using_handle(stdin): {:?}", | ||
terminal_size::terminal_size_using_handle(stdin) | ||
"Size from terminal_size(): {:?}", | ||
terminal_size::terminal_size() | ||
); | ||
} | ||
|
||
#[cfg(not(windows))] | ||
fn run() { | ||
use std::os::unix::io::AsRawFd; | ||
|
||
println!( | ||
"Size from terminal_size_using_fd(stdout): {:?}", | ||
terminal_size::terminal_size_using_fd(std::io::stdout().as_raw_fd()) | ||
"Size from terminal_size_of(stdout): {:?}", | ||
terminal_size::terminal_size_of(std::io::stdout()) | ||
); | ||
println!( | ||
"Size from terminal_size_using_fd(stderr): {:?}", | ||
terminal_size::terminal_size_using_fd(std::io::stderr().as_raw_fd()) | ||
"Size from terminal_size_of(stderr): {:?}", | ||
terminal_size::terminal_size_of(std::io::stderr()) | ||
); | ||
println!( | ||
"Size from terminal_size_using_fd(stdin): {:?}", | ||
terminal_size::terminal_size_using_fd(std::io::stdin().as_raw_fd()) | ||
); | ||
} | ||
|
||
fn main() { | ||
println!( | ||
"Size from terminal_size(): {:?}", | ||
terminal_size::terminal_size() | ||
"Size from terminal_size_of(stdin): {:?}", | ||
terminal_size::terminal_size_of(std::io::stdin()) | ||
); | ||
|
||
run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters