Skip to content

Commit

Permalink
libterm => 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 11, 2019
1 parent 57d7cfc commit 0ce5129
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/libterm/Cargo.toml
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "term"
version = "0.0.0"
edition = "2018"

[lib]
name = "term"
Expand Down
6 changes: 3 additions & 3 deletions src/libterm/lib.rs
Expand Up @@ -35,20 +35,20 @@
test(attr(deny(warnings))))]
#![deny(missing_docs)]

#![deny(rust_2018_idioms)]

#![cfg_attr(windows, feature(libc))]
// Handle rustfmt skips
#![feature(custom_attribute)]
#![feature(nll)]
#![allow(unused_attributes)]

use std::io::prelude::*;
use std::io::{self, Stdout, Stderr};

pub use terminfo::TerminfoTerminal;
#[cfg(windows)]
pub use win::WinConsole;

use std::io::{self, Stdout, Stderr};

pub mod terminfo;

#[cfg(windows)]
Expand Down
22 changes: 10 additions & 12 deletions src/libterm/terminfo/mod.rs
Expand Up @@ -5,18 +5,16 @@ use std::env;
use std::error;
use std::fmt;
use std::fs::File;
use std::io::prelude::*;
use std::io;
use std::io::BufReader;
use std::io::{self, prelude::*, BufReader};
use std::path::Path;

use Attr;
use color;
use Terminal;
use self::searcher::get_dbpath_for_term;
use self::parser::compiled::{parse, msys_terminfo};
use self::parm::{expand, Variables, Param};
use crate::Attr;
use crate::color;
use crate::Terminal;

use searcher::get_dbpath_for_term;
use parser::compiled::{parse, msys_terminfo};
use parm::{expand, Variables, Param};

/// A parsed terminfo database entry.
#[derive(Debug)]
Expand Down Expand Up @@ -49,7 +47,7 @@ impl error::Error for Error {
}

fn cause(&self) -> Option<&dyn error::Error> {
use self::Error::*;
use Error::*;
match *self {
IoError(ref e) => Some(e),
_ => None,
Expand All @@ -58,8 +56,8 @@ impl error::Error for Error {
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use Error::*;
match *self {
TermUnset => Ok(()),
MalformedTerminfo(ref e) => e.fmt(f),
Expand Down
32 changes: 18 additions & 14 deletions src/libterm/terminfo/parm.rs
Expand Up @@ -40,23 +40,27 @@ pub enum Param {
/// Container for static and dynamic variable arrays
pub struct Variables {
/// Static variables A-Z
sta: [Param; 26],
sta_va: [Param; 26],
/// Dynamic variables a-z
dyn: [Param; 26],
dyn_va: [Param; 26],
}

impl Variables {
/// Return a new zero-initialized Variables
pub fn new() -> Variables {
Variables {
sta: [Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0)],
dyn: [Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0)],
sta_va: [
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0)
],
dyn_va: [
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0), Number(0), Number(0),
Number(0), Number(0), Number(0), Number(0), Number(0)
],
}
}
}
Expand Down Expand Up @@ -249,14 +253,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
if cur >= 'A' && cur <= 'Z' {
if let Some(arg) = stack.pop() {
let idx = (cur as u8) - b'A';
vars.sta[idx as usize] = arg;
vars.sta_va[idx as usize] = arg;
} else {
return Err("stack is empty".to_string());
}
} else if cur >= 'a' && cur <= 'z' {
if let Some(arg) = stack.pop() {
let idx = (cur as u8) - b'a';
vars.dyn[idx as usize] = arg;
vars.dyn_va[idx as usize] = arg;
} else {
return Err("stack is empty".to_string());
}
Expand All @@ -267,10 +271,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
GetVar => {
if cur >= 'A' && cur <= 'Z' {
let idx = (cur as u8) - b'A';
stack.push(vars.sta[idx as usize].clone());
stack.push(vars.sta_va[idx as usize].clone());
} else if cur >= 'a' && cur <= 'z' {
let idx = (cur as u8) - b'a';
stack.push(vars.dyn[idx as usize].clone());
stack.push(vars.dyn_va[idx as usize].clone());
} else {
return Err("bad variable name in %g".to_string());
}
Expand Down
14 changes: 7 additions & 7 deletions src/libterm/terminfo/parser/compiled.rs
Expand Up @@ -3,14 +3,14 @@
//! ncurses-compatible compiled terminfo format parsing (term(5))

use std::collections::HashMap;
use std::io::prelude::*;
use std::io;
use std::io::prelude::*;
use super::super::TermInfo;

// These are the orders ncurses uses in its compiled format (as of 5.9). Not sure if portable.

#[rustfmt_skip]
pub static boolfnames: &'static[&'static str] = &["auto_left_margin", "auto_right_margin",
pub static boolfnames: &[&str] = &["auto_left_margin", "auto_right_margin",
"no_esc_ctlc", "ceol_standout_glitch", "eat_newline_glitch", "erase_overstrike", "generic_type",
"hard_copy", "has_meta_key", "has_status_line", "insert_null_glitch", "memory_above",
"memory_below", "move_insert_mode", "move_standout_mode", "over_strike", "status_line_esc_ok",
Expand All @@ -23,13 +23,13 @@ pub static boolfnames: &'static[&'static str] = &["auto_left_margin", "auto_righ
"return_does_clr_eol"];

#[rustfmt_skip]
pub static boolnames: &'static[&'static str] = &["bw", "am", "xsb", "xhp", "xenl", "eo",
pub static boolnames: &[&str] = &["bw", "am", "xsb", "xhp", "xenl", "eo",
"gn", "hc", "km", "hs", "in", "db", "da", "mir", "msgr", "os", "eslok", "xt", "hz", "ul", "xon",
"nxon", "mc5i", "chts", "nrrmc", "npc", "ndscr", "ccc", "bce", "hls", "xhpa", "crxm", "daisy",
"xvpa", "sam", "cpix", "lpix", "OTbs", "OTns", "OTnc", "OTMT", "OTNL", "OTpt", "OTxr"];

#[rustfmt_skip]
pub static numfnames: &'static[&'static str] = &[ "columns", "init_tabs", "lines",
pub static numfnames: &[&str] = &[ "columns", "init_tabs", "lines",
"lines_of_memory", "magic_cookie_glitch", "padding_baud_rate", "virtual_terminal",
"width_status_line", "num_labels", "label_height", "label_width", "max_attributes",
"maximum_windows", "max_colors", "max_pairs", "no_color_video", "buffer_capacity",
Expand All @@ -40,13 +40,13 @@ pub static numfnames: &'static[&'static str] = &[ "columns", "init_tabs", "lines
"new_line_delay", "backspace_delay", "horizontal_tab_delay", "number_of_function_keys"];

#[rustfmt_skip]
pub static numnames: &'static[&'static str] = &[ "cols", "it", "lines", "lm", "xmc", "pb",
pub static numnames: &[&str] = &[ "cols", "it", "lines", "lm", "xmc", "pb",
"vt", "wsl", "nlab", "lh", "lw", "ma", "wnum", "colors", "pairs", "ncv", "bufsz", "spinv",
"spinh", "maddr", "mjump", "mcs", "mls", "npins", "orc", "orl", "orhi", "orvi", "cps", "widcs",
"btns", "bitwin", "bitype", "UTug", "OTdC", "OTdN", "OTdB", "OTdT", "OTkn"];

#[rustfmt_skip]
pub static stringfnames: &'static[&'static str] = &[ "back_tab", "bell", "carriage_return",
pub static stringfnames: &[&str] = &[ "back_tab", "bell", "carriage_return",
"change_scroll_region", "clear_all_tabs", "clear_screen", "clr_eol", "clr_eos",
"column_address", "command_character", "cursor_address", "cursor_down", "cursor_home",
"cursor_invisible", "cursor_left", "cursor_mem_address", "cursor_normal", "cursor_right",
Expand Down Expand Up @@ -120,7 +120,7 @@ pub static stringfnames: &'static[&'static str] = &[ "back_tab", "bell", "carria
"acs_plus", "memory_lock", "memory_unlock", "box_chars_1"];

#[rustfmt_skip]
pub static stringnames: &'static[&'static str] = &[ "cbt", "_", "cr", "csr", "tbc", "clear",
pub static stringnames: &[&str] = &[ "cbt", "_", "cr", "csr", "tbc", "clear",
"_", "_", "hpa", "cmdch", "cup", "cud1", "home", "civis", "cub1", "mrcup", "cnorm", "cuf1",
"ll", "cuu1", "cvvis", "dch1", "dl1", "dsl", "hd", "smacs", "blink", "bold", "smcup", "smdc",
"dim", "smir", "invis", "prot", "rev", "smso", "smul", "ech", "rmacs", "sgr0", "rmcup", "rmdc",
Expand Down
6 changes: 3 additions & 3 deletions src/libterm/win.rs
Expand Up @@ -7,9 +7,9 @@ extern crate libc;
use std::io;
use std::io::prelude::*;

use Attr;
use color;
use Terminal;
use crate::Attr;
use crate::color;
use crate::Terminal;

/// A Terminal implementation which uses the Win32 Console API.
pub struct WinConsole<T> {
Expand Down

0 comments on commit 0ce5129

Please sign in to comment.