libterm => 2018
This commit is contained in:
parent
57d7cfc3cf
commit
0ce5129d05
6 changed files with 42 additions and 39 deletions
|
@ -2,6 +2,7 @@
|
||||||
authors = ["The Rust Project Developers"]
|
authors = ["The Rust Project Developers"]
|
||||||
name = "term"
|
name = "term"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "term"
|
name = "term"
|
||||||
|
|
|
@ -35,20 +35,20 @@
|
||||||
test(attr(deny(warnings))))]
|
test(attr(deny(warnings))))]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
|
#![deny(rust_2018_idioms)]
|
||||||
|
|
||||||
#![cfg_attr(windows, feature(libc))]
|
#![cfg_attr(windows, feature(libc))]
|
||||||
// Handle rustfmt skips
|
// Handle rustfmt skips
|
||||||
#![feature(custom_attribute)]
|
#![feature(custom_attribute)]
|
||||||
#![feature(nll)]
|
|
||||||
#![allow(unused_attributes)]
|
#![allow(unused_attributes)]
|
||||||
|
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
use std::io::{self, Stdout, Stderr};
|
||||||
|
|
||||||
pub use terminfo::TerminfoTerminal;
|
pub use terminfo::TerminfoTerminal;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub use win::WinConsole;
|
pub use win::WinConsole;
|
||||||
|
|
||||||
use std::io::{self, Stdout, Stderr};
|
|
||||||
|
|
||||||
pub mod terminfo;
|
pub mod terminfo;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|
|
@ -5,18 +5,16 @@ use std::env;
|
||||||
use std::error;
|
use std::error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::{self, prelude::*, BufReader};
|
||||||
use std::io;
|
|
||||||
use std::io::BufReader;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use Attr;
|
use crate::Attr;
|
||||||
use color;
|
use crate::color;
|
||||||
use Terminal;
|
use crate::Terminal;
|
||||||
use self::searcher::get_dbpath_for_term;
|
|
||||||
use self::parser::compiled::{parse, msys_terminfo};
|
|
||||||
use self::parm::{expand, Variables, Param};
|
|
||||||
|
|
||||||
|
use searcher::get_dbpath_for_term;
|
||||||
|
use parser::compiled::{parse, msys_terminfo};
|
||||||
|
use parm::{expand, Variables, Param};
|
||||||
|
|
||||||
/// A parsed terminfo database entry.
|
/// A parsed terminfo database entry.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -49,7 +47,7 @@ impl error::Error for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cause(&self) -> Option<&dyn error::Error> {
|
fn cause(&self) -> Option<&dyn error::Error> {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
match *self {
|
match *self {
|
||||||
IoError(ref e) => Some(e),
|
IoError(ref e) => Some(e),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -58,8 +56,8 @@ impl error::Error for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
use self::Error::*;
|
use Error::*;
|
||||||
match *self {
|
match *self {
|
||||||
TermUnset => Ok(()),
|
TermUnset => Ok(()),
|
||||||
MalformedTerminfo(ref e) => e.fmt(f),
|
MalformedTerminfo(ref e) => e.fmt(f),
|
||||||
|
|
|
@ -40,23 +40,27 @@ pub enum Param {
|
||||||
/// Container for static and dynamic variable arrays
|
/// Container for static and dynamic variable arrays
|
||||||
pub struct Variables {
|
pub struct Variables {
|
||||||
/// Static variables A-Z
|
/// Static variables A-Z
|
||||||
sta: [Param; 26],
|
sta_va: [Param; 26],
|
||||||
/// Dynamic variables a-z
|
/// Dynamic variables a-z
|
||||||
dyn: [Param; 26],
|
dyn_va: [Param; 26],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Variables {
|
impl Variables {
|
||||||
/// Return a new zero-initialized Variables
|
/// Return a new zero-initialized Variables
|
||||||
pub fn new() -> Variables {
|
pub fn new() -> Variables {
|
||||||
Variables {
|
Variables {
|
||||||
sta: [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), 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),
|
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),
|
||||||
|
Number(0), Number(0), Number(0), Number(0), Number(0)
|
||||||
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,14 +253,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
|
||||||
if cur >= 'A' && cur <= 'Z' {
|
if cur >= 'A' && cur <= 'Z' {
|
||||||
if let Some(arg) = stack.pop() {
|
if let Some(arg) = stack.pop() {
|
||||||
let idx = (cur as u8) - b'A';
|
let idx = (cur as u8) - b'A';
|
||||||
vars.sta[idx as usize] = arg;
|
vars.sta_va[idx as usize] = arg;
|
||||||
} else {
|
} else {
|
||||||
return Err("stack is empty".to_string());
|
return Err("stack is empty".to_string());
|
||||||
}
|
}
|
||||||
} else if cur >= 'a' && cur <= 'z' {
|
} else if cur >= 'a' && cur <= 'z' {
|
||||||
if let Some(arg) = stack.pop() {
|
if let Some(arg) = stack.pop() {
|
||||||
let idx = (cur as u8) - b'a';
|
let idx = (cur as u8) - b'a';
|
||||||
vars.dyn[idx as usize] = arg;
|
vars.dyn_va[idx as usize] = arg;
|
||||||
} else {
|
} else {
|
||||||
return Err("stack is empty".to_string());
|
return Err("stack is empty".to_string());
|
||||||
}
|
}
|
||||||
|
@ -267,10 +271,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec<
|
||||||
GetVar => {
|
GetVar => {
|
||||||
if cur >= 'A' && cur <= 'Z' {
|
if cur >= 'A' && cur <= 'Z' {
|
||||||
let idx = (cur as u8) - b'A';
|
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' {
|
} else if cur >= 'a' && cur <= 'z' {
|
||||||
let idx = (cur as u8) - b'a';
|
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 {
|
} else {
|
||||||
return Err("bad variable name in %g".to_string());
|
return Err("bad variable name in %g".to_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
//! ncurses-compatible compiled terminfo format parsing (term(5))
|
//! ncurses-compatible compiled terminfo format parsing (term(5))
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::io::prelude::*;
|
||||||
use super::super::TermInfo;
|
use super::super::TermInfo;
|
||||||
|
|
||||||
// These are the orders ncurses uses in its compiled format (as of 5.9). Not sure if portable.
|
// These are the orders ncurses uses in its compiled format (as of 5.9). Not sure if portable.
|
||||||
|
|
||||||
#[rustfmt_skip]
|
#[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",
|
"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",
|
"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",
|
"memory_below", "move_insert_mode", "move_standout_mode", "over_strike", "status_line_esc_ok",
|
||||||
|
@ -23,13 +23,13 @@ pub static boolfnames: &'static[&'static str] = &["auto_left_margin", "auto_righ
|
||||||
"return_does_clr_eol"];
|
"return_does_clr_eol"];
|
||||||
|
|
||||||
#[rustfmt_skip]
|
#[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",
|
"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",
|
"nxon", "mc5i", "chts", "nrrmc", "npc", "ndscr", "ccc", "bce", "hls", "xhpa", "crxm", "daisy",
|
||||||
"xvpa", "sam", "cpix", "lpix", "OTbs", "OTns", "OTnc", "OTMT", "OTNL", "OTpt", "OTxr"];
|
"xvpa", "sam", "cpix", "lpix", "OTbs", "OTns", "OTnc", "OTMT", "OTNL", "OTpt", "OTxr"];
|
||||||
|
|
||||||
#[rustfmt_skip]
|
#[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",
|
"lines_of_memory", "magic_cookie_glitch", "padding_baud_rate", "virtual_terminal",
|
||||||
"width_status_line", "num_labels", "label_height", "label_width", "max_attributes",
|
"width_status_line", "num_labels", "label_height", "label_width", "max_attributes",
|
||||||
"maximum_windows", "max_colors", "max_pairs", "no_color_video", "buffer_capacity",
|
"maximum_windows", "max_colors", "max_pairs", "no_color_video", "buffer_capacity",
|
||||||
|
@ -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"];
|
"new_line_delay", "backspace_delay", "horizontal_tab_delay", "number_of_function_keys"];
|
||||||
|
|
||||||
#[rustfmt_skip]
|
#[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",
|
"vt", "wsl", "nlab", "lh", "lw", "ma", "wnum", "colors", "pairs", "ncv", "bufsz", "spinv",
|
||||||
"spinh", "maddr", "mjump", "mcs", "mls", "npins", "orc", "orl", "orhi", "orvi", "cps", "widcs",
|
"spinh", "maddr", "mjump", "mcs", "mls", "npins", "orc", "orl", "orhi", "orvi", "cps", "widcs",
|
||||||
"btns", "bitwin", "bitype", "UTug", "OTdC", "OTdN", "OTdB", "OTdT", "OTkn"];
|
"btns", "bitwin", "bitype", "UTug", "OTdC", "OTdN", "OTdB", "OTdT", "OTkn"];
|
||||||
|
|
||||||
#[rustfmt_skip]
|
#[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",
|
"change_scroll_region", "clear_all_tabs", "clear_screen", "clr_eol", "clr_eos",
|
||||||
"column_address", "command_character", "cursor_address", "cursor_down", "cursor_home",
|
"column_address", "command_character", "cursor_address", "cursor_down", "cursor_home",
|
||||||
"cursor_invisible", "cursor_left", "cursor_mem_address", "cursor_normal", "cursor_right",
|
"cursor_invisible", "cursor_left", "cursor_mem_address", "cursor_normal", "cursor_right",
|
||||||
|
@ -120,7 +120,7 @@ pub static stringfnames: &'static[&'static str] = &[ "back_tab", "bell", "carria
|
||||||
"acs_plus", "memory_lock", "memory_unlock", "box_chars_1"];
|
"acs_plus", "memory_lock", "memory_unlock", "box_chars_1"];
|
||||||
|
|
||||||
#[rustfmt_skip]
|
#[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",
|
"_", "_", "hpa", "cmdch", "cup", "cud1", "home", "civis", "cub1", "mrcup", "cnorm", "cuf1",
|
||||||
"ll", "cuu1", "cvvis", "dch1", "dl1", "dsl", "hd", "smacs", "blink", "bold", "smcup", "smdc",
|
"ll", "cuu1", "cvvis", "dch1", "dl1", "dsl", "hd", "smacs", "blink", "bold", "smcup", "smdc",
|
||||||
"dim", "smir", "invis", "prot", "rev", "smso", "smul", "ech", "rmacs", "sgr0", "rmcup", "rmdc",
|
"dim", "smir", "invis", "prot", "rev", "smso", "smul", "ech", "rmacs", "sgr0", "rmcup", "rmdc",
|
||||||
|
|
|
@ -7,9 +7,9 @@ extern crate libc;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
use Attr;
|
use crate::Attr;
|
||||||
use color;
|
use crate::color;
|
||||||
use Terminal;
|
use crate::Terminal;
|
||||||
|
|
||||||
/// A Terminal implementation which uses the Win32 Console API.
|
/// A Terminal implementation which uses the Win32 Console API.
|
||||||
pub struct WinConsole<T> {
|
pub struct WinConsole<T> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue