├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE ├── README.md ├── src └── lib.rs └── tests └── integration_test.rs /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target/ 3 | **/*.rs.bk 4 | Cargo.lock 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | rust: 3 | - stable 4 | - beta 5 | - nightly 6 | 7 | script: 8 | - cargo build --verbose --all 9 | - cargo test 10 | 11 | cache: cargo -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ferris_print" 3 | version = "0.1.0" 4 | authors = ["Kim Desrosiers "] 5 | license = "MIT" 6 | description = "A simple macro to print using ferris say." 7 | homepage = "https://github.com/kimond/ferris-print" 8 | repository = "https://github.com/kimond/ferris-print" 9 | readme = "README.md" 10 | 11 | keywords = ["print", "ferris", "say", "macro"] 12 | 13 | edition = '2018' 14 | 15 | [dependencies] 16 | ferris-says = "0.1.1" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Kim Desrosiers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ferris print 2 | ============ 3 | [![Build Status](https://travis-ci.org/kimond/ferris-print.svg?branch=master)](https://travis-ci.org/kimond/ferris-print) 4 | 5 | A simple macro to print using ferris say. 6 | 7 | ## Why? 8 | Sometime I am bored with the classic `println!`. But with `ferrisprint!` my output is more exciting. 9 | 10 | ## Instruction 11 | Put the following in you `Cargo.toml`: 12 | 13 | ```toml 14 | [dependencies] 15 | ferris_print = "0.1" 16 | ``` 17 | 18 | Then import the crate with: 19 | 20 | ```rust 21 | use ferris_print::ferrisprint; 22 | ``` 23 | 24 | ### Example 25 | 26 | ```rust 27 | use ferris_print::ferrisprint; 28 | 29 | fn main() { 30 | ferrisprint!("Hello world"); 31 | } 32 | ``` 33 | 34 | The code above will print out this: 35 | 36 | ```plain 37 | ---------------------------- 38 | | Hello world | 39 | ---------------------------- 40 | \ 41 | \ 42 | _~^~^~_ 43 | \) / o o \ (/ 44 | '_ - _' 45 | / '-----' \ 46 | ``` 47 | 48 | ## Credits 49 | * [@mgattozzi](https://github.com/mgattozzi) for [ferris-say](https://github.com/mgattozzi/ferris-says) 50 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use ferris_says; 2 | use std::io::Result as IoResult; 3 | 4 | pub fn say(input: &[u8], width: usize, writer: &mut W) -> IoResult<()> 5 | where W: std::io::Write { 6 | ferris_says::say(input, width, writer) 7 | } 8 | 9 | #[macro_export] 10 | macro_rules! ferrisprint { 11 | ($fmt:expr) => { 12 | { 13 | use std::io::{stdout, BufWriter}; 14 | let stdout = stdout(); 15 | let width = 24; 16 | let mut writer = BufWriter::new(stdout.lock()); 17 | $crate::say(concat!($fmt).as_bytes(), width, &mut writer).unwrap(); 18 | } 19 | }; 20 | ($fmt:expr, $($arg:tt)*) => { 21 | { 22 | use std::io::{stdout, BufWriter}; 23 | let stdout = stdout(); 24 | let width = 24; 25 | let mut writer = BufWriter::new(stdout.lock()); 26 | $crate::say(format!(concat!($fmt), $($arg)*).as_bytes(), width, &mut writer).unwrap(); 27 | } 28 | }; 29 | } 30 | 31 | #[cfg(test)] 32 | mod tests { 33 | #[test] 34 | fn ferrisprint_macro_works() { 35 | ferrisprint!("hola"); 36 | let str = "ok"; 37 | ferrisprint!("hey {}", &str); 38 | } 39 | 40 | #[test] 41 | fn ferrisprint_macro_works_with_multiple_arguments() { 42 | ferrisprint!("I am {} the {}", "ferris", "crab"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/integration_test.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate ferris_print; 3 | 4 | #[test] 5 | fn ferrisprint_macro_works() { 6 | ferrisprint!("I'm working well!"); 7 | } 8 | #[test] 9 | fn ferrisprint_macro_works_with_parameters() { 10 | ferrisprint!("I'm working well! {}", "again"); 11 | } 12 | --------------------------------------------------------------------------------