├── assets └── fox.png ├── LICENSE ├── README.md └── foxsay.py /assets/fox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gingermuffin/foxsay/HEAD/assets/fox.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2021 Anastasia Kim 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Foxsay 2 | 3 | This is a simple program that generates pictures of a cute fox with a message. 4 | 5 | It is like a `cowsay` but without cows! Fox girls are better! 6 | 7 | ![Fox Image](./assets/fox.png) 8 | 9 | ## Usage 10 | 11 | ```sh 12 | $ ./foxsay.py "Hello, Github!" 13 | # Or. 14 | $ python3 ./foxsay.py "Hello, Github!" 15 | # Or call it without text to get a fox's wisdom. 16 | $ ./foxsay.py 17 | 18 | # ╭────────────────╮ 19 | # │ │ 20 | # │ Hello, Github! │ 21 | # │ │ 22 | # ╰─v──────────────╯ 23 | # 24 | # |\_|\ ,_.=-,_ 25 | # ._.@ @ ,._.-=-.,_.=` {.-` 26 | # '-.,_ ( .-,_ _.` 27 | # 'm`m^"-m.G ` 28 | ``` 29 | 30 | ## How to add a new wisdom 31 | Just add it into the `WISDOM` (in [./foxsay.py](./foxsay.py) file) and create 32 | a new Pull Request! 33 | 34 | ``` python 35 | WISDOM = [ 36 | # ... 37 | "Add your own one! :)", 38 | ] 39 | ``` 40 | 41 | --- 42 | 43 | #### License 44 | [MIT](./LICENSE) 45 | 46 | --- 47 | 48 | With :heart: by [Anastasia Kim (@gingermuffin)](https://github.com/gingermuffin) 49 | -------------------------------------------------------------------------------- /foxsay.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import random 5 | 6 | # Some constants. 7 | MIN_WIDTH = 1 8 | MAX_WIDTH = 80 9 | 10 | GREEN = u"\u001b[32m" 11 | ORANGE = u"\u001b[33m" 12 | BLUE = u"\u001b[34m" 13 | RESET = u"\u001b[0m" 14 | 15 | BALLOON_COLOR = BLUE 16 | 17 | BALLOON_IMAGE_PARTS = [ 18 | ["╭", "─", "╮"], 19 | ["│", " ", "│"], 20 | ["╰", "─", "╯"], 21 | [" ", "v", " "], 22 | ] 23 | 24 | FOX_IMAGE_WITHOUT_COLORS = """ 25 | |\_|\ ,_.=-,_ 26 | ._.@ @ ,._.-=-.,_.=` {.-` 27 | '-.,_ ( .-,_ _.` 28 | 'm`m^"-m.G ` 29 | """[1:-1] # Cut first and last empty lines. 30 | 31 | # It's a fox trust me :(. 32 | # All {} will be replaced with its colors. 33 | FOX_IMAGE = """ 34 | |{orange}\_{reset}|{orange}\{reset} {orange},_.={reset}-,_ 35 | .{orange}_.{reset}{green}@ @{reset} {orange},._.-=-.,_.=` {reset}{{.-` 36 | {orange}'-.,_ ( .-,_ _.{reset}` 37 | {orange}'m`m^"-m.G{reset} {orange}`{reset} 38 | """[1:-1].format(green = GREEN, orange = ORANGE, reset = RESET) 39 | 40 | WISDOM = [ 41 | "What does the fox say?", 42 | "Ring-ding-ding-ding-dingeringeding!", 43 | "Wa-pa-pa-pa-pa-pa-pow!", 44 | # "Hatee-hatee-hatee-ho!", 45 | # "Joff-tchoff-tchoffo-tchoffo-tchoff!", 46 | # "Jacha-chacha-chacha-chow!", 47 | # "Fraka-kaka-kaka-kaka-kow!", 48 | # "A-hee-ahee ha-hee!", 49 | # "A-oo-oo-oo-ooo!" 50 | "Eating one cooked chicken restores six hunger", 51 | "A fox has to do what a fox has to do", 52 | "The mitochondria is the powerhouse of the cell", 53 | ] 54 | 55 | # Wisdom functions. 56 | def get_random_wisdom(): 57 | return random.choice(WISDOM) 58 | 59 | # Draw functions. 60 | def split_text_by_lines(text, line_width): 61 | lines = [] 62 | 63 | for i in range(0, len(text), line_width): 64 | lines.append(text[i:i+line_width]) 65 | 66 | return lines 67 | 68 | def draw_balloon(text = None): 69 | # We get a random text if we don't have one. 70 | if text is None or text == "": 71 | text = get_random_wisdom() 72 | 73 | # Reserve 2 symbols for borders and 2 symbols for gaps. 74 | line_width = max(MIN_WIDTH, min(MAX_WIDTH - 4, len(text))) 75 | lines = split_text_by_lines(text, line_width) 76 | 77 | result = "" 78 | 79 | # Draw top line. 80 | result += BALLOON_COLOR +\ 81 | BALLOON_IMAGE_PARTS[0][0] +\ 82 | BALLOON_IMAGE_PARTS[0][1] * (line_width + 2) +\ 83 | BALLOON_IMAGE_PARTS[0][2] +\ 84 | RESET +\ 85 | "\n" 86 | 87 | # Draw an empty line. 88 | result += BALLOON_COLOR +\ 89 | BALLOON_IMAGE_PARTS[1][0] +\ 90 | RESET +\ 91 | BALLOON_IMAGE_PARTS[1][1] * (line_width + 2) +\ 92 | BALLOON_COLOR +\ 93 | BALLOON_IMAGE_PARTS[1][2] +\ 94 | RESET +\ 95 | "\n" 96 | 97 | for line in lines: 98 | extra_space = line_width - len(line) 99 | 100 | result += BALLOON_COLOR +\ 101 | BALLOON_IMAGE_PARTS[1][0] +\ 102 | RESET +\ 103 | BALLOON_IMAGE_PARTS[1][1] +\ 104 | line +\ 105 | BALLOON_IMAGE_PARTS[1][1] * extra_space +\ 106 | BALLOON_IMAGE_PARTS[1][1] +\ 107 | BALLOON_COLOR +\ 108 | BALLOON_IMAGE_PARTS[1][2] +\ 109 | RESET +\ 110 | "\n" 111 | 112 | # Draw an empty line. 113 | result += BALLOON_COLOR +\ 114 | BALLOON_IMAGE_PARTS[1][0] +\ 115 | RESET +\ 116 | BALLOON_IMAGE_PARTS[1][1] * (line_width + 2) +\ 117 | BALLOON_COLOR +\ 118 | BALLOON_IMAGE_PARTS[1][2] +\ 119 | RESET +\ 120 | "\n" 121 | 122 | # Draw bottom line. 123 | result += BALLOON_COLOR +\ 124 | BALLOON_IMAGE_PARTS[2][0] +\ 125 | BALLOON_IMAGE_PARTS[2][1] +\ 126 | BALLOON_IMAGE_PARTS[3][1] +\ 127 | BALLOON_IMAGE_PARTS[2][1] * (line_width) +\ 128 | BALLOON_IMAGE_PARTS[2][2] +\ 129 | RESET +\ 130 | "\n" 131 | 132 | print(result) 133 | 134 | 135 | def draw_fox(): 136 | print(FOX_IMAGE) 137 | 138 | # Main. 139 | def main(): 140 | text = None 141 | 142 | # Get text from the input. 143 | if not sys.stdin.isatty(): 144 | text = "" 145 | for line in sys.stdin: 146 | text += line 147 | text = text.replace("\n", "") 148 | 149 | # Otherwise from the arguments. 150 | if text is None and len(sys.argv) > 1: 151 | text = " ".join(sys.argv[1:]) 152 | 153 | draw_balloon(text) 154 | draw_fox() 155 | 156 | if __name__ == "__main__": 157 | main() 158 | --------------------------------------------------------------------------------