diff --git a/COPYING b/COPYING index 9dbbef9..c749fa1 100644 --- a/COPYING +++ b/COPYING @@ -1,7 +1,7 @@ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 - Copyright (C) 2012 Sven-Hendrik Haase, Jan Alexander Steffens and Erkin Batu Altunbaş + Copyright (C) 2012 Erkin Batu Altunbaş Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..79a4281 --- /dev/null +++ b/CREDITS @@ -0,0 +1,16 @@ +# Pretty much all the contributors in alphabetic order. + +# Active developers +Erkin Batu Altunbaş +Mattias Andrée +Sven-Hendrik Haase +Jan Alexander Steffens + +# Patchers and other contributors +Duane Bekaert +Elis +James Ross-Gowan +Jannis +Kyah Rindlisbacher +Louis Taylor +Pablo Lezaeta diff --git a/DEPENDENCIES b/DEPENDENCIES new file mode 100644 index 0000000..c8b1eef --- /dev/null +++ b/DEPENDENCIES @@ -0,0 +1,41 @@ +REQUIRED dependencies: + +bash: required for the main script [file: ponysay] + +cowsay: this is a wrapper for cowsay + +coreutils: the main script [file: ponysay] uses stty, cut, ls, cat, head and tail + +sed: used to remove .pony from pony named when running ponysay -l + + + +OPTIONAL dependencies: + +(none) + + + +PONY PROVIDER dependencies: + +make: required to run `make ttyponies` + +coreutils: ln and readlink are used in ttyponies.sh + +bash: required to run ttyponies.sh + +util-say: used by ttyponies.sh to builder ttyponies from xterm ponies +# Available for Arch:ers in AUR as util-say-git are on github at https://github.com/maandree/util-say + + + +MAKE dependencies: + +gcc: used for compiling ponysaytruncater.c + +gzip: used for compressing manpages + +make: required to run the make script + +coreutils: make script uses install unlink rm ln mkdir cp + diff --git a/Makefile b/Makefile index 6a6e8dc..598767d 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,61 @@ -install: - gcc -o ponysaytruncater ponysaytruncater.c - mkdir -p $(DESTDIR)/usr/share/ponies - mkdir -p $(DESTDIR)/usr/share/ttyponies - cp -r ponies/*.pony $(DESTDIR)/usr/share/ponies/ - cp -r ttyponies/*.pony $(DESTDIR)/usr/share/ttyponies/ - install -Dm755 ponysay $(DESTDIR)/usr/bin/ponysay - install -Dm755 ponysaytruncater $(DESTDIR)/usr/bin/ponysaytruncater - ln -sf ponysay $(DESTDIR)/usr/bin/ponythink +all: ponysaytruncater manpages + +ponysaytruncater: + gcc -o "ponysaytruncater" "ponysaytruncater.c" + +manpages: + gzip -9 < manuals/manpage.6 > manuals/manpage.6.gz + gzip -9 < manuals/manpage.es.6 > manuals/manpage.es.6.gz + +ttyponies: + mkdir -p ttyponies + ./ttyponies.sh + +install: all + mkdir -p "$(DESTDIR)/usr/share/ponysay/" + mkdir -p "$(DESTDIR)/usr/share/ponysay/ponies" + mkdir -p "$(DESTDIR)/usr/share/ponysay/ttyponies" + cp ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/" + cp ttyponies/*.pony "$(DESTDIR)/usr/share/ponysay/ttyponies/" + + mkdir -p "$(DESTDIR)/usr/bin/" + install "ponysay" "$(DESTDIR)/usr/bin/ponysay" + install -s "ponysaytruncater" "$(DESTDIR)/usr/bin/ponysaytruncater" + ln -sf "ponysay" "$(DESTDIR)/usr/bin/ponythink" + + mkdir -p "$(DESTDIR)/usr/share/zsh/site-functions/" + install "completion/zsh-completion.zsh" "$(DESTDIR)/usr/share/zsh/site-functions/_ponysay" + + mkdir -p "$(DESTDIR)/usr/share/bash-completion/completions/" + install "completion/bash-completion.sh" "$(DESTDIR)/usr/share/bash-completion/completions/ponysay" + + mkdir -p "$(DESTDIR)/usr/share/licenses/ponysay/" + install "COPYING" "$(DESTDIR)/usr/share/licenses/ponysay/COPYING" + + mkdir -p "$(DESTDIR)/usr/share/man/man6" + install "manuals/manpage.6.gz" "$(DESTDIR)/usr/share/man/man6/ponysay.6.gz" + ln -sf "ponysay.6.gz" "$(DESTDIR)/usr/share/man/man6/ponythink.6.gz" + + mkdir -p "$(DESTDIR)/usr/share/man/es/man6" + install "manuals/manpage.es.6.gz" "$(DESTDIR)/usr/share/man/es/man6/ponysay.6.gz" + ln -sf "ponysay.6.gz" "$(DESTDIR)/usr/share/man/es/man6/ponythink.6.gz" uninstall: - rm -fr $(DESTDIR)/usr/share/ponies -# cp -r ponies/*.pony $(DESTDIR)/usr/share/ponies/ - rm -fr $(DESTDIR)/usr/share/ttyponies -# cp -r ttyponies/*.pony $(DESTDIR)/usr/share/ttyponies/ - rm -f $(DESTDIR)/usr/bin/ponysay - rm -f $(DESTDIR)/usr/bin/ponysaytruncater - unlink $(DESTDIR)/usr/bin/ponythink + rm -fr "$(DESTDIR)/usr/share/ponysay/ponies" + rm -fr "$(DESTDIR)/usr/share/ponysay/ttyponies" + unlink "$(DESTDIR)/usr/bin/ponysay" + unlink "$(DESTDIR)/usr/bin/ponysaytruncater" + unlink "$(DESTDIR)/usr/bin/ponythink" + unlink "$(DESTDIR)/usr/share/zsh/site-functions/_ponysay"; + unlink "$(DESTDIR)/usr/share/licenses/ponysay/COPYING" + unlink "$(DESTDIR)/usr/share/bash-completion/completions/ponysay" + unlink "$(DESTDIR)/usr/share/man/man6/ponysay.6.gz" + unlink "$(DESTDIR)/usr/share/man/man6/ponythink.6.gz" + unlink "$(DESTDIR)/usr/share/man/es/man6/ponysay.6.gz" + unlink "$(DESTDIR)/usr/share/man/es/man6/ponythink.6.gz" + +clean: + rm -f "ponysaytruncater" + rm manuals/manpage.6.gz + rm manuals/manpage.es.6.gz + diff --git a/README.md b/README.md index c7f85b2..d4983c1 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,23 @@ -`ponysay` - A cowsay wrapper with ponies. - -The pony files are [desktop/browser ponies](http://web.student.tuwien.ac.at/~e0427417/browser-ponies/ponies.html) converted using [img2xterm](https://github.com/rossy2401/img2xterm). +`ponysay` - A cowsay wrapper for ponies. ![Derp](http://i.imgur.com/xOJbE.png) + Today your terminal, tomorrow the world! Installation on Linux (or other Unix) ------------------------------------- -If you do not already have `cowsay` you will need to install it +First of all, you need `cowsay` from your local repositories. +Obtain it from [here](http://www.nog.net/~tony/warez/cowsay.shtml) if you wish to compile it yourself. - apt-get install cowsay # assuming dpkg +[Download](https://github.com/erkin/ponysay/downloads) or clone the project. +In the terminal, `cd` into the ponysay directory and `make install`. -[Download](https://github.com/erkin/ponysay/downloads) the latest project. In the terminal, `cd` into the ponysay directory and run - - sudo make +This will install ponysay into the $PREFIX (`/usr` by default, meaning you may need to make as root). -This will install ponysay into the $PREFIX (`/usr` by default). In order to use ponysay, run +In order to use ponysay, run: - ponysay "I am just the cutest pony" + ponysay "I am just the cutest pony!" Or if you have a specific pony in your mind: @@ -26,12 +25,10 @@ Or if you have a specific pony in your mind: ### Pony fortune on terminal startup -This requires that you have the `fortune` utility installed +This requires that you have the `fortune` utility installed. You can install it from your repositories or just fetch the source code from [here](ftp://ftp.ibiblio.org/pub/linux/games/amusements/fortune/). + +You can try [this](http://www.reddit.com/r/mylittlelinux/comments/srixi/using_ponysay_with_a_ponified_fortune_warning/) script or [ponypipe](https://github.com/maandree/ponypipe) to ponify fortunes. - apt-get install fortune - -You can try [this](http://www.reddit.com/r/mylittlelinux/comments/srixi/using_ponysay_with_a_ponified_fortune_warning/) script to ponify fortunes. - Edit your `~/.bashrc` and add this to the end of the file fortune | ponysay @@ -67,4 +64,4 @@ __A:__ Ask and we'll add! __Q:__ Which programs do you use to generate the pony files? -__A:__ The pony files are actually a bunch of selected [browser ponies](http://web.student.tuwien.ac.at/~e0427417/browser-ponies/ponies.html) that are generated into cow files via [img2xterm](https://github.com/rossy2401/img2xterm). +__A:__ The pony files are actually a bunch of selected [browser ponies](http://web.student.tuwien.ac.at/~e0427417/browser-ponies/ponies.html) that are generated into cow files via [img2xterm](https://github.com/rossy2401/img2xterm) or [util-say](https://github.com/maandree/util-say). diff --git a/completion/bash-completion.sh b/completion/bash-completion.sh new file mode 100644 index 0000000..82eb608 --- /dev/null +++ b/completion/bash-completion.sh @@ -0,0 +1,33 @@ +# bash completion for ponysay -*- shell-script -*- + +_ponysay() +{ + local cur prev words cword + _init_completion -n = || return + + COMPREPLY=( $( compgen -W '-v -h -l -f -W' -- "$cur" ) ) + + if [[ $prev = "-f" ]]; then + COMPREPLY=() + + sysponies=/usr/share/ponysay/ponies/ + usrponies=~/.ponies/ + if [[ $TERM = "linux" ]]; then + sysponies=/usr/share/ponysay/ttyponies/ + usrponies=~/.ttyponies/ + fi + + if [[ -d $sysponies ]]; then + COMPREPLY+=( $( compgen -W "$(ls --color=no $sysponies | sed -e 's/.pony//g')" -- "$cur" ) ) + fi + if [[ -d $usrponies ]]; then + COMPREPLY+=( $( compgen -W "$(ls --color=no $usrponies | sed -e 's/.pony//g')" -- "$cur" ) ) + fi + elif [[ $prev = "-W" ]]; then + cols=$( echo `tput cols` - 10 | bc ) + COMPREPLY=( $cols $( echo $cols / 2 | bc ) 100 60 ) + fi +} + +complete -o default -F _ponysay ponysay + diff --git a/completion/zsh-completion.zsh b/completion/zsh-completion.zsh new file mode 100644 index 0000000..07b2ebf --- /dev/null +++ b/completion/zsh-completion.zsh @@ -0,0 +1,11 @@ +#compdef ponysay +_shortopts=( + '-v[Show version and exit]' + '-h[Show this help and exit]' + '-l[list ponyfiles]' + '-f[Select a pony (either a filename or a ponyname]: :_path_files -W "/usr/share/ponysay/ponies" -g "*(\:r)"' + '-W[The screen column where the message should be wrapped]' + ) +_arguments -s : \ + "$_shortopts[@]" + diff --git a/manuals/manpage.6 b/manuals/manpage.6 new file mode 100644 index 0000000..e25a560 --- /dev/null +++ b/manuals/manpage.6 @@ -0,0 +1,96 @@ +.\" +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH PONYSAY 6 "July 12, 2012" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +ponysay \- A cowsay wrapper with ponies +.SH SYNOPSIS +.B ponysay +.RI [ options ] +.RI [ message ] +.br +.B ponythink +.RI [ options ] +.RI [ message ] +.br +.SH DESCRIPTION +.PP +.\" TeX users may be more comfortable with the \fB\fP and +.\" \fI\fP escape sequences to invode bold face and italics, +.\" respectively. +\fBponysay\fP displays an image of a pony saying some text provided by the user in a terminal. +It is a wrapper for \fIcowsay\fP. If \fImessage\fP is not provided, it accepts standard input, +word-wraps the message given at about 40 columns, and prints the pony saying the given message on standard output. +.PP +If no arguments are provided, the program only accepts standard input piped from another program, a file or +either here documents or here strings (see man bash(1) for details on here document/string.) +.PP +\fBponythink\fP is to \fIponysay\fP as \fIcowthink\fP is to \fIcowsay\fP. +.SH OPTIONS +A summary of options is included below. +.TP +.B \-h +Show summary of options. +.TP +.B \-v +Show version of program. +.TP +.B \-l +List pony files. +.TP +.B \-f \fIname\fP +Select a pony (either a file name or a pony name.) +.TP +.B \-W \fIcolumn\fP +The screen column where the message should be wrapped +.SH ENVIRONMENT +.TP +.B PONYSAY_BOTTOM +Under TTY (Linux VT), if the output is larger the the screen's height, only the beginning is +printed, leaving two blank lines. If you want the buttom to be printed rather the the beginning +you can export \fIPONYSAY_BOTTOM\fP with the value \fIyes\fP, \fIy\fP or \fI1\fP. +.TP +.B PONYSAY_SHELL_LINES +Under TTY (Linux VT), if the output is larger the the screen's height, two lines are left blank. +If you want more, or less, blank lines you can export \fIPONYSAY_SHELL_LINES\fP with the value +of how many blank lines you want. Naturally this takes effect if the output is not actually larger +than the screen. +.TP +.B PONYSAY_FULL_WIDTH +You can export \fIPONYSAY_FULL_WIDTH\fP with the value \fIno\fP, \fIn\fP or \fI0\fP, if you +do not want the output to be truncated on the width to fit the terminal. +.TP +.B PONYSAY_TRUNCATE_HEIGHT +Export \fIPONYSAY_TRUNCATE_HEIGHT\fP with the value \fIyes\fP, \fIy\fP or \fI1\fP, if you +want to truncate the output on the height even if you are not running \fIponysay\fP under TTY. +.SH BUG +Bugs can be reported in <\fBhttps://github.com/erkin/ponysay/issues\fP>. +.SH SEE ALSO +.BR cowsay (1), +.BR fortune (6). +.br +.SH AUTHOR +ponysay was written by Erkin Batu Altunbaş +with major contributions from Mattias Andrée, Sven-Hendrik Haase, Jan Alexander Steffens et al. +.\" See file CREDITS for full list. +.PP +This manual page was written by Louis Taylor +for the Debian project (and may be used by others), and edited +by Mattias Andrée . +.br +.PP +This program is licensed under WTFPL. +.\" See file COPYING to see the license. diff --git a/manuals/manpage.es.6 b/manuals/manpage.es.6 new file mode 100644 index 0000000..f5f8db2 --- /dev/null +++ b/manuals/manpage.es.6 @@ -0,0 +1,103 @@ +.\" +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH PONYSAY 6 "Julio 13, 2012" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NOMBRE +ponysay \- un contenedor para cowsay usando ponis +.SH SINOPSIS +.B ponysay +.RI [ opciones ] +.RI [ mensaje ] +.br +.B ponythink +.RI [ opciones ] +.RI [ mensaje ] +.br +.SH DESCRIPCIÓN +.PP +.\" TeX users may be more comfortable with the \fB\fP and +.\" \fI\fP escape sequences to invode bold face and italics, +.\" respectively. +\fBponysay\fP muestra la imagen de un poni con un texto dado por el usuario, esto dentro de la terminal. +Este es en realidad un contenedor para \fIcowsay\fP, aunque sigue usando este último para motrar el mensaje. +Si el \fImesaje\fP no es provisto, este aceptará una orden estándar. +El mensaje debería de tener alrededor de 40 columnas, y el o la poni devería de mostrar este mensaje +en una salida estándar. +.PP +Si no se le da ningun argumenrto, el programa solo aceptará mensajes estándares provistos por otro programa, +un archivo, ambos o cadena de caracteres (vease man bash(1) para detalles de archivos y cadenas de caracteres.) +.PP +\fBponythink\fP es a \fIponysay\fP como \fIcowthink\fP es a \fIcowsay\fP. +.SH OPCIONES +El resumen de las opciones está incluido acontinuación. +.TP +.B \-h +Muestra la ayuda, un resumen de las opciones. +.TP +.B \-v +Muestra la versión del programa. +.TP +.B \-l +Lista los ponis disponibles. +.TP +.B \-f \fInombre\fP +selecciona un poni específico (ya sea un archivo o el nombre directamente) +.TP +.B \-W \fIcolumna\fP +El numero de columnas en el que será impreso el mensaje +.SH ENTORNO +.TP +.B PONYSAY_BOTTOM +Bajo TTY (Linux VT), si la imagen es mas larga que la terminal en pantalla, solo el inicio de esta +es impreso, dejando solo dos líneas blancas. si desea que apesar de todo sea impreso el fondo del +inicio puede exportar \fIPONYSAY_BOTTOM\fP con el valor \fIyes\fP, \fIy\fP o \fI1\fP. +.TP +.B PONYSAY_SHELL_LINES +Bajo TTY (Linux VT), si la imagen es mas larga que la terminal en pantalla, solo dos líneas blancas +serán impresas. si desea más o menos lineas blancas, puede exportar \fIPONYSAY_SHELL_LINES\fP con +el valor de cuantas líneas blancas desea. Naturalmente esto solo tomará efecto si la salida no es mas +larga que la pantalla. +.TP +.B PONYSAY_FULL_WIDTH +Puede exportar \fIPONYSAY_FULL_WIDTH\fP con el valor \fIno\fP, \fIn\fP o \fI0\fP, si usted +no desea que la salida sea truncada para que calce en la terminal. +.TP +.B PONYSAY_TRUNCATE_HEIGHT +Exporte \fIPONYSAY_TRUNCATE_HEIGHT\fP con el valor \fIyes\fP, \fIy\fP o \fI1\fP, si +desea truncar la salida en el largo aun si no se está dentro de una terminal \fIponysay\fP bajo TTY. +.SH BUGs +.nf +Los bugs pueden ser reportados en +.br +<\fBhttps://github.com/erkin/ponysay/issues\fP>. +.SH VEA TAMBIÉN +.BR cowsay (1), +.BR fortune (6). +.br +.SH AUTOR +ponysay fue escrito por Erkin Batu Altunbaş +con la ayuda de Mattias Andrée, Sven-Hendrik Haase, Jan Alexander Steffens y otros. +.\" vea el archivo CREDITS para la lista completa +.PP +Este manual originalmente fue escrito por Louis Taylor +para el proyecto Debian (y puede ser usado por otros), y editado por +Mattias Andrée . +.br +La actual traducción al español fue escrita por Pablo Lezaeta . +.br +.PP +Este programa está licenciado bajo la WTFPL +.\" Vea el archivo COPYING para ver la licencia completa. diff --git a/ponies/applecore.pony b/ponies/applecore.pony new file mode 100644 index 0000000..42d0c0a --- /dev/null +++ b/ponies/applecore.pony @@ -0,0 +1,23 @@ +$the_cow =< 80 )) && scrw=80 + + echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m" + files=`ls -1 $SYSTEMPONIES | sed "s/.pony//"` + maxw=1 + for file in $files; do + w=$(( `echo $file | wc -m` + 2 )) + (( $maxw < $w )) && maxw=$w + done + cols=$(( $scrw / $maxw )) + echo "$files" | pr -T --columns=$cols + if [[ -d $HOMEPONIES ]]; then - echo "ponyfiles located in $HOMEPONIES:" - ls -1 $HOMEPONIES | sed "s/.pony//" + echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m" + files=`ls -1 $HOMEPONIES | sed "s/.pony//"` + maxw=1 + for file in $files; do + w=$(( `echo $file | wc -m` )) + (( $maxw < $w )) && maxw=$w + done + cols=$(( $scrw / $maxw )) + echo "$files" | pr -T --columns=$cols fi } @@ -34,18 +52,20 @@ usage() { Usage: ${0##*/} [options] [message] -If [message] is not provided, reads the message from STDIN +If [message] is not provided, reads the message from STDIN. Options: - -v Show version and exit - -h Show this help and exit - -l List ponyfiles. - -f[name] Select a pony (Either a filename or a pony name) - -W[column] The screen column where the message should be wrapped + -v Show version and exit. + -h Show this help and exit. + -l List pony files. + -f[name] Select a pony (either a file name or a pony name.) + -W[column] The screen column where the message should be wrapped. + +See man ponysay(6) for more information. EOF } -# if no stdin and no argumrnts then print usage and exit +# if no stdin and no arguments then print usage and exit if [[ -t 0 && $# == 0 ]]; then usage exit @@ -59,10 +79,40 @@ say() { echo -ne '\ec' fi - exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | (ponysaytruncater `tput cols || echo 0` 2>/dev/null || - ${HOME}/.local/bin/ponysaytruncater `tput cols || echo 0` 2>/dev/null || - ./ponysaytruncater `tput cols || echo 0` 2>/dev/null || - cat) + function wtrunc + { + if [ "$PONYSAY_FULL_WIDTH" = 'no' ] || [ "$PONYSAY_FULL_WIDTH" = 'n' ] || [ "$PONYSAY_FULL_WIDTH" = '0' ]; then + cat + else + WIDTH=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` + ponysaytruncater $WIDTH 2>/dev/null || + ${HOME}/.local/bin/ponysaytruncater $WIDTH 2>/dev/null || + ./ponysaytruncater $WIDTH 2>/dev/null || + cat + fi + } + + if [ "$PONYSAY_SHELL_LINES" = "" ]; then + PONYSAY_SHELL_LINES=2 + fi + function htrunchead + { + head --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) + } + function htrunctail + { + tail --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) + } + + if [ "$TERM" = "linux" ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'yes' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'y' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = '1' ]; then + if [ "$PONYSAY_BOTTOM" = 'yes' ] || [ "$PONYSAY_BOTTOM" = 'y' ] || [ "$PONYSAY_BOTTOM" = '1' ]; then + exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunctail + else + exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunchead + fi + else + exec "$cmd" -f "$pony" "${wrap:+-W$wrap}" | wtrunc + fi } while getopts f:W:lhv OPT @@ -78,7 +128,7 @@ do done shift $((OPTIND - 1)) -if ! hash $cmd &>/dev/null; then +hash $cmd &>/dev/null; if [ $? -ne 0 ]; then cat >&2 < - - #define String char* #define boolean char - #define true 1 #define false 0 - - -/** - * Stdin file descriptor ID - */ +/* Stdin file descriptor ID */ #define STDIN 0 - - -/** - * The number of columns on the current line - */ +/* The number of columns on the current line */ static int x = 0; -/** - * Escape sequence state - */ +/* Escape sequence state */ static int esc = 0; -/** - * Last bytes as written - */ +/* Last bytes as written */ static boolean ok = true; - - - void write(char b, int width); int toInt(String string); - -/** - *

Mane method!

- *

+/* Mane method! * The only argument, in addition to the executed file, * should be the width of the terminal which you get by * adding `tput cols || echo 0` as and argument. - *

- * + * * @param argc The number of startup arguments * @param argv The startup arguments, the first is the file itself * @@ -60,115 +39,115 @@ int toInt(String string); */ void main(int argc, String* argv) { - int width = 0; - if (argc > 1) - width = toInt(*(argv + 1)); - - char b = 0; - - if (width > 15) //sanity - while (read(STDIN, &b, 1)) - write(b, width); - else - while (read(STDIN, &b, 1)) - printf("%c", b); + int width = 0; + if (argc > 1) + width = toInt(*(argv + 1)); + + char b = 0; + + if (width > 15) /* sanity */ + while (read(STDIN, &b, 1)) + write(b, width); + else + while (read(STDIN, &b, 1)) + printf("%c", b); } - -/** - * Writes a character to stdout, iff it fits within the terminal +/* Writes a character to stdout, iff it fits within the terminal * * @param b The character (byte) to write * @param width The width of the terminal */ void write(char b, int width) { - int i; - char nx; - - if (esc == 0) + int i; + char nx; + + if (esc == 0) { - if (b == '\n') + if (b == '\n') { - if (x >= width) + if (x >= width) { - // Reset background colour - write('\e', width); - write('[', width); - write('4', width); - write('9', width); - write('m', width); + /* Reset background colour */ + write('\e', width); + write('[', width); + write('4', width); + write('9', width); + write('m', width); } - x = -1; + x = -1; } - else if (b == '\t') + else if (b == '\t') { - // Tab to next pos ≡₈ 0 - nx = 8 - (x & 7); - for (i = 0; i < nx; i++) - write(' ', width); - return; //(!) + /* Tab to next pos ≡₈ 0 */ + nx = 8 - (x & 7); + for (i = 0; i < nx; i++) + write(' ', width); + return; /* (!) */ } - else if (b == '\e') - esc = 1; + else if (b == '\e') + esc = 1; } - else if (esc == 1) + else if (esc == 1) { - if (b == '[') esc = 2; //CSI ends with a letter, m is for colour - else if (b == ']') esc = 3; //OSI, OSI P is for palett editing in Linux VT - else esc = 10; //Nothing to see here, move along + if (b == '[') esc = 2; /* CSI: CSI ends with a letter, m is for colour */ + else if (b == ']') esc = 3; /* OSI: OSI P is for palett editing in Linux VT */ + else esc = 10; /* Nothing to see here, move along */ } - else if (esc == 2) + else if (esc == 2) { - if ((('a' <= b) && (b <= 'z')) || (('A' <= b) && (b <= 'Z'))) - esc = 10; + if ((('a' <= b) && (b <= 'z')) || (('A' <= b) && (b <= 'Z'))) + esc = 10; } - else if ((esc == 3) && (b == 'P')) + else if ((esc == 3) && (b == 'P')) { - esc = ~0; + esc = ~0; } - else if (esc < 0) + else if (esc < 0) { - esc--; - if (esc == ~7) - esc = 10; + esc--; + if (esc == ~7) + esc = 10; } - else - esc = 10; - - if ( // Can be printed: - (x < width) || // within bounds ∨ - (esc != 0) || // ∨ escape sequence ∨ - (ok && ((b & 0xC0) == 0x80))) // ∨ last with printed ∧ not first byte in character + else + esc = 10; + + if ( + /* Can be printed: + within bounds ∨ + ∨ escape sequence ∨ + ∨ last with printed ∧ not first byte in character */ + (x < width) || + (esc != 0) || + (ok && ((b & 0xC0) == 0x80))) { - printf("%c", b); - if ((esc == 0) && ((b & 0xC0) != 0x80)) // Count up columns of not in escape sequnce and - x++; // the byte is not the first byte in the character - ok = true; + printf("%c", b); + if ((esc == 0) && ((b & 0xC0) != 0x80)) + /* Count up columns of not in escape sequnce and */ + x++; /* the byte is not the first byte in the character */ + ok = true; } - else - ok = false; - - if (esc == 10) - esc = 0; + else + ok = false; + + if (esc == 10) + esc = 0; } - -/** - * Converts a string to an integer +/* Converts a string to an integer * * @param string The string to convert * @return The integer represented by the string */ int toInt(String string) { - int rc = 0; - String str = string; - char c = 0; - - while ((c = *str++) != 0) - rc = (rc << 1) + (rc << 3) - (c & 15); - - return -rc; + int rc = 0; + String str = string; + char c = 0; + + while ((c = *str++) != 0) + rc = (rc << 1) + (rc << 3) - (c & 15); + + return -rc; } - diff --git a/ttyponies.sh b/ttyponies.sh new file mode 100755 index 0000000..4913119 --- /dev/null +++ b/ttyponies.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +for pony in $(ls --color=no ponies/); do + echo "building ttypony: $pony" + if [[ `readlink "ponies/$pony"` = '' ]]; then + ponysay2ttyponysay < "ponies/$pony" | tty2colourfultty -c 1 -e > "ttyponies/$pony" + elif [[ ! -f "ttyponies/$pony" ]]; then + ln -s `readlink "ponies/$pony"` "ttyponies/$pony" + fi +done + diff --git a/ttyponies/allie.pony b/ttyponies/allie.pony index a791294..11625fc 100644 --- a/ttyponies/allie.pony +++ b/ttyponies/allie.pony @@ -1,31 +1,31 @@ $the_cow =<