From e3cafeaf9292f67459ff1d186f68283bfaedf2ae Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 31 Jan 2022 00:27:37 +0100 Subject: Add dependencies/vendor (whatsapp) --- vendor/github.com/mdp/qrterminal/.travis.yml | 4 + vendor/github.com/mdp/qrterminal/CHANGELOG.md | 11 ++ vendor/github.com/mdp/qrterminal/README.md | 78 +++++++++++++ vendor/github.com/mdp/qrterminal/qrterminal.go | 153 +++++++++++++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 vendor/github.com/mdp/qrterminal/.travis.yml create mode 100644 vendor/github.com/mdp/qrterminal/CHANGELOG.md create mode 100644 vendor/github.com/mdp/qrterminal/README.md create mode 100644 vendor/github.com/mdp/qrterminal/qrterminal.go (limited to 'vendor/github.com/mdp/qrterminal') diff --git a/vendor/github.com/mdp/qrterminal/.travis.yml b/vendor/github.com/mdp/qrterminal/.travis.yml new file mode 100644 index 00000000..b54e2c3e --- /dev/null +++ b/vendor/github.com/mdp/qrterminal/.travis.yml @@ -0,0 +1,4 @@ +language: go + +go: + - tip diff --git a/vendor/github.com/mdp/qrterminal/CHANGELOG.md b/vendor/github.com/mdp/qrterminal/CHANGELOG.md new file mode 100644 index 00000000..f4d10b1b --- /dev/null +++ b/vendor/github.com/mdp/qrterminal/CHANGELOG.md @@ -0,0 +1,11 @@ +## 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) diff --git a/vendor/github.com/mdp/qrterminal/README.md b/vendor/github.com/mdp/qrterminal/README.md new file mode 100644 index 00000000..e8beb315 --- /dev/null +++ b/vendor/github.com/mdp/qrterminal/README.md @@ -0,0 +1,78 @@ +# QRCode Terminal + +[![Build Status](https://secure.travis-ci.org/mdp/qrterminal.png)](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 + +`go get github.com/mdp/qrterminal` + +## Usage + +```go +import ( + "github.com/mdp/qrterminal" + "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" + "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" + "os" + ) + +func main() { + config := qrterminal.Config{ + HalfBlocks: true, + Level: qrterminal.M, + Writer: os.Stdout, + } + qrterminal.Generate("https://github.com/mdp/qrterminal", config) +} +``` + +Credits: + +Mark Percival m@mdp.im +[Matthew Kennerly](https://github.com/mtkennerly) +[Viric](https://github.com/viric) +[WindomZ](https://github.com/WindomZ) +[mattn](https://github.com/mattn) diff --git a/vendor/github.com/mdp/qrterminal/qrterminal.go b/vendor/github.com/mdp/qrterminal/qrterminal.go new file mode 100644 index 00000000..c44a13c4 --- /dev/null +++ b/vendor/github.com/mdp/qrterminal/qrterminal.go @@ -0,0 +1,153 @@ +package 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) +} -- cgit v1.2.3