Coder Social home page Coder Social logo

tmck-code / pokesay Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 3.0 148.78 MB

Print pokemon in the CLI! An adaptation of the classic "cowsay"

License: MIT License

Makefile 2.27% Shell 7.76% Dockerfile 2.77% Go 87.20%
golang bashrc cli dotfiles pokemon krabby pokemon-colorscripts pokemonsay pokemonshow pokeshell

pokesay's Introduction

pokesay

Print pokemon in the CLI! An adaptation of the classic "cowsay"

demo

Other docs


One-line installs

(These commands can also be used to update your existing pokesay)

  • OSX / darwin
    bash -c "$(curl https://raw.githubusercontent.com/tmck-code/pokesay/master/build/scripts/install.sh)" bash darwin amd64
  • OSX / darwin (M1)
    bash -c "$(curl https://raw.githubusercontent.com/tmck-code/pokesay/master/build/scripts/install.sh)" bash darwin arm64
  • Linux x64
    bash -c "$(curl https://raw.githubusercontent.com/tmck-code/pokesay/master/build/scripts/install.sh)" bash linux amd64
  • Android ARM64 (Termux)
    bash -c "$(curl https://raw.githubusercontent.com/tmck-code/pokesay/master/build/scripts/install.sh)" bash android arm64
  • Windows x64 (.exe)
    bash -c "$(curl https://raw.githubusercontent.com/tmck-code/pokesay/master/build/scripts/install.sh)" bash windows amd64

Usage

Just pipe some text! e.g.

echo yolo | pokesay

To see it every time you open a terminal, add it to your .bashrc file!
(This requires that you have fortune installed)

echo 'fortune | pokesay' >> $HOME/.bashrc

Note: The pokesay tool is intended to only be used with piped text input from STDIN, entering text by typing (or other methods) might not work as expected!

Full Usage

Run pokesay with -h or --help to see the full usage

Usage: pokesay [-bCfhjLlsuvW] [-c value] [-n value] [-t value] [-w value] [parameters ...]
 -b, --info-border  draw a border around the info box
 -c, --category=value
                    choose a pokemon from a specific category
 -C, --no-category-info
                    do not print pokemon category information in the info box
 -f, --fastest      run with the fastest possible configuration (--nowrap &
                    --notabspaces)
 -h, --help         display this help message
 -j, --japanese-name
                    print the japanese name in the info box
 -L, --list-categories
                    list all available categories
 -l, --list-names   list all available names
 -n, --name=value   choose a pokemon from a specific name
 -s, --no-tab-spaces
                    do not replace tab characters (fastest)
 -t, --tab-width=value
                    replace any tab characters with N spaces [4]
 -u, --unicode-borders
                    use unicode characters to draw the border around the speech
                    box (and info box if --info-border is enabled)
 -v, --verbose      print verbose output
 -W, --no-wrap      disable text wrapping (fastest)
 -w, --width=value  the max speech bubble width [80]

Examples

  • List all available categories
    pokesay -L
  • List all available names
    pokesay -l
  • Print a message with a random pokemon
    echo 'Hello, world!' | pokesay
  • Print a message with a specific pokemon
    echo 'Hello, world!' | pokesay -n pikachu
  • Print a message with a specific pokemon category
    # big pokemon (i.e. with a large dimensions in the terminal)
    echo 'Hello, world!' | pokesay -c big
    # shiny pokemon
    echo 'Hello, world!' | pokesay -c shiny
  • Print a message with a specific pokemon category and name
    # for shiny charizards
    echo 'Hello, world!' | pokesay -c shiny -n charizard

How it works

This project extends on the original fortune | cowsay, a simple command combo that can be added to your .bashrc to give you a random message spoken by a cow every time you open a new shell.

 ☯ ~ fortune | cowsay
 ______________________________________
/ Hollywood is where if you don't have \
| happiness you send out for it.       |
|                                      |
\ -- Rex Reed                          /
 --------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

As a personal project, this has been lovingly over-engineered with a focus on the lowest latency possible, so that it doesn't slow down your terminal experience.

  1. These pokemon sprites used here are sourced from the awesome repo msikma/pokesprite

    sprits

  2. All of these sprites are converted into a form that can be rendered in a terminal (unicode characters and colour control sequences) by the img2xterm tool, found at rossy/img2xterm

  3. Use some go tools (encoding/gob and go:embed) to generate a go source code file that encodes all of the converted unicode sprites as gzipped text and some search-optimised data structures.

  4. Finally, this is built with the main CLI logic in pokesay.go into an single executable that can be easily popped into a directory in the user's $PATH

If all you are after is installing the program to use, then there are no dependencies required! Navigate to the Releases and download the latest binary.


TODO

  • Short-term
    • optionally print ID assigned to each pokemon, support deterministic selection via the same ID
  • Longer-term
  • In Beta
    • support long and short cli args (e.g. --name/-n)
  • Completed
    • Make the category struct faster to load - currently takes up to 80% of the execution time
    • Store metadata and names in a more storage-efficient manner
    • Import japanese names from data/pokemon.json
    • Fix bad whitespace stripping when building assets
    • List all names
    • Make data structure to hold categories, names and pokemon
    • Increase speed
    • Improve categories to be more specific than shiny/regular
    • Filter by both name and category

Similar projects

There are many other projects that bring pokemon to the terminal! Check them out via the links.

Inspired by the pokeshell project, I've included a comparison table

project dependencies speed japanese names size categories selection by name selection by category animated sprites
pokeshell imagemagick, chafa ? ? ? ? ? ?
pokemon-icat python ? ? ? ? ? ?
pokemon-colorscripts python3 ? ? ? ? ? ?
pokemonsay-newgenerations cowsay (perl) ? ? ? ? ? ?
pokeTerm python3 ? ? ? ? ? ?
krabby rust, cargo ?
pokemonsay npm ? ? ? ? ? ?

pokesay's People

Contributors

humanfactors avatar tmck-code avatar

Stargazers

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

Watchers

 avatar  avatar

pokesay's Issues

Does not print pokemon, choice: unown-c

So I just ran the fortune | pokesay command a few times and then this showed up without any pokemon. Notice the "choice: unown-c".

This was on macOS with version 0.5.3.

➜ fortune | pokesay
/----------------------------------------------------------------------------------\
| [A computer is] like an Old Testament god, with a lot of rules and no mercy.      |
|         -- Joseph Campbell                                                        |
\----------------------------------------------------------------------------------/
         \
          \
           \
            \
choice: unown-c / categories: [PokemonGen7xRegularUnownCCow]

pokesay stalls without any inputs

I know it's kind of a silly edge case, but pokesay-windows-amd64 stalls without input (I haven't tested other builds). It appears it cannot break the loop in zone below until user manually escapes the standard input (C-z <return>), which results in the input being shown twice.

https://github.com/tmck-code/pokesay-go/blob/487afe9a85cc78f06c791c267f4fa842331844a0/cmd/pokesay.go#L38-L49

Although this is of course meant to have an input piped, I think it would be good to handle this case. In theory, we could have a more formally input handler, but that is totally overkill. Maybe documenting this would be easier...


See example below:

image

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.