pax_global_header00006660000000000000000000000064135275262130014520gustar00rootroot0000000000000052 comment=11fc7373051f5e96eac3079061343e2899fdd9c6 qrterminal-3.0.0/000077500000000000000000000000001352752621300136765ustar00rootroot00000000000000qrterminal-3.0.0/.goreleaser000077500000000000000000000006111352752621300160300ustar00rootroot00000000000000#!/bin/bash source $HOME/.config/goreleaser.env if [ -x "$(command -v goreleaser)" ]; then goreleaser @$ else GO_SRC="/app" docker run --rm \ -v $PWD:$GO_SRC \ -v /var/run/docker.sock:/var/run/docker.sock \ -w $GO_SRC \ -e GITHUB_TOKEN=$GITHUB_TOKEN \ -e DOCKER_USERNAME=$DOCKER_USERNAME \ -e DOCKER_PASSWORD=$DOCKER_PASSWORD \ goreleaser/goreleaser $@ fi qrterminal-3.0.0/.goreleaser.yml000066400000000000000000000021621352752621300166300ustar00rootroot00000000000000# This is an example goreleaser.yaml file with some sane defaults. # Make sure to check the documentation at http://goreleaser.com before: hooks: # you may remove this if you don't use vgo - go mod download # you may remove this if you don't need go generate - go generate ./... builds: - main: ./cmd/qrterminal/main.go binary: qrterminal env: - CGO_ENABLED=0 goarch: - amd64 - 386 - arm goos: - linux - darwin - windows ignore: - goos: darwin goarch: 386 - goos: windows goarch: arm archives: - replacements: 386: i386 amd64: x86_64 checksum: name_template: 'checksums.txt' snapshot: name_template: "{{ .Tag }}-next" changelog: sort: asc filters: exclude: - '^docs:' - '^test:' brew: name: qrterminal github: owner: mdp name: homebrew-tap commit_author: name: mdp email: m@mdp.im homepage: https://github.com/mdp/qrterminal description: 'Create and display QR codes on the command line' dockers: - image_templates: - "mpercival/qrterminal:latest" - "mpercival/qrterminal:{{ .Tag }}" qrterminal-3.0.0/.travis.yml000066400000000000000000000000321352752621300160020ustar00rootroot00000000000000language: go go: - tip qrterminal-3.0.0/CHANGELOG.md000066400000000000000000000011731352752621300155110ustar00rootroot00000000000000## 3.0.0 Adjust go.mod to include required version string ## 2.0.1 Add goreleaser and release to Homebrew and Github ## 2.0.0 Add a command line tool and QuietZone around QRCode ## 1.0.1 Add go.mod ## 1.0.0 Update to add a quiet zone border to the QR Code - #5 and fixed by [WindomZ](https://github.com/WindomZ) #8 - This can be configured with the `QuietZone int` option - Defaults to 4 'pixels' wide to match the QR Code spec - This alters the size of the barcode considerably and is therefore a breaking change, resulting in a bump to v1.0.0 ## 0.2.1 Fix direction of the qr code #6 by (https://github.com/mattn) qrterminal-3.0.0/Dockerfile000066400000000000000000000000721352752621300156670ustar00rootroot00000000000000FROM scratch COPY qrterminal / ENTRYPOINT ["/qrterminal"] qrterminal-3.0.0/LICENSE000066400000000000000000000020501352752621300147000ustar00rootroot00000000000000Copyright 2019 Mark Percival 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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. qrterminal-3.0.0/Makefile000066400000000000000000000002761352752621300153430ustar00rootroot00000000000000APP ?= "./cmd/qrterminal" build: @go build "$(APP)" release: ./.goreleaser release --rm-dist reltest: ./.goreleaser release --snapshot --rm-dist --skip-publish test: @go test -cover qrterminal-3.0.0/README.md000066400000000000000000000053411352752621300151600ustar00rootroot00000000000000# QRCode Terminal [![Build Status](https://api.travis-ci.org/mdp/qrterminal.svg)](https://travis-ci.org/mdp/qrterminal) A golang library for generating QR codes in the terminal. Originally this was a port of the [NodeJS version](https://github.com/gtanner/qrcode-terminal). Recently it's been updated to allow for smaller code generation using ASCII 'half blocks' ## Example Full size ASCII block QR Code: alt text Smaller 'half blocks' in the terminal: alt text ## Install For command line usage [see below](https://github.com/mdp/qrterminal#command-line), or grab the binary from the [releases page](https://github.com/mdp/qrterminal/releases) As a library in an application `go get github.com/mdp/qrterminal/v3` ## Usage ```go import ( "github.com/mdp/qrterminal/v3" "os" ) func main() { // Generate a 'dense' qrcode with the 'Low' level error correction and write it to Stdout qrterminal.Generate("https://github.com/mdp/qrterminal", qrterminal.L, os.Stdout) } ``` ### More complicated Large Inverted barcode with medium redundancy and a 1 pixel border ```go import ( "github.com/mdp/qrterminal/v3" "os" ) func main() { config := qrterminal.Config{ Level: qrterminal.M, Writer: os.Stdout, BlackChar: qrterminal.WHITE, WhiteChar: qrterminal.BLACK, QuietZone: 1, } qrterminal.GenerateWithConfig("https://github.com/mdp/qrterminal", config) } ``` HalfBlock barcode with medium redundancy ```go import ( "github.com/mdp/qrterminal/v3" "os" ) func main() { config := qrterminal.Config{ HalfBlocks: true, Level: qrterminal.M, Writer: os.Stdout, } qrterminal.Generate("https://github.com/mdp/qrterminal", config) } ``` ## Command Line #### Installation OSX: `brew install mdp/tap/qrterminal` Others: Download from the [releases page](https://github.com/mdp/qrterminal/releases) Source: `go get -u github.com/mdp/qrterminal/v3/cmd/qrterminal` #### Usage Print out a basic QR code in your terminal: `qrterminal https://github.com/mdp/qrterminal` Using 'medium' error correction: `qrterminal https://github.com/mdp/qrterminal -l M` Or just use Docker: `docker run --rm mpercival/qrterminal:latest 'https://github.com/mdp/qrterminal'` ### Contributors/Credits: - [Mark Percival](https://github.com/mdp) - [Matthew Kennerly](https://github.com/mtkennerly) - [Viric](https://github.com/viric) - [WindomZ](https://github.com/WindomZ) - [mattn](https://github.com/mattn) qrterminal-3.0.0/cmd/000077500000000000000000000000001352752621300144415ustar00rootroot00000000000000qrterminal-3.0.0/cmd/qrterminal/000077500000000000000000000000001352752621300166175ustar00rootroot00000000000000qrterminal-3.0.0/cmd/qrterminal/main.go000066400000000000000000000031201352752621300200660ustar00rootroot00000000000000package main import ( "flag" "fmt" "os" "runtime" "strings" "github.com/mattn/go-colorable" "github.com/mdp/qrterminal/v3" "rsc.io/qr" ) var verboseFlag bool var levelFlag string var quietZoneFlag int func getLevel(s string) qr.Level { switch l := strings.ToLower(s); l { case "l": return qr.L case "m": return qr.M case "h": return qr.H default: return -1 } } func main() { flag.BoolVar(&verboseFlag, "v", false, "Output debugging information") flag.StringVar(&levelFlag, "l", "L", "Error correction level") flag.IntVar(&quietZoneFlag, "q", 2, "Size of quietzone border") flag.Parse() level := getLevel(levelFlag) if len(flag.Args()) < 1 { fmt.Fprintf(os.Stderr, "usage of %s: \"[arguments]\"\n", os.Args[0]) fmt.Println("Options:") flag.PrintDefaults() os.Exit(1) } else if level < 0 { fmt.Fprintf(os.Stderr, "Invalid error correction level: %s\n", levelFlag) fmt.Fprintf(os.Stderr, "Valid options are [L, M, H]\n") os.Exit(1) } cfg := qrterminal.Config{ Level: level, Writer: os.Stdout, QuietZone: quietZoneFlag, BlackChar: qrterminal.BLACK, WhiteChar: qrterminal.WHITE, } if verboseFlag { fmt.Fprintf(os.Stdout, "Level: %s \n", levelFlag) fmt.Fprintf(os.Stdout, "Quietzone Border Size: %d \n", quietZoneFlag) fmt.Fprintf(os.Stdout, "Encoded data: %s \n", strings.Join(flag.Args(), "\n")) fmt.Println("") } if runtime.GOOS == "windows" { cfg.Writer = colorable.NewColorableStdout() cfg.BlackChar = qrterminal.BLACK cfg.WhiteChar = qrterminal.WHITE } qrterminal.GenerateWithConfig(strings.Join(flag.Args(), "\n"), cfg) } qrterminal-3.0.0/go.mod000066400000000000000000000002131352752621300150000ustar00rootroot00000000000000module github.com/mdp/qrterminal/v3 require ( github.com/mattn/go-colorable v0.1.2 github.com/mdp/qrterminal v1.0.1 rsc.io/qr v0.2.0 ) qrterminal-3.0.0/go.sum000066400000000000000000000015351352752621300150350ustar00rootroot00000000000000github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mdp/qrterminal v1.0.1 h1:07+fzVDlPuBlXS8tB0ktTAyf+Lp1j2+2zK3fBOL5b7c= github.com/mdp/qrterminal v1.0.1/go.mod h1:Z33WhxQe9B6CdW37HaVqcRKzP+kByF3q/qLxOGe12xQ= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY= rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs= qrterminal-3.0.0/qrterminal.go000066400000000000000000000075451352752621300164160ustar00rootroot00000000000000package qrterminal import ( "io" "strings" "rsc.io/qr" ) const WHITE = "\033[47m \033[0m" const BLACK = "\033[40m \033[0m" // Use ascii blocks to form the QR Code const BLACK_WHITE = "▄" const BLACK_BLACK = " " const WHITE_BLACK = "▀" const WHITE_WHITE = "█" // Level - the QR Code's redundancy level const H = qr.H const M = qr.M const L = qr.L // default is 4-pixel-wide white quiet zone const QUIET_ZONE = 4 //Config for generating a barcode type Config struct { Level qr.Level Writer io.Writer HalfBlocks bool BlackChar string BlackWhiteChar string WhiteChar string WhiteBlackChar string QuietZone int } func (c *Config) writeFullBlocks(w io.Writer, code *qr.Code) { white := c.WhiteChar black := c.BlackChar // Frame the barcode in a 1 pixel border w.Write([]byte(stringRepeat(stringRepeat(white, code.Size+c.QuietZone*2)+"\n", c.QuietZone))) // top border for i := 0; i <= code.Size; i++ { w.Write([]byte(stringRepeat(white, c.QuietZone))) // left border for j := 0; j <= code.Size; j++ { if code.Black(j, i) { w.Write([]byte(black)) } else { w.Write([]byte(white)) } } w.Write([]byte(stringRepeat(white, c.QuietZone-1) + "\n")) // right border } w.Write([]byte(stringRepeat(stringRepeat(white, code.Size+c.QuietZone*2)+"\n", c.QuietZone-1))) // bottom border } func (c *Config) writeHalfBlocks(w io.Writer, code *qr.Code) { ww := c.WhiteChar bb := c.BlackChar wb := c.WhiteBlackChar bw := c.BlackWhiteChar // Frame the barcode in a 4 pixel border // top border if c.QuietZone%2 != 0 { w.Write([]byte(stringRepeat(bw, code.Size+c.QuietZone*2) + "\n")) w.Write([]byte(stringRepeat(stringRepeat(ww, code.Size+c.QuietZone*2)+"\n", c.QuietZone/2))) } else { w.Write([]byte(stringRepeat(stringRepeat(ww, code.Size+c.QuietZone*2)+"\n", c.QuietZone/2))) } for i := 0; i <= code.Size; i += 2 { w.Write([]byte(stringRepeat(ww, c.QuietZone))) // left border for j := 0; j <= code.Size; j++ { next_black := false if i+1 < code.Size { next_black = code.Black(j, i+1) } curr_black := code.Black(j, i) if curr_black && next_black { w.Write([]byte(bb)) } else if curr_black && !next_black { w.Write([]byte(bw)) } else if !curr_black && !next_black { w.Write([]byte(ww)) } else { w.Write([]byte(wb)) } } w.Write([]byte(stringRepeat(ww, c.QuietZone-1) + "\n")) // right border } // bottom border if c.QuietZone%2 == 0 { w.Write([]byte(stringRepeat(stringRepeat(ww, code.Size+c.QuietZone*2)+"\n", c.QuietZone/2-1))) w.Write([]byte(stringRepeat(wb, code.Size+c.QuietZone*2) + "\n")) } else { w.Write([]byte(stringRepeat(stringRepeat(ww, code.Size+c.QuietZone*2)+"\n", c.QuietZone/2))) } } func stringRepeat(s string, count int) string { if count <= 0 { return "" } return strings.Repeat(s, count) } // GenerateWithConfig expects a string to encode and a config func GenerateWithConfig(text string, config Config) { if config.QuietZone < 1 { config.QuietZone = 1 // at least 1-pixel-wide white quiet zone } w := config.Writer code, _ := qr.Encode(text, config.Level) if config.HalfBlocks { config.writeHalfBlocks(w, code) } else { config.writeFullBlocks(w, code) } } // Generate a QR Code and write it out to io.Writer func Generate(text string, l qr.Level, w io.Writer) { config := Config{ Level: l, Writer: w, BlackChar: BLACK, WhiteChar: WHITE, QuietZone: QUIET_ZONE, } GenerateWithConfig(text, config) } // Generate a QR Code with half blocks and write it out to io.Writer func GenerateHalfBlock(text string, l qr.Level, w io.Writer) { config := Config{ Level: l, Writer: w, HalfBlocks: true, BlackChar: BLACK_BLACK, WhiteBlackChar: WHITE_BLACK, WhiteChar: WHITE_WHITE, BlackWhiteChar: BLACK_WHITE, QuietZone: QUIET_ZONE, } GenerateWithConfig(text, config) } qrterminal-3.0.0/qrterminal_test.go000066400000000000000000000015531352752621300174460ustar00rootroot00000000000000package qrterminal import ( "os" "testing" ) func TestGenerate(t *testing.T) { Generate("https://github.com/mdp/qrterminal", L, os.Stdout) } func TestGenerateWithConfig(t *testing.T) { config := Config{ Level: M, Writer: os.Stdout, BlackChar: WHITE, // Inverted WhiteChar: BLACK, QuietZone: QUIET_ZONE, } GenerateWithConfig("https://github.com/mdp/qrterminal", config) } func TestGenerateHalfBlock(t *testing.T) { GenerateHalfBlock("https://github.com/mdp/qrterminal", L, os.Stdout) } func TestGenerateWithHalfBlockConfig(t *testing.T) { config := Config{ Level: M, Writer: os.Stdout, HalfBlocks: true, BlackChar: BLACK_BLACK, WhiteBlackChar: WHITE_BLACK, WhiteChar: WHITE_WHITE, BlackWhiteChar: BLACK_WHITE, QuietZone: 3, } GenerateWithConfig("https://github.com/mdp/qrterminal", config) }