Skip to content

Commit

Permalink
Merge pull request #102 from dimbleby/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
Stebalien authored Aug 3, 2020
2 parents 97da4f2 + 1e5991e commit dadf589
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ travis-ci = { repository = "Stebalien/term" }
appveyor = { repository = "Stebalien/term" }

[dependencies]
dirs = "2.0.1"
dirs = "3.0.1"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["consoleapi", "wincon", "handleapi", "fileapi"] }
Expand Down
37 changes: 16 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,32 +253,27 @@ pub type Result<T> = std::result::Result<T, Error>;

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use std::error::Error;
if let crate::Error::Io(ref e) = *self {
write!(f, "{}", e)
} else {
f.write_str(self.description())
}
}
}

impl std::error::Error for Error {
fn description(&self) -> &str {
use crate::Error::*;
match *self {
Io(ref io) => io.description(),
TerminfoParsing(ref e) => e.description(),
ParameterizedExpansion(ref e) => e.description(),
NotSupported => "operation not supported by the terminal",
TermUnset => "TERM environment variable unset, unable to detect a terminal",
TerminfoEntryNotFound => "could not find a terminfo entry for this terminal",
CursorDestinationInvalid => "could not move cursor to requested position",
ColorOutOfRange => "color not supported by the terminal",
__Nonexhaustive => "placeholder variant that shouldn't be used",
Io(ref io) => io.fmt(f),
TerminfoParsing(ref e) => e.fmt(f),
ParameterizedExpansion(ref e) => e.fmt(f),
NotSupported => f.write_str("operation not supported by the terminal"),
TermUnset => {
f.write_str("TERM environment variable unset, unable to detect a terminal")
}
TerminfoEntryNotFound => {
f.write_str("could not find a terminfo entry for this terminal")
}
CursorDestinationInvalid => f.write_str("could not move cursor to requested position"),
ColorOutOfRange => f.write_str("color not supported by the terminal"),
__Nonexhaustive => f.write_str("placeholder variant that shouldn't be used"),
}
}
}

fn cause(&self) -> Option<&dyn std::error::Error> {
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Error::Io(ref io) => Some(io),
Error::TerminfoParsing(ref e) => Some(e),
Expand Down
27 changes: 9 additions & 18 deletions src/terminfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,16 @@ pub enum Error {

impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
use std::error::Error;
match *self {
NotUtf8(e) => write!(f, "{}", e),
BadMagic(v) => write!(f, "bad magic number {:x} in terminfo header", v),
_ => f.write_str(self.description()),
ShortNames => f.write_str("no names exposed, need at least one"),
TooManyBools => f.write_str("more boolean properties than libterm knows about"),
TooManyNumbers => f.write_str("more number properties than libterm knows about"),
TooManyStrings => f.write_str("more string properties than libterm knows about"),
InvalidLength => f.write_str("invalid length field value, must be >= -1"),
NotUtf8(ref e) => e.fmt(f),
NamesMissingNull => f.write_str("names table missing NUL terminator"),
StringsMissingNull => f.write_str("string table missing NUL terminator"),
}
}
}
Expand All @@ -222,21 +227,7 @@ impl ::std::convert::From<::std::string::FromUtf8Error> for Error {
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
BadMagic(..) => "incorrect magic number at start of file",
ShortNames => "no names exposed, need at least one",
TooManyBools => "more boolean properties than libterm knows about",
TooManyNumbers => "more number properties than libterm knows about",
TooManyStrings => "more string properties than libterm knows about",
InvalidLength => "invalid length field value, must be >= -1",
NotUtf8(ref e) => e.description(),
NamesMissingNull => "names table missing NUL terminator",
StringsMissingNull => "string table missing NUL terminator",
}
}

fn cause(&self) -> Option<&dyn (::std::error::Error)> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
NotUtf8(ref e) => Some(e),
_ => None,
Expand Down
35 changes: 14 additions & 21 deletions src/terminfo/parm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,26 @@ pub enum Error {

impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
use std::error::Error;
f.write_str(self.description())
}
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
use self::Error::*;
match *self {
StackUnderflow => "not enough elements on the stack",
TypeMismatch => "type mismatch",
UnrecognizedFormatOption(_) => "unrecognized format option",
InvalidVariableName(_) => "invalid variable name",
InvalidParameterIndex(_) => "invalid parameter index",
MalformedCharacterConstant => "malformed character constant",
IntegerConstantOverflow => "integer constant computation overflowed",
MalformedIntegerConstant => "malformed integer constant",
FormatWidthOverflow => "format width constant computation overflowed",
FormatPrecisionOverflow => "format precision constant computation overflowed",
StackUnderflow => f.write_str("not enough elements on the stack"),
TypeMismatch => f.write_str("type mismatch"),
UnrecognizedFormatOption(_) => f.write_str("unrecognized format option"),
InvalidVariableName(_) => f.write_str("invalid variable name"),
InvalidParameterIndex(_) => f.write_str("invalid parameter index"),
MalformedCharacterConstant => f.write_str("malformed character constant"),
IntegerConstantOverflow => f.write_str("integer constant computation overflowed"),
MalformedIntegerConstant => f.write_str("malformed integer constant"),
FormatWidthOverflow => f.write_str("format width constant computation overflowed"),
FormatPrecisionOverflow => {
f.write_str("format precision constant computation overflowed")
}
}
}

fn cause(&self) -> Option<&dyn (::std::error::Error)> {
None
}
}

impl ::std::error::Error for Error {}

/// Container for static and dynamic variable arrays
#[derive(Default)]
pub struct Variables {
Expand Down

0 comments on commit dadf589

Please sign in to comment.