Skip to content

Commit

Permalink
Update to rust 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 authored and gierens committed Aug 29, 2023
1 parent 1afa971 commit d0893eb
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ansi_term"
description = "Library for ANSI terminal colours and styles (bold, underline)"

edition = "2018"
authors = [ "ogham@bsago.me", "Ryan Scheel (Havvy) <ryan.havvy@gmail.com>", "Josh Triplett <josh@joshtriplett.org>" ]
documentation = "https://docs.rs/ansi_term"
homepage = "https://github.com/ogham/rust-ansi-term"
Expand Down
20 changes: 9 additions & 11 deletions src/ansi.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use style::{Colour, Style};

use std::fmt;

use write::AnyWrite;
use crate::style::{Colour, Style};
use crate::write::AnyWrite;
use crate::difference::Difference;


// ---- generating ANSI codes ----
Expand Down Expand Up @@ -284,23 +284,21 @@ impl Colour {

impl fmt::Display for Prefix {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let f: &mut fmt::Write = f;
let f: &mut dyn fmt::Write = f;
self.0.write_prefix(f)
}
}


impl fmt::Display for Infix {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use difference::Difference;

match Difference::between(&self.0, &self.1) {
Difference::ExtraStyles(style) => {
let f: &mut fmt::Write = f;
let f: &mut dyn fmt::Write = f;
style.write_prefix(f)
},
Difference::Reset => {
let f: &mut fmt::Write = f;
let f: &mut dyn fmt::Write = f;
write!(f, "{}{}", RESET, self.1.prefix())
},
Difference::ResetHyperlink => {
Expand All @@ -317,7 +315,7 @@ impl fmt::Display for Infix {

impl fmt::Display for Suffix {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let f: &mut fmt::Write = f;
let f: &mut dyn fmt::Write = f;
self.0.write_suffix(f)
}
}
Expand All @@ -326,8 +324,8 @@ impl fmt::Display for Suffix {

#[cfg(test)]
mod test {
use style::Style;
use style::Colour::*;
use crate::style::Style;
use crate::style::Colour::*;

macro_rules! test {
($name: ident: $style: expr; $input: expr => $result: expr) => {
Expand Down
18 changes: 11 additions & 7 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use std::fmt;

use style::Style;
use crate::style::Style;

/// Styles have a special `Debug` implementation that only shows the fields that
/// are set. Fields that haven’t been touched aren’t included in the output.
///
/// This behaviour gets bypassed when using the alternate formatting mode
/// `format!("{:#?}")`.
///
/// use ansi_term::Colour::{Red, Blue};
/// assert_eq!("Style { fg(Red), on(Blue), bold, italic }",
/// format!("{:?}", Red.on(Blue).bold().italic()));
/// ```
/// use ansi_term::Colour::{Red, Blue};
///
/// assert_eq!(
/// "Style { fg(Red), on(Blue), bold, italic }",
/// format!("{:?}", Red.on(Blue).bold().italic())
/// );
/// ```
impl fmt::Debug for Style {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
if fmt.alternate() {
Expand Down Expand Up @@ -72,8 +77,8 @@ impl fmt::Debug for Style {

#[cfg(test)]
mod test {
use style::Colour::*;
use style::Style;
use crate::style::Colour::*;
use crate::style::Style;

fn style() -> Style {
Style::new()
Expand Down Expand Up @@ -102,7 +107,6 @@ mod test {

#[test]
fn long_and_detailed() {
extern crate regex;
let expected_debug = "Style { fg(Blue), bold }";
let expected_pretty_repat = r##"(?x)
Style\s+\{\s+
Expand Down
4 changes: 2 additions & 2 deletions src/difference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ impl Difference {
mod test {
use super::*;
use super::Difference::*;
use style::Colour::*;
use style::Style;
use crate::style::Colour::*;
use crate::style::Style;

fn style() -> Style {
Style::new()
Expand Down
20 changes: 10 additions & 10 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::fmt;
use std::io;
use std::ops::Deref;

use ansi::{RESET, RESET_HYPERLINK};
use difference::Difference;
use style::{Style, Colour};
use write::AnyWrite;
use crate::ansi::{RESET, RESET_HYPERLINK};
use crate::difference::Difference;
use crate::style::{Style, Colour};
use crate::write::AnyWrite;


/// An `ANSIGenericString` includes a generic string type and a `Style` to
Expand Down Expand Up @@ -198,7 +198,7 @@ impl Colour {

impl<'a> fmt::Display for ANSIString<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let w: &mut fmt::Write = f;
let w: &mut dyn fmt::Write = f;
self.write_to_any(w)
}
}
Expand All @@ -207,7 +207,7 @@ impl<'a> ANSIByteString<'a> {
/// Write an `ANSIByteString` to an `io::Write`. This writes the escape
/// sequences for the associated `Style` around the bytes.
pub fn write_to<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
let w: &mut io::Write = w;
let w: &mut dyn io::Write = w;
self.write_to_any(w)
}
}
Expand All @@ -226,7 +226,7 @@ where <S as ToOwned>::Owned: fmt::Debug, &'a S: AsRef<[u8]> {

impl<'a> fmt::Display for ANSIStrings<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let f: &mut fmt::Write = f;
let f: &mut dyn fmt::Write = f;
self.write_to_any(f)
}
}
Expand All @@ -236,7 +236,7 @@ impl<'a> ANSIByteStrings<'a> {
/// escape sequences for the associated `Style`s around each set of
/// bytes.
pub fn write_to<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
let w: &mut io::Write = w;
let w: &mut dyn io::Write = w;
self.write_to_any(w)
}
}
Expand Down Expand Up @@ -283,8 +283,8 @@ where <S as ToOwned>::Owned: fmt::Debug, &'a S: AsRef<[u8]> {
#[cfg(test)]
mod tests {
pub use super::super::ANSIStrings;
pub use style::Style;
pub use style::Colour::*;
pub use crate::style::Style;
pub use crate::style::Colour::*;

#[test]
fn no_control_codes_for_plain() {
Expand Down
20 changes: 7 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,34 +238,28 @@
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(unused_extern_crates, unused_qualifications)]

#[cfg(target_os="windows")]
extern crate winapi;
#[cfg(test)]
#[macro_use]
extern crate doc_comment;

#[cfg(test)]
doctest!("../README.md");
doc_comment::doctest!("../README.md");

mod ansi;
pub use ansi::{Prefix, Infix, Suffix};
pub use crate::ansi::{Prefix, Infix, Suffix};

mod style;
pub use style::{Colour, Style};
pub use crate::style::{Colour, Style};

/// Color is a type alias for `Colour`.
pub type Color = Colour;
pub use crate::Colour as Color;

mod difference;
mod display;
pub use display::*;
pub use crate::display::*;

mod write;

mod windows;
pub use windows::*;
pub use crate::windows::*;

mod util;
pub use util::*;
pub use crate::util::*;

mod debug;
7 changes: 4 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use display::*;
use std::ops::Deref;

use crate::display::*;

/// Return a substring of the given ANSIStrings sequence, while keeping the formatting.
pub fn sub_string<'a>(start: usize, len: usize, strs: &ANSIStrings<'a>) -> Vec<ANSIString<'static>> {
let mut vec = Vec::new();
Expand Down Expand Up @@ -56,8 +57,8 @@ pub fn unstyled_len(strs: &ANSIStrings) -> usize {

#[cfg(test)]
mod test {
use Colour::*;
use display::*;
use crate::Colour::*;
use crate::display::*;
use super::*;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub trait AnyWrite {
}


impl<'a> AnyWrite for fmt::Write + 'a {
impl<'a> AnyWrite for dyn fmt::Write + 'a {
type wstr = str;
type Error = fmt::Error;

Expand All @@ -26,7 +26,7 @@ impl<'a> AnyWrite for fmt::Write + 'a {
}


impl<'a> AnyWrite for io::Write + 'a {
impl<'a> AnyWrite for dyn io::Write + 'a {
type wstr = [u8];
type Error = io::Error;

Expand Down

0 comments on commit d0893eb

Please sign in to comment.