Switch from usize to u16 in terminal_size
This commit is contained in:
parent
451cb95ee2
commit
119cbda718
|
@ -3,17 +3,17 @@ extern crate termion;
|
||||||
use termion::{TermWrite, Color, Style};
|
use termion::{TermWrite, Color, Style};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
const LINE_NUM_BG: Color = Color::Grayscale(5);
|
const LINE_NUM_BG: Color = Color::Grayscale(3);
|
||||||
const LINE_NUM_FG: Color = Color::Grayscale(18);
|
const LINE_NUM_FG: Color = Color::Grayscale(18);
|
||||||
const ERROR_FG: Color = Color::Grayscale(17);
|
const ERROR_FG: Color = Color::Grayscale(17);
|
||||||
const INFO_LINE: &'static str = "│ ";
|
const INFO_LINE: &'static str = "| ";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let stdout = io::stdout();
|
let stdout = io::stdout();
|
||||||
let mut stdout = stdout.lock();
|
let mut stdout = stdout.lock();
|
||||||
|
|
||||||
stdout.color(Color::LightGreen).unwrap();
|
stdout.color(Color::LightGreen).unwrap();
|
||||||
stdout.write("—— src/test/ui/borrow-errors.rs at 82:18 ——\n".as_bytes()).unwrap();
|
stdout.write("-- src/test/ui/borrow-errors.rs at 82:18 --\n".as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
|
|
||||||
stdout.color(Color::Red).unwrap();
|
stdout.color(Color::Red).unwrap();
|
||||||
|
@ -42,7 +42,7 @@ fn main() {
|
||||||
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
stdout.color(Color::Red).unwrap();
|
stdout.color(Color::Red).unwrap();
|
||||||
stdout.write(" ━━━ ".as_bytes()).unwrap();
|
stdout.write(" ^^^ ".as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
|
|
||||||
stdout.color(ERROR_FG).unwrap();
|
stdout.color(ERROR_FG).unwrap();
|
||||||
|
@ -61,7 +61,7 @@ fn main() {
|
||||||
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
stdout.color(Color::Red).unwrap();
|
stdout.color(Color::Red).unwrap();
|
||||||
stdout.write(" ━━━ ".as_bytes()).unwrap();
|
stdout.write(" ^^^ ".as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
|
|
||||||
stdout.color(ERROR_FG).unwrap();
|
stdout.color(ERROR_FG).unwrap();
|
||||||
|
@ -85,7 +85,7 @@ fn main() {
|
||||||
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
stdout.color(Color::Red).unwrap();
|
stdout.color(Color::Red).unwrap();
|
||||||
stdout.write(" ━━━ ".as_bytes()).unwrap();
|
stdout.write(" ^^^ ".as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
|
|
||||||
stdout.color(ERROR_FG).unwrap();
|
stdout.color(ERROR_FG).unwrap();
|
||||||
|
@ -104,7 +104,7 @@ fn main() {
|
||||||
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
stdout.color(Color::Red).unwrap();
|
stdout.color(Color::Red).unwrap();
|
||||||
stdout.write(" ━━━ ".as_bytes()).unwrap();
|
stdout.write(" ^^^ ".as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
|
|
||||||
stdout.color(ERROR_FG).unwrap();
|
stdout.color(ERROR_FG).unwrap();
|
||||||
|
@ -128,7 +128,7 @@ fn main() {
|
||||||
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
stdout.write(INFO_LINE.as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
stdout.color(Color::Red).unwrap();
|
stdout.color(Color::Red).unwrap();
|
||||||
stdout.write(" ━ ".as_bytes()).unwrap();
|
stdout.write(" ^ ".as_bytes()).unwrap();
|
||||||
stdout.reset().unwrap();
|
stdout.reset().unwrap();
|
||||||
|
|
||||||
stdout.color(ERROR_FG).unwrap();
|
stdout.color(ERROR_FG).unwrap();
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn tiocgwinsz() -> u32 {
|
||||||
|
|
||||||
/// Get the size of the terminal.
|
/// Get the size of the terminal.
|
||||||
#[cfg(not(target_os = "redox"))]
|
#[cfg(not(target_os = "redox"))]
|
||||||
pub fn terminal_size() -> io::Result<(usize, usize)> {
|
pub fn terminal_size() -> io::Result<(u16, u16)> {
|
||||||
use libc::ioctl;
|
use libc::ioctl;
|
||||||
use libc::STDOUT_FILENO;
|
use libc::STDOUT_FILENO;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ pub fn terminal_size() -> io::Result<(usize, usize)> {
|
||||||
let mut size: TermSize = mem::zeroed();
|
let mut size: TermSize = mem::zeroed();
|
||||||
|
|
||||||
if ioctl(STDOUT_FILENO, tiocgwinsz(), &mut size as *mut _) == 0 {
|
if ioctl(STDOUT_FILENO, tiocgwinsz(), &mut size as *mut _) == 0 {
|
||||||
Ok((size.col as usize, size.row as usize))
|
Ok((size.col as u16, size.row as u16))
|
||||||
} else {
|
} else {
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "Unable to get the terminal size."))
|
Err(io::Error::new(io::ErrorKind::Other, "Unable to get the terminal size."))
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ pub fn terminal_size() -> io::Result<(usize, usize)> {
|
||||||
|
|
||||||
/// Get the size of the terminal.
|
/// Get the size of the terminal.
|
||||||
#[cfg(target_os = "redox")]
|
#[cfg(target_os = "redox")]
|
||||||
pub fn terminal_size() -> io::Result<(usize, usize)> {
|
pub fn terminal_size() -> io::Result<(u16, u16)> {
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
let width = try!(env::var("COLUMNS").map_err(|x| io::Error::new(io::ErrorKind::NotFound, x))).parse().unwrap_or(0);
|
let width = try!(env::var("COLUMNS").map_err(|x| io::Error::new(io::ErrorKind::NotFound, x))).parse().unwrap_or(0);
|
||||||
|
|
Loading…
Reference in New Issue