Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init fix #1

Merged
merged 6 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: rust

addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev

rust:
- beta
- stable

# load travis-cargo
before_script:
- |
pip install 'travis-cargo<0.2' --user &&
export PATH=$HOME/.local/bin:$PATH

script:
- |
travis-cargo build
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix build for non-Windows platforms

## [v0.2.0] - 2018-06-05
Removed `init()`. Instead, ANSI is automatically enabled the first time an ANSI string is crated.
Expand Down
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate itertools;
use ansi_term::{ANSIGenericString, Colour};
use difference::{Changeset, Difference};
use itertools::Itertools;
use std::{fmt, sync::Once};
use std::fmt;

fn red(s: &str) -> ANSIGenericString<str> {
Colour::Red.paint(s)
Expand All @@ -25,12 +25,18 @@ static NL_LEFT: &str = "\n<";
static RIGHT: &str = ">";
static NL_RIGHT: &str = "\n>";

#[cfg(windows)]
#[inline(always)]
fn enable_ansi() {
use std::sync::Once;

static ONCE: Once = Once::new();
ONCE.call_once(|| {ansi_term::enable_ansi_support().ok();});
}

#[cfg(not(windows))]
#[inline(always)]
fn enable_ansi() {
if cfg!(windows) {
static ONCE: Once = Once::new();
ONCE.call_once(|| {ansi_term::enable_ansi_support().ok();});
}
}

#[derive(Copy, Clone, Debug)]
Expand Down