pokesay

command module
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 7 Imported by: 0

README

pokesay

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


pokesay demo


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]

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.


Building binaries

On your host OS

Dependencies: Go 1.19

You'll have to install a golang version that matches the go.mod, and ensure that other package dependencies are installed (see the dockerfile for the dependencies)

# Generate binary asset files from the cowfiles
./build/build_assets.sh

# Finally, build the pokesay tool
go build pokesay.go
In docker

Dependencies: docker

In order to re/build the binaries from scratch, along with all the cowfile conversion, use the handy Makefile tasks

make -C build build/docker build/assets build/release

This will produce 4 executable bin files inside the build/bin directory, and a heap of binary asset files in build/assets.


Developing

Testing

Run tests with

go test -v ./test/

# or, with debug information printed
DEBUG=test go test -v ./test/
Deploying
  1. Make a PR, and merge it into master
  2. Draft a new release https://github.com/tmck-code/pokesay/releases/new
  3. Give it a new tag and identical release title by incrementing the version
    1. Generate the release notes automatically
  4. Run make all (or some variation) locally to create the binaries under build/bin/
    1. Upload the bins to the release page
  5. Then click "Publish Release"! The install script downloads binaries from the most recently-published released

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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
src
bin
bin/convert command
bin/pokedex command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL