├── .gitattributes ├── .github ├── images │ ├── ascii.png │ ├── front.png │ ├── help.png │ ├── icon.png │ └── example.png ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── PULL_REQUEST_TEMPLATE.md └── CONTRIBUTING.md ├── .gitignore ├── .travis.yml ├── LICENSE ├── cat.go ├── app_test.go ├── CODE_OF_CONDUCT.md ├── README.md ├── .dist └── build.sh └── app.go /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | /.dist/* linguist-detectable=false 3 | -------------------------------------------------------------------------------- /.github/images/ascii.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammadmuzzammil1998/catsay/HEAD/.github/images/ascii.png -------------------------------------------------------------------------------- /.github/images/front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammadmuzzammil1998/catsay/HEAD/.github/images/front.png -------------------------------------------------------------------------------- /.github/images/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammadmuzzammil1998/catsay/HEAD/.github/images/help.png -------------------------------------------------------------------------------- /.github/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammadmuzzammil1998/catsay/HEAD/.github/images/icon.png -------------------------------------------------------------------------------- /.github/images/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammadmuzzammil1998/catsay/HEAD/.github/images/example.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | catsay 8 | *.deb 9 | *.tar.gz 10 | 11 | # Test binary, build with `go test -c` 12 | *.test 13 | 14 | # Output of the go coverage tool, specifically when used with LiteIDE 15 | *.out 16 | 17 | .dist/BIN_INFO 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - CC_TEST_REPORTER_ID=$CC_SECRET 4 | 5 | language: go 6 | 7 | go: 8 | - master 9 | 10 | before_script: 11 | - go get -d 12 | - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter 13 | - chmod +x ./cc-test-reporter 14 | - ./cc-test-reporter before-build 15 | 16 | script: 17 | - go test -coverprofile c.out ./... 18 | 19 | after_script: 20 | - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Desktop (please complete the following information):** 24 | - OS: [e.g. linux, windows] 25 | - Browser [e.g. chrome, safari] 26 | - Version [e.g. 2] 27 | 28 | **Additional context** 29 | Add any other context about the problem here. 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Muhammad Muzzammil 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 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. 4 | 5 | Fixes # (issue) 6 | 7 | ## Type of change 8 | 9 | Please delete options that are not relevant. 10 | 11 | - [ ] Bug fix (non-breaking change which fixes an issue) 12 | - [ ] New feature (non-breaking change which adds functionality) 13 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 14 | - [ ] This change requires a documentation update 15 | 16 | # How Has This Been Tested? 17 | 18 | Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration 19 | 20 | - [ ] Test A 21 | - [ ] Test B 22 | 23 | **Test Configuration**: 24 | 25 | * Thing A 26 | * Thing B 27 | * Thing C 28 | 29 | # Checklist: 30 | 31 | - [ ] My code follows the style guidelines of this project 32 | - [ ] I have performed a self-review of my own code 33 | - [ ] I have commented my code, particularly in hard-to-understand areas 34 | - [ ] I have made corresponding changes to the documentation 35 | - [ ] My changes generate no new warnings 36 | - [ ] I have added tests that prove my fix is effective or that my feature works 37 | - [ ] New and existing unit tests pass locally with my changes 38 | - [ ] Any dependent changes have been merged and published in downstream modules 39 | -------------------------------------------------------------------------------- /cat.go: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2018 Muhammad Muzzammil 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package main 26 | 27 | //Cat contains parts to build a cat 28 | type Cat struct { 29 | Body string `json:"body"` 30 | BodyASCII string `json:"ascii"` 31 | MinLen int `json:"minimumlength"` 32 | } 33 | 34 | //Returns a cat 35 | func getCat() *Cat { 36 | return &Cat{ 37 | Body: " (\\__/)||\n_ (•ㅅ•)||\n \\/o \\っ\n", 38 | BodyASCII: " (\\__/) ||\n_ (*/\\*) ||\n \\/o \\ >", 39 | MinLen: 9, 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to CatSay 2 | :tada: First off, thanks for taking the time to contribute! :tada: 3 | 4 | ## Index 5 | * [Code Of Conduct](#code-of-conduct) 6 | * [Bug Reporting](#report-a-bug) 7 | * [Feature Request](#add-new-feature) 8 | * [Pull Request](#pull-request) 9 | * [Contact](#contact) 10 | 11 | ## Code Of Conduct 12 | We need you to strictly follow our code of conduct. Help us make a better community. 13 | ### What is Code of conduct? 14 | A code of conduct defines standards for how to engage in a community. It signals an inclusive environment that respects all contributions. It also outlines procedures for addressing problems between members of your project's community. 15 | ### Read our Code of conduct 16 | You can read our code of conduct [here](./CODE_OF_CONDUCT.md) 17 | 18 | ## Report a bug 19 | Before reporting, please ensure that: 20 | - [ ] Bug is not fixed or mentioned in any branch, pull request or issue of CatSay. 21 | - [ ] Bug is not on your computer only, test it on at least 3 computers. 22 | - [ ] You are using latest version of CatSay. 23 | - [ ] You check if someone hasn't already filed a bug report of same issue. (if someone has filed one, comment on it) 24 | - [ ] You do your research to help us identify the problem. 25 | 26 | ### Format of Report 27 | A report should contain the following: 28 | 29 | * A suitable title, 30 | * Description of what happened and what was supposed to happen, 31 | * Exact steps, 32 | * And, your thought on how to fix this. :) 33 | 34 | ## Add new feature 35 | > “The best way to predict your future is to create it.” ~*Abraham Lincoln* 36 | 37 | Just [email us](mailto:swsh@muzzammil.xyz) the details or create an [issue here](https://github.com/muhammadmuzzammil1998/catsay/issues/new) and we will get right on it. 38 | 39 | Details should include: 40 | 41 | * What you want, 42 | * How do you want it, 43 | * Any research you have done for it, 44 | * Your contact information (name, email and website.) 45 | * Anything you want, as long as it follows our [code of conduct](#code-of-conduct). 46 | 47 | ## Pull Request 48 | You can make a pull request, but it should be unique and follow guidelines described here and in our [code of conduct](#code-of-conduct). 49 | 50 | ### Somethings to remember when writing code: 51 | * Use programmer-friendly variable names. 52 | * Don't do unnecessary things. 53 | * Format your code. 54 | 55 | ## Contact 56 | My email: [email@muzzammil.xyz](mailto:email@muzzammil.xyz) 57 | -------------------------------------------------------------------------------- /app_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2018 Muhammad Muzzammil 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package main 26 | 27 | import ( 28 | "bufio" 29 | "strings" 30 | "testing" 31 | ) 32 | 33 | var message = buildMessage("Hello", "\tnewline", "one more newline with more data", " one more with less data", "this\tone\thas\ttabs!") 34 | 35 | func TestReadLines(t *testing.T) { 36 | r := bufio.NewReader(strings.NewReader("Hello")) 37 | s := readLines(r) 38 | if s[0] != "Hello" { 39 | t.Fatalf("Couldn't parse bufio.Reader") 40 | } 41 | } 42 | 43 | func TestGetWidth(t *testing.T) { 44 | setup() 45 | r := getWidth(message) 46 | if r < 9 { 47 | t.Fatalf("Expected to be greater or equal to 9 but got %d", r) 48 | } 49 | } 50 | 51 | func TestRemoveTabs(t *testing.T) { 52 | r := removeTabs(message) 53 | if r[4] != "this one has tabs!" { 54 | t.Fatalf("Tabs were not replaced with spaces") 55 | } 56 | } 57 | 58 | func TestCreateMessage(t *testing.T) { 59 | setup() 60 | data := removeTabs(message) 61 | r := createMessage(data, getWidth(data)) 62 | var e = ` _________________________________ 63 | / Hello \ 64 | | newline | 65 | | one more newline with more data | 66 | | one more with less data | 67 | \ this one has tabs! / 68 | ---------------------------------` 69 | 70 | if r != e { 71 | t.Fatalf("Expected\n%s\nbut got\n%s", e, r) 72 | } 73 | } 74 | 75 | func TestFormatMessage(t *testing.T) { 76 | setup() 77 | data := removeTabs(message) 78 | e := formatMessage(data, getWidth(data)) 79 | eLen := len(e[0]) 80 | var rLen int 81 | for _, r := range e { 82 | rLen = len(r) 83 | } 84 | if eLen != rLen { 85 | t.Fatalf("Length of each line should be equal. Expected %d but got %d", eLen, rLen) 86 | } 87 | } 88 | 89 | func TestMultiByteString(t *testing.T) { 90 | setup() 91 | data := removeTabs(buildMessage("こんにちわ世界")) 92 | got := createMessage(data, getWidth(data)) 93 | var want = ` ________________ 94 | < こんにちわ世界 > 95 | ----------------` 96 | if got != want { 97 | t.Fatalf("Expected\n%s\nbut got\n%s", want, got) 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at email@muzzammil.xyz. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # catsay 2 | [![Build Status](https://travis-ci.org/muhammadmuzzammil1998/catsay.svg?branch=master)](https://travis-ci.org/muhammadmuzzammil1998/catsay) [![CodeFactor](https://www.codefactor.io/repository/github/muhammadmuzzammil1998/catsay/badge)](https://www.codefactor.io/repository/github/muhammadmuzzammil1998/catsay) [![Go Report Card](https://goreportcard.com/badge/github.com/muhammadmuzzammil1998/catsay)](https://goreportcard.com/report/github.com/muhammadmuzzammil1998/catsay) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/800d49d519784954ad0051d8c23a34c4)](https://www.codacy.com/app/muhammadmuzzammil1998/catsay?utm_source=github.com&utm_medium=referral&utm_content=muhammadmuzzammil1998/catsay&utm_campaign=Badge_Grade) [![Maintainability](https://api.codeclimate.com/v1/badges/1ce5d0c70611a65a5036/maintainability)](https://codeclimate.com/github/muhammadmuzzammil1998/catsay/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/1ce5d0c70611a65a5036/test_coverage)](https://codeclimate.com/github/muhammadmuzzammil1998/catsay/test_coverage) [![GitHub license](https://img.shields.io/github/license/muhammadmuzzammil1998/catsay.svg)](https://github.com/muhammadmuzzammil1998/catsay/blob/master/LICENSE) [![Twitter](https://img.shields.io/twitter/url/https/github.com/muhammadmuzzammil1998/catsay.svg?style=social)](https://twitter.com/intent/tweet?hashtags=catsay&text=Take%20a%20look%20at%20this!%20CatSay%20by%20@mmuzzammil1998&url=https://github.com/muhammadmuzzammil1998/catsay/) 3 | 4 | **catsay** is a program that generates pictures of a cat holding a sign with a message. 5 | ![image](.github/images/front.png) 6 | 7 | ## Build 8 | Requires [git](https://git-scm.com/download/win) to clone and [Go](https://golang.org/dl/) to build. 9 | ```bash 10 | $ git clone https://github.com/muhammadmuzzammil1998/catsay.git 11 | $ cd catsay 12 | $ go get -d 13 | $ go build 14 | ``` 15 | 16 | ## Installation 17 | Follow the guide on the [releases](https://github.com/muhammadmuzzammil1998/catsay/releases) page for detailed instructions. 18 | ### Linux 19 | Download `.deb` file for catsay from the [releases](https://github.com/muhammadmuzzammil1998/catsay/releases) page. 20 | ```bash 21 | $ wget https://github.com/muhammadmuzzammil1998/catsay/releases/download/{version}/catsay-linux-{amd64/386}.deb 22 | $ sudo dpkg -i catsay-linux-{amd64/386}.deb 23 | ``` 24 | ### Windows 25 | Start PowerShell as an admin 26 | ```ps 27 | $ Invoke-WebRequest https://github.com/muhammadmuzzammil1998/catsay/releases/download/{version}/catsay-windows-{amd64/386}.exe -OutFile catsay.exe 28 | $ mv .\catsay.exe C:\Windows\catsay.exe 29 | ``` 30 | ### Other OSs 31 | You can download the [binary already built](https://github.com/muhammadmuzzammil1998/catsay/releases) for your system or [build it yourself](https://github.com/muhammadmuzzammil1998/catsay#build). 32 | 33 | ### NOTE: This should be obvious but still: 34 | - Adapt `{version}` number. Check version number from [here](https://github.com/muhammadmuzzammil1998/catsay/releases). 35 | - Choose your architecture, `amd64` for 64 bit and `386` for 32 bit systems. 36 | 37 | ## Usage 38 | Pipe the data you want your cat to say. 39 | ### Examples 40 | ![image](.github/images/example.png) 41 | 42 | ## Seeing blocks instead of eyes, nose, or hand? 43 | This is probably because your terminal doesn't support those characters. lulz. 44 | 45 | Try `catsay -ascii` to use ASCII-only characters. 46 | ![image](.github/images/ascii.png) 47 | 48 | ## Help 49 | ![image](.github/images/help.png) 50 | 51 | ## Uninstall 52 | ### Linux 53 | ```bash 54 | $ sudo dpkg --remove catsay 55 | ``` 56 | ### Windows 57 | Start PowerShell as an admin 58 | ```ps 59 | $ del C:\Windows\catsay.exe 60 | ``` 61 | ## Contributors 62 | 63 | - **[@mattn](https://github.com/mattn)** - Fixed width for multi-byte strings *([#14](https://github.com/muhammadmuzzammil1998/catsay/pull/14))* 64 | -------------------------------------------------------------------------------- /.dist/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # MIT License 4 | # 5 | # Copyright (c) 2018 Muhammad Muzzammil 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to deal 9 | # in the Software without restriction, including without limitation the rights 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | # copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | # SOFTWARE. 24 | 25 | platforms=("darwin/386" "darwin/amd64" "dragonfly/amd64" "freebsd/386" "freebsd/amd64" "freebsd/arm" "linux/386" "linux/amd64" "linux/arm" "linux/arm64" "linux/ppc64" "linux/ppc64le" "linux/mips" "linux/mipsle" "linux/mips64" "linux/mips64le" "netbsd/386" "netbsd/amd64" "netbsd/arm" "openbsd/386" "openbsd/amd64" "openbsd/arm" "plan9/386" "plan9/amd64" "solaris/amd64" "windows/386" "windows/amd64") 26 | cd .. 27 | rm -rf bin deb 28 | mkdir bin 29 | 30 | version=2.1 31 | maintainer="Muhammad Muzzammil " 32 | url="https://github.com/muhammadmuzzammil1998/catsay/" 33 | desc="catsay is a program that generates pictures of a cat holding a sign with a message." 34 | license="MIT" 35 | 36 | go test -v 37 | 38 | if [ $? -ne 0 ]; then 39 | echo 'Tests were not successful' 40 | exit 1 41 | fi 42 | 43 | for platform in "${platforms[@]}" 44 | do 45 | package_name=catsay 46 | 47 | platform_split=(${platform//\// }) 48 | GOOS=${platform_split[0]} 49 | GOARCH=${platform_split[1]} 50 | output_name=$package_name'-'$GOOS'-'$GOARCH 51 | 52 | if [ $GOOS = "windows" ]; then 53 | package_name+='.exe' 54 | fi 55 | 56 | env GOOS=$GOOS GOARCH=$GOARCH go build -o $package_name 57 | 58 | if [ $? -ne 0 ]; then 59 | echo 'Unable to build for '$GOOS'-'$GOARCH 60 | else 61 | if [ $GOOS = "linux" ]; then 62 | if [[ $GOARCH = "386" || $GOARCH = "amd64" ]]; then 63 | mkdir deb; cd deb; mkdir catsay; mkdir catsay/DEBIAN; mkdir catsay/usr; mkdir catsay/usr/bin; 64 | cp ../$package_name catsay/usr/bin 65 | echo -e "Package: catsay\nVersion: $version\nArchitecture: all\nMaintainer: $maintainer\nHomepage: $url\nDescription: $desc\nLicense: $license\n" > catsay/DEBIAN/control 66 | 67 | dpkg-deb --build catsay 68 | mv catsay.deb ../bin/$output_name'.deb' 69 | cd ../bin 70 | file $output_name'.deb' >> BIN_INFO 71 | cd .. 72 | rm -rf deb; 73 | fi 74 | fi 75 | 76 | if [ $GOOS = "windows" ]; then 77 | cp $package_name bin/$output_name'.exe' 78 | fi 79 | 80 | mkdir $output_name 81 | cp LICENSE $output_name 82 | mv $package_name $output_name 83 | echo 'Built for '$GOOS'-'$GOARCH 84 | file $output_name'/'$package_name >> bin/BIN_INFO 85 | tar -zcvf $output_name.tar.gz $output_name > /dev/null 86 | echo 'Packed in '$output_name'.tar.gz' 87 | mv $output_name'.tar.gz' bin/ 88 | rm -rf $output_name 89 | fi 90 | done 91 | 92 | echo -e "\n\nPacking binaries..." 93 | tar -zcvf .dist/catsay-binaries.tar.gz bin > /dev/null 94 | file .dist/catsay-binaries.tar.gz >> bin/BIN_INFO 95 | mv bin/BIN_INFO .dist/BIN_INFO 96 | rm -rf bin 97 | -------------------------------------------------------------------------------- /app.go: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2018 Muhammad Muzzammil 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package main 26 | 27 | import ( 28 | "bufio" 29 | "flag" 30 | "fmt" 31 | "io" 32 | "os" 33 | "strings" 34 | 35 | "github.com/mattn/go-runewidth" 36 | ) 37 | 38 | //Defining a main cat 39 | var cat *Cat 40 | 41 | func main() { 42 | //Declaring flags and parsing them 43 | var ascii, version bool 44 | var data []string 45 | flag.BoolVar(&ascii, "ascii", false, "Use this if you see blocks here \"•ㅅ•っ\"") 46 | flag.BoolVar(&version, "version", false, "Check version of catsay") 47 | flag.Parse() 48 | 49 | //Checking flags 50 | if version { 51 | data = buildMessage("CatSay", "\tby Muhammad Muzzammil", "", "Version 2.1", "", "http://bit.ly/CATSAY") 52 | } else if info, _ := os.Stdin.Stat(); info.Mode()&os.ModeCharDevice != 0 { 53 | data = buildMessage("oh hai kittehs!", "use pipez... i doan knoe how 2 werk otherwize.", "example: echo \"y halo thar, im kat\" | catsay", "", "or try \"catsay -help\"", "btw, i hatz dis sign. lulz") 54 | } else { 55 | data = readLines(bufio.NewReader(os.Stdin)) 56 | } 57 | 58 | setup() 59 | data = removeTabs(data) //Replace tabs with spaces 60 | message := createMessage(data, getWidth(data)) //Create Message Dialog 61 | fmt.Println(message) //Print message dialog 62 | if ascii { //If ascii is true, show ascii cat 63 | fmt.Println(cat.BodyASCII) 64 | } else { 65 | fmt.Println(cat.Body) 66 | } 67 | } 68 | 69 | //Setup a new cat 70 | func setup() { 71 | cat = getCat() 72 | } 73 | 74 | //Reads and returns data from piped information 75 | func readLines(reader *bufio.Reader) []string { 76 | var ret []string 77 | for { 78 | line, _, err := reader.ReadLine() 79 | if err != nil && err == io.EOF { 80 | break 81 | } 82 | ret = append(ret, string(line)) 83 | } 84 | return ret 85 | } 86 | 87 | //Gets maximum width of block 88 | func getWidth(message []string) int { 89 | ret := cat.MinLen 90 | for _, l := range message { 91 | width := runewidth.StringWidth(l) 92 | if width > ret { 93 | ret = width 94 | } 95 | } 96 | return ret 97 | } 98 | 99 | //Creates and returns a new message dialog 100 | func createMessage(lines []string, width int) string { 101 | lines = formatMessage(lines, width) 102 | count := len(lines) 103 | var message []string 104 | 105 | message = append(message, " "+strings.Repeat("_", width+2)) //Top 106 | if count > 1 { 107 | message = append(message, fmt.Sprintf(`%s %s %s`, "/", lines[0], "\\")) 108 | i := 1 109 | for ; i < count-1; i++ { 110 | message = append(message, fmt.Sprintf(`%s %s %s`, "|", lines[i], "|")) 111 | } 112 | message = append(message, fmt.Sprintf(`%s %s %s`, "\\", lines[i], "/")) 113 | } else { 114 | message = append(message, fmt.Sprintf("%s %s %s", "<", lines[0], ">")) 115 | } 116 | 117 | message = append(message, " "+strings.Repeat("-", width+2)) //Bottom 118 | return strings.Join(message, "\n") 119 | } 120 | 121 | //Replaces tabs with 4 spaces 122 | func removeTabs(message []string) []string { 123 | var ret []string 124 | for _, l := range message { 125 | l = strings.Replace(l, "\t", " ", -1) 126 | ret = append(ret, l) 127 | } 128 | return ret 129 | } 130 | 131 | //Formats message by adding whitespaces 132 | func formatMessage(message []string, width int) []string { 133 | var ret []string 134 | for _, l := range message { 135 | w := runewidth.StringWidth(l) 136 | ret = append(ret, l+strings.Repeat(" ", width-w)) 137 | } 138 | return ret 139 | } 140 | 141 | //Builds a message 142 | func buildMessage(s ...string) []string { 143 | return s 144 | } 145 | --------------------------------------------------------------------------------