GithubHelp home page GithubHelp logo

rust-lang / ferris-says Goto Github PK

View Code? Open in Web Editor NEW
175.0 10.0 40.0 31 KB

A Rust flavored implementation of `cowsay`

Home Page: https://crates.io/crates/ferris-says

License: Apache License 2.0

Rust 100.00%

ferris-says's Introduction

Ferris Says

A library for printing out text with Ferris as the mascot!

Build requirements

You only need a stable version of the Rust compiler.

How to use the library

Put the following in your Cargo.toml:

[dependencies]
ferris-says = "0.2"

Then import the crate with:

extern crate ferris_says;

Example

The following bit of code will write the byte string to STDOUT

extern crate ferris_says;

use ferris_says::say;
use std::io::{ stdout, BufWriter };

fn main() {
    let out = b"Hello fellow Rustaceans!";
    let width = 24;

    let mut writer = BufWriter::new(stdout());
    say(out, width, &mut writer).unwrap();
}

This will print out this when run:

 __________________________
< Hello fellow Rustaceans! >
 --------------------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

How to use the binary

The binary version is called fsays and can be installed with cargo install:

cargo install fsays

It reads input from stdin and prints it out to the console.

fsays 'Hello fellow Rustaceans!'

This will print out this when run:

 __________________________
< Hello fellow Rustaceans! >
 --------------------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

A width can also be specified, if desired.

fsays --width 12 'Hello fellow Rustaceans!'

will result in the following output:

 ______________
/ Hello fellow \
\ Rustaceans!  /
 --------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

You can also use multiple files as input by using the -f/--files flag!

Contributing

See CONTRIBUTING.md for more information.

License

Licensed under either of

at your option.

Licensing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Credit

Original Ferris ASCII art by @Diggsey

ferris-says's People

Contributors

aleksanderkrauze avatar federicomenaquintero avatar horki avatar jmick414 avatar killercup avatar lf- avatar lra avatar marcospb19 avatar mgattozzi avatar mgeisler avatar nickretallack avatar y21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ferris-says's Issues

Typo in crates.io

Hi,
I'm very new to Rust, but I found a typo in crates.io page.

It says:

[dependencies]
ferris_says = "0.1"

but the correct is ferris-says, not ferris_says.

Thank you.

[Bug Report] Wrong line width when used with fortune

fsays failed to format long string when used with piped fortune.

└─(09:51:39 on wenqing ✹)──> fortune | fsays                                                                                                                                                          
 _________________________________________
/       My dear People.                         \
|       My dear Bagginses and Boffins, and my   |
| dear Tooks and Brandybucks,             |
| and Grubbs, and Chubbs, and Burrowses,  |
| and Hornblowers, and Bolgers,           |
| Bracegirdles, Goodbodies, Brockhouses   |
| and Proudfoots.  Also my good           |
| Sackville Bagginses that I welcome back |
| at last to Bag End.  Today is my        |
| one hundred and eleventh birthday: I am |
| eleventy-one today!"                    |
\               -- J. R. R. Tolkien                     /
 -----------------------------------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

Unexpected output from binary when input includes tabs

Whenever the input contains a tab character, it breaks the formatting of the text bubble (at least with the binary, I haven't tried the library).

For example, this is what I observe if it gets \thello, world as input:

$ printf '\thello, world' | fsays
 ______________
<       hello, world >
 --------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

I would expect the output to look more like this (with the text matching the bubble in size):

$ printf '\thello, world' | fsays
 __________________
<     hello, world >
 ------------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

I hit this issue because in my .bashrc I have the command fortune | cowsay, and I tried replacing cowsay with this crate, but fortune puts an output with tabs, which causes the output of fortune | fsays to be misformatted.

Example run wrong

enviroments: macOs 13 Ventura

% rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.65.0 (897e37553 2022-11-02)`

% cargo --version
cargo 1.65.0 (4bc8f24d3 2022-10-20)

run wrong with

  let out = b"Hello fellow Rustaceans!"; // now, type of out is '&[u8; 24]'
  say(input: &str)

image

cargon run get an error.

image

Separate the bin and lib targets

Saw some people griping that the Rust website is doing a disservice to Rust as a systems programming language because the example on the Getting Started section imports this crate, which fetches 98 MB of 25 different dependencies to build a "Hello World" app. For a result that can be achieved in every other programming language without dependencies. Most of those are coming from the Clap crate, which is only used by the binary. So splitting the library to a different Cargo workspace should stop the complaints.

Release new version and publish it to crates.io

#21 fixed unsoundness bug, but version on crates.io still uses old vulnerable code. Please release current code as a 0.2.2 and consider yanking affected versions.

Also I created #32 and #33, which (if accepted) should be released as 0.3 (since they break API).

[Question] missing Clippy

Confused 🦀 ...

  • added
[features]
clippy = []

to Cargo.toml

  • then, trying cargo run --features "clippy" (from #5), the output always... features... Ferris...

What am I missing?

The wrong number of displayed spaces when multibyte string is given

Expected output

--------------------
| 突然の死👻      |
--------------------
              \
               \
                  _~^~^~_
              \) /  o o  \ (/
                '_   -   _'
                / '-----' \

Actual output

--------------------
| 突然の死👻 |
--------------------
              \
               \
                  _~^~^~_
              \) /  o o  \ (/
                '_   -   _'
                / '-----' \

Step to reproduce

$ echo "突然の死👻" | fsays --width 16

Additional information

  • PHP provides a function mb_strwidth(), which calculates the width of multibyte strings. In this function, the width of an unicode character is assumed as follows:

    chars width
    U+0000 - U+0019 0
    U+0020 - U+1FFF 1
    U+2000 - U+FF60 2
    U+FF61 - U+FF9F 1
    U+FFA0 - 2

[Question] How could I update the package by command line?

Hey, guys! Hope you are doing well :)

I'm just playing with the package with the v0.2 and I'm trying to update it to v0.3.1.

I've already tried cargo update -p ferris-says but it doesn't work.

Any suggestion? Please and thank you :)

Unclear documentation for `max_width`

I was going through the rust startup documentation trying to learn the language and started messing around with the example hello world code.

If you use non ASCII characters then they may take up more space than just a single byte (in UTF-8).

The code documentation for the say method's max_width field says :

max_width is the maximum width of a line of text before it is wrapped

Which would imply that the code will wrap on the character and not on the number of bytes since the word text is used.

For example the following code:

fn main() {
    let stdout = stdout();
    let message = "🐢🐢🐢";
    // Three characters so the width should be 3
    let width = 3;

    let mut writer = BufWriter::new(stdout.lock());
    ferris_says::say(message.as_bytes(), width, &mut writer).unwrap();
}

produces:

 ____
/ 🐢 \
| 🐢 |
\ 🐢 /
 ----
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

While the expected result (to me) was:

 ________
< 🐢🐢🐢 >
 --------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

My proposal is to either change the code so that it would cut at the character instead of at the byte and/ or update the documentation.

Though then again this is a package just for fun so it isn't the end of the world if nothing changes.

Add additional speech modes

Optionally make it possible for Ferris to think (with o O bubbles) or to shout (by using / \ for the speech bubble), similar to what cowsay and cowthink do.

Add a changelog

We have no CHANGELOG which is not great if people want a slimmed down version of what fixes/features have gone in between versions.

Correct example for ferris_says on mac

The correct ferris_says for mac

refer below

extern crate ferris_says;

use ferris_says::say;
use std::io::{ stdout, BufWriter };

fn main() {
let width = 24;

let mut writer = BufWriter::new(stdout());
say("Hello fellow Rustaceans!", width, &mut writer).unwrap();

}

No output and program stuck when calling `fsays` without arguments

Hello,

Maybe I am using the binary in a wrong way..
If I call it without any arguments, nothing happens and it appears to be stuck.

I've looked a bit at the code because I was interested and the program appears to be stuck in the following section
at line 106 of main.rs

  let reader = BufReader::new(stdin.lock()).bytes().fold(
      Ok(Vec::new()),
      |a: Result<Vec<u8>>, b| {
          if let Ok(mut a) = a {
              a.push(b.chain_err(|| INPUT)?);
              Ok(a)
          } else {
              a
          }
      },
  )?;

I'm nowhere nearly experienced yet to know hat is happening here. I've printed a in the closure and it appears to fill some vector with everything I type, but it does not react to something like a newline. Do you have any idea what might cause this?

Also, is there a way to build the binary from the root of the crate in some way? I need to navigate into fsays to run cargo run , which builds the project binary in the root, but I can' t run cargo build --bin fsays from the root

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.