output_vt100-0.1.2/.gitignore010064400017500001750000000000351343347205600142220ustar0000000000000000/target **/*.rs.bk Cargo.lockoutput_vt100-0.1.2/.gitlab-ci.yml010064400017500001750000000003151343347205600146670ustar0000000000000000stages: - build rust-latest: stage: build image: rust:latest script: - cargo build --verbose rust-nightly: stage: build image: rustlang/rust:nightly script: - cargo build --verbose output_vt100-0.1.2/Cargo.toml.orig010064400017500001750000000007421343347477600151410ustar0000000000000000[package] name = "output_vt100" version = "0.1.2" authors = ["Phuntsok Drak-pa "] edition = "2018" description = "Utility to activate escape codes in Windows' CMD and PowerShell" repository = "https://github.com/Phundrak/output-vt100-rs" keywords = ["vt100", "console", "ansi"] readme = "README.md" license = "MIT" categories = ["development-tools"] [dependencies] winapi = { version = "0.3.6", features = ["winuser", "winbase", "consoleapi", "processenv"] } output_vt100-0.1.2/Cargo.toml0000644000000017460000000000000113730ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "output_vt100" version = "0.1.2" authors = ["Phuntsok Drak-pa "] description = "Utility to activate escape codes in Windows' CMD and PowerShell" readme = "README.md" keywords = ["vt100", "console", "ansi"] categories = ["development-tools"] license = "MIT" repository = "https://github.com/Phundrak/output-vt100-rs" [dependencies.winapi] version = "0.3.6" features = ["winuser", "winbase", "consoleapi", "processenv"] output_vt100-0.1.2/LICENSE010064400017500001750000000021131343347207500132370ustar0000000000000000The MIT License (MIT) Copyright (c) 2016 rust-derive-builder contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. output_vt100-0.1.2/README.md010064400017500001750000000033461343347447700135320ustar0000000000000000[![crates.io](https://img.shields.io/crates/v/output_vt100.svg?style=flat)](https://crates.io/crates/output_vt100) [![Released API docs](https://docs.rs/output_vt100/badge.svg)](https://docs.rs/output_vt100) [![Downloads](https://img.shields.io/crates/d/output_vt100.svg?style=flat)](https://crates.io/crates/output_vt100) [![GPL-3.0 Licensed](https://img.shields.io/crates/l/output_vt100.svg?style=flat)](https://crates.io/crates/output_vt100) [![AppVeyor CI](https://img.shields.io/appveyor/ci/Phundrak/output-vt100-rs.svg?style=flat)](https://ci.appveyor.com/project/Phundrak/output-vt100-rs) [![pipeline status](http://labs.phundrak.fr/phundrak/output-vt100-rs/badges/master/pipeline.svg)](http://labs.phundrak.fr/phundrak/output-vt100-rs/commits/master) # Output-VT100 This simple crates allows developers to enable ANSI escape characters in Windows' console, be it CMD or PowerShell. Its usage is very simple, as shown below: ```rust extern crate output_vt100; fn main() { output_vt100::init(); println!("\x1b[31mThis text is red!\x1b[0m"); } ``` If you wish to ensure the `output_vt100::init()` function is only ran once, you can use the crate [ctor](https://crates.io/crates/ctor). Be aware though it might not be suited for every use case, as explained on the crate’s presentation. ```rust extern crate output_vt100; extern crate ctor; use ctor::*; #[ctor] fn init_term() { output_vt100::init(); } fn main() { println!("\x1b[31mThis text is red!\x1b[0m"); } ``` Not that init panics on error, if you do not wish to panic, use `output_vt100::try_init` which returns a `Result<(), ()>` # Acknowledgements A big thank you to [nbouteme](https://github.com/nbouteme) who helped me a lot during the development of this create. output_vt100-0.1.2/appveyor.yml010064400017500001750000000035561343347205600146350ustar0000000000000000# Appveyor configuration template for Rust using rustup for Rust installation # https://github.com/starkat99/appveyor-rust ## Operating System (VM environment) ## # Rust needs at least Visual Studio 2013 Appveyor OS for MSVC targets. os: Visual Studio 2015 ## Build Matrix ## environment: matrix: ### MSVC Toolchains ### # Stable 64-bit MSVC - channel: stable target: x86_64-pc-windows-msvc # Stable 32-bit MSVC - channel: stable target: i686-pc-windows-msvc # Beta 64-bit MSVC - channel: beta target: x86_64-pc-windows-msvc # Beta 32-bit MSVC - channel: beta target: i686-pc-windows-msvc # Nightly 64-bit MSVC - channel: nightly target: x86_64-pc-windows-msvc # Nightly 32-bit MSVC - channel: nightly target: i686-pc-windows-msvc ### GNU Toolchains ### # Stable 64-bit GNU - channel: stable target: x86_64-pc-windows-gnu # Stable 32-bit GNU - channel: stable target: i686-pc-windows-gnu # Beta 64-bit GNU - channel: beta target: x86_64-pc-windows-gnu # Beta 32-bit GNU - channel: beta target: i686-pc-windows-gnu # Nightly 64-bit GNU - channel: nightly target: x86_64-pc-windows-gnu # Nightly 32-bit GNU - channel: nightly target: i686-pc-windows-gnu ## Install Script ## install: - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - rustup-init -yv --default-toolchain %channel% --default-host %target% - set PATH=%PATH%;%USERPROFILE%\.cargo\bin - rustc -vV - cargo -vV ## Build Script ## # This prevents the "directory does not contain a project or solution file" # error. build: false # Uses 'cargo build' to build. AppVeyor cannot run tests on this crate as it # redirects the console's output, and its state then cannot be retrieved, let # alone modified. test_script: - cargo build --verbose %cargoflags% output_vt100-0.1.2/examples/red-hello.rs010064400017500001750000000001661343347205600162760ustar0000000000000000extern crate output_vt100; fn main() { output_vt100::init(); println!("\x1b[31mThis text is red!\x1b[0m"); } output_vt100-0.1.2/src/lib.rs010064400017500001750000000043771343347416400141540ustar0000000000000000//! # Output-VT100 //! //! When you write terminal-based crates, sometimes you might want to use the //! standard ANSI escaped characters, to display some colors, to display text //! as bold, italic or whatever. However, you’ve just discovered all your //! pretty displays that worked like a charm on Linux and Mac look terrible //! on Windows, because the escaped characters do not work. Rather, they are //! not activated by default. Then you discover you have to do system calls to //! Windows directly to activate them in order to get your beautiful text back. //! What a pain! //! And this is where this crate comes in action! Simply add it as a dependency //! for your own crate, and use it like this: //! ```rust //! extern crate output_vt100; //! //! fn main() { //! output_vt100::init(); //! println!("\x1b[31mThis text is red!\x1b[0m"); //! } //! ``` //! And that’s it! By calling it once, you have now activated PowerShell’s and //! CMD’s support for ANSI’s escaped characters on your Windows builds! And //! you can leave this line in your Unix builds too, it will simply do nothing. #[cfg(windows)] pub fn try_init() -> Result<(), ()> { use winapi::shared::minwindef::DWORD; use winapi::um::consoleapi::{GetConsoleMode, SetConsoleMode}; use winapi::um::processenv::GetStdHandle; use winapi::um::winbase::STD_OUTPUT_HANDLE; use winapi::um::wincon::{DISABLE_NEWLINE_AUTO_RETURN, ENABLE_VIRTUAL_TERMINAL_PROCESSING}; let console_out = unsafe { GetStdHandle(STD_OUTPUT_HANDLE) }; let mut state: DWORD = 0; let mut ret: Result<(), _> = Ok(()); unsafe { let mut e: DWORD = 0; if GetConsoleMode(console_out, &mut state) == 0 { ret = Err(()); } if ret.is_ok() { state |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; state &= !DISABLE_NEWLINE_AUTO_RETURN; if SetConsoleMode(console_out, state) == 0 { ret = Err(()); } } } return ret; } #[cfg(windows)] pub fn init() { assert_eq!(try_init().is_ok(), true); } #[cfg(not(windows))] pub fn try_init() -> Result<(), ()> { Ok(()) } #[cfg(not(windows))] pub fn init() { ; } #[cfg(test)] mod tests { #[test] fn activate_vt100() { crate::init(); } } output_vt100-0.1.2/.cargo_vcs_info.json0000644000000001120000000000000133570ustar00{ "git": { "sha1": "e2c13d11880cdf2d21696d1d7cdc9c8cffcb813b" } }