├── .github └── dependabot.yml ├── LICENSE ├── README.md ├── go.mod ├── go.sum ├── quirky.go └── screenshots └── url.png /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | updates: 4 | - package-ecosystem: gomod 5 | directory: / 6 | schedule: 7 | interval: daily 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Jeppe Toustrup 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QuiRky 2 | 3 | A command line QR code printer inspired by "because I can" mentality and "not invented here" syndrome. 4 | 5 | 6 | ## Usage 7 | 8 | ``` 9 | $ quirky --help 10 | Usage: quirky [options] [text | -] 11 | 12 | Specify "-" or just nothing to read from stdin. 13 | 14 | Options: 15 | -d Make QR code double size 16 | -i Invert colors 17 | ``` 18 | 19 | 20 | ## Screenshots 21 | 22 | ![URL](screenshots/url.png) 23 | 24 | 25 | ## Installation 26 | 27 | If you have [Go](https://golang.org/) installed, then you should simply run: 28 | 29 | ``` 30 | go get github.com/Tenzer/quirky 31 | ``` 32 | 33 | and you will get the `quirky` executable inside `$GOPATH/bin`. 34 | 35 | 36 | ## Change log 37 | 38 | ### 1.0.2 - 2021-05-23 39 | * Switch dependencies to use go modules 40 | * Update all dependencies 41 | 42 | ### 1.0.1 - 2018-10-22 43 | * Updated dependencies 44 | 45 | ### 1.0.0 - 2016-06-09 46 | * Initial release 47 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Tenzer/quirky 2 | 3 | go 1.12 4 | 5 | require github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= 2 | github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= 3 | -------------------------------------------------------------------------------- /quirky.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "flag" 6 | "fmt" 7 | "os" 8 | "strings" 9 | 10 | qrcode "github.com/skip2/go-qrcode" 11 | ) 12 | 13 | var doubleSize = flag.Bool("d", false, "Make QR code double size") 14 | var inverted = flag.Bool("i", false, "Invert colors") 15 | 16 | func normal() { 17 | if *inverted { 18 | fmt.Print("\x1b[0m") 19 | } else { 20 | fmt.Print("\x1b[7m") 21 | } 22 | } 23 | 24 | func invert() { 25 | if *inverted { 26 | fmt.Print("\x1b[7m") 27 | } else { 28 | fmt.Print("\x1b[0m") 29 | } 30 | } 31 | 32 | func printCode(bitmap [][]bool) { 33 | width := len(bitmap) 34 | height := len(bitmap[0]) 35 | 36 | for y := 0; y < width; y += 2 { 37 | lastInverted := false 38 | if !*inverted { 39 | lastInverted = true 40 | normal() 41 | } 42 | 43 | for x := 0; x < height; x++ { 44 | upper := bitmap[y][x] 45 | 46 | var lower bool 47 | if y+1 < width { 48 | lower = bitmap[y+1][x] 49 | } else { 50 | lower = false 51 | } 52 | 53 | if upper == lower { 54 | if upper && !lastInverted { 55 | invert() 56 | lastInverted = true 57 | } else if !upper && lastInverted { 58 | normal() 59 | lastInverted = false 60 | } 61 | fmt.Print(" ") 62 | } else { 63 | if upper && !lastInverted { 64 | invert() 65 | lastInverted = true 66 | } else if !upper && lastInverted { 67 | normal() 68 | lastInverted = false 69 | } 70 | fmt.Print("▄") 71 | } 72 | } 73 | fmt.Println("\x1b[0m") 74 | } 75 | } 76 | 77 | func printCodeDouble(bitmap [][]bool) { 78 | width := len(bitmap) 79 | height := len(bitmap[0]) 80 | 81 | for y := 0; y < width; y++ { 82 | lastInverted := false 83 | if !*inverted { 84 | lastInverted = true 85 | normal() 86 | } 87 | 88 | for x := 0; x < height; x++ { 89 | if bitmap[y][x] && !lastInverted { 90 | invert() 91 | lastInverted = true 92 | } else if !bitmap[y][x] && lastInverted { 93 | normal() 94 | lastInverted = false 95 | } 96 | fmt.Print(" ") 97 | } 98 | fmt.Println("\x1b[0m") 99 | } 100 | } 101 | 102 | func main() { 103 | flag.Usage = func() { 104 | fmt.Fprintf(os.Stderr, "Usage: %s [options] [text | -]\n\n", os.Args[0]) 105 | fmt.Fprintln(os.Stderr, " Specify \"-\" or just nothing to read from stdin.") 106 | fmt.Fprintln(os.Stderr) 107 | fmt.Fprintln(os.Stderr, "Options:") 108 | flag.PrintDefaults() 109 | } 110 | flag.Parse() 111 | 112 | data := flag.Args() 113 | var dataString string 114 | if len(data) > 1 { 115 | flag.Usage() 116 | os.Exit(1) 117 | } else if len(data) == 0 || data[0] == "-" { 118 | input := bufio.NewReader(os.Stdin) 119 | line, _, _ := input.ReadLine() 120 | dataString = strings.TrimSpace(string(line[:])) 121 | } else { 122 | dataString = strings.TrimSpace(data[0]) 123 | } 124 | 125 | if len(dataString) == 0 { 126 | fmt.Println("No data was provided") 127 | os.Exit(1) 128 | } 129 | 130 | qr, err := qrcode.New(dataString, qrcode.Low) 131 | if err != nil { 132 | fmt.Println(err) 133 | os.Exit(1) 134 | } 135 | 136 | if *doubleSize { 137 | printCodeDouble(qr.Bitmap()) 138 | } else { 139 | printCode(qr.Bitmap()) 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /screenshots/url.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tenzer/quirky/c900cb2dcee09e2f2380573e193d0d90d908893f/screenshots/url.png --------------------------------------------------------------------------------