feat: init

This commit is contained in:
Reinaldy Rafli 2021-10-27 19:42:25 +07:00
commit 63062cab90
No known key found for this signature in database
GPG Key ID: CFDB9400255D8CB6
10 changed files with 1074 additions and 0 deletions

92
.github/COMMIT_CONVENTION.md vendored Normal file
View File

@ -0,0 +1,92 @@
> [conventional-changelog](https://github.com/ajoslin/conventional-changelog) [angular](https://github.com/angular/angular) preset
## Angular Convention
Angular's [commit message guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit).
### Examples
Appears under "Features" header, pencil subheader:
```xml
feat(pencil): add 'graphiteWidth' option
```
Appears under "Bug Fixes" header, graphite subheader, with a link to issue #28:
```xml
fix(graphite): stop graphite breaking when width < 0.1
Closes #28
```
Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation:
```xml
perf(pencil): remove graphiteWidth option
BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reason.
```
The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header.
```xml
revert: feat(pencil): add 'graphiteWidth' option
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
```
### Commit Message Format
A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:
```xml
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```
The **header** is mandatory and the **scope** of the header is optional.
### Revert
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
### Type
If the prefix is `feat`, `fix` or `perf`, it will appear in the changelog. However if there is any [BREAKING CHANGE](#footer), the commit will always appear in the changelog.
Other prefixes are up to your discretion. Suggested prefixes are `build`, `ci`, `docs` ,`style`, `refactor`, and `test` for non-changelog related tasks.
Details regarding these types can be found in the official [Angular Contributing Guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#type).
### Scope
The scope could be anything specifying place of the commit change. For example `$location`,
`$browser`, `$compile`, `$rootScope`, `ngHref`, `ngClick`, `ngView`, etc...
### Subject
The subject contains succinct description of the change:
* use the imperative, present tense: "change" not "changed" nor "changes"
* don't capitalize first letter
* no dot (.) at the end
### Body
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
The body should include the motivation for the change and contrast this with previous behavior.
### Footer
The footer should contain any information about **Breaking Changes** and is also the place to
reference GitHub issues that this commit **Closes**.
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.
A detailed explanation can be found in this [document][commit-message-format].
[commit-message-format]: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#

178
.github/codegen.js vendored Normal file
View File

@ -0,0 +1,178 @@
/**
* A simple codegen to generate the array of array letter
*/
const fs = require('fs/promises');
const letters =
[
`
__ _
/ _\` |
| (_| |
\\__,_|
`,
` _
| |__
| '_ \\
| |_) |
|_.__/
`,
`
___
/ __|
| (__
\\___|
`,
` _
__| |
/ _ |
| (_| |
\\__,_|
`,
`
___
/ _ \\
| __/
\\___|
`,
` __
/ _|
| |_
| _|
|_|
`,
`
__ _
/ _\` |
| (_| |
\\__, |
|___/ `,
` _
| |__
| '_ \\
| | | |
|_| |_|
`,
` _
(_)
| |
| |
|_|
`,
` _
(_)
| |
| |
_/ |
|__/ `,
` _
| | __
| |/ /
| <
|_|\\_\\
`,
` _
| |
| |
| |
|_|
`,
`
_ __ ___
| '_ \` _ \\
| | | | | |
|_| |_| |_|
`,
`
_ __
| '_ \
| | | |
|_| |_|
`,
`
___
/ _ \
| (_) |
\___/
`,
`
_ __
| '_ \
| |_) |
| .__/
|_| `,
`
__ _
/ _\` |
| (_| |
\\__, |
|_|`,
`
_ __
| '__|
| |
|_|
`,
`
___
/ __|
\\__ \\
|___/
`,
` _
| |_
| __|
| |_
\\__|
`,
`
_ _
| | | |
| |_| |
\\__,_|
`,
`
__ __
\\ \\ / /
\\ V /
\\_/
`,
`
__ __
\\ \\ /\\ / /
\\ V V /
\\_/\\_/
`,
`
__ __
\\ \\/ /
> <
/_/\\_\\
`,
`
_ _
| | | |
| |_| |
\\__, |
|___/ `,
`
____
|_ /
/ /
/___|
`,
]
;(async () => {
let output = ''
for (const letter of letters) {
let split = letter.split('\n');
output += `case "":\n`
output += `return []string{\n`
for (const s of split) {
output += '`'+s+'`,\n'
}
output += "}\n";
}
await fs.writeFile('./../generated.go', output, { encoding: 'utf-8' });
})();

41
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,41 @@
name: CI
on: [push, pull_request]
jobs:
build-test:
name: Build test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: [1.16.x, 1.17.x]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Build
run: go build ./
coverage:
name: Coverage
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x
- name: Run coverage
run: go test -v -race -coverprofile=coverage.out -covermode=atomic -failfast ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1

19
.gitignore vendored Normal file
View File

@ -0,0 +1,19 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
### Go Patch ###
/vendor/
/Godeps/

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Reinaldy Rafli <aldy505@tutanota.com>
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.

46
README.md Normal file
View File

@ -0,0 +1,46 @@
# ASCIITXT
```
Just a simple utilities for creating...
_____ _____ __ __ _____
|_ _| | ____| \ \/ / |_ _|
| | | _| \ / | |
| | | |___ / \ | |
|_| |_____| /_/\_\ |_|
_ ___ _ __ _____
| | |_ _| | |/ / | ____|
| | | | | ' / | _|
| |___ | | | . \ | |___
|_____| |___| |_|\_\ |_____|
_____ _ _ ___ ____
|_ _| | | | | |_ _| / ___|
| | | |_| | | | \___ \
| | | _ | | | ___) |
|_| |_| |_| |___| |____/
The usage is pretty straight forward, on your Go file:
import "github.com/aldy505/asciitxt"
func main() {
output := asciitxt.New("Hello world", asciitxt.Standard)
// or
output = asciitxt.WithConfig("Hello world", &asciitxt.Config{
Style: asciitxt.Standard,
})
}
What's the asciitxt.Standard, you asked.
Well, I thought it would be nice if we could have more than one style.
But, for now that's a long term plan.
My current goal is to support most unicode letters and signs.
Licensed under MIT License. See the LICENSE file.
```

67
asciitxt.go Normal file
View File

@ -0,0 +1,67 @@
package asciitxt
import (
"strings"
)
type Style int
const (
Standard Style = iota + 1
)
type Config struct {
Style Style
}
func New(txt string) string {
return WithConfig(txt, Config{Style: Standard})
}
func WithConfig(txt string, config Config) string {
if config.Style == 0 {
config.Style = Standard
}
letters := strings.Split(txt, "")
var arr [][]string
llen := getStyleLength(config.Style)
for i := 0; i < len(letters); i++ {
var temp []string
letter := getStyleLetter(config.Style, letters[i])
for j := 0; j < len(letter); j++ {
temp = append(temp, letter[j])
}
arr = append(arr, temp)
}
var output string
for k := 0; k < llen; k++ {
for l := 0; l < len(arr); l++ {
output += arr[l][k]
}
output += "\n"
}
return output
}
func getStyleLength(style Style) int {
switch style {
case Standard:
return StandardLength
default:
return 0
}
}
func getStyleLetter(style Style, letter string) []string {
switch style {
case Standard:
return getStandardLetter(letter)
default:
panic("invalid style was given")
}
}

22
asciitxt_test.go Normal file
View File

@ -0,0 +1,22 @@
package asciitxt_test
import (
"testing"
"github.com/aldy505/asciitxt"
)
func TestNew(t *testing.T) {
s := asciitxt.New("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 0123456789 _ the quick brown fox jumps over the lazy dog")
if s == "" {
t.Error("should not be empty")
}
}
func TestWithConfig(t *testing.T) {
s := asciitxt.WithConfig("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 0123456789 _ the quick brown fox jumps over the lazy dog", asciitxt.Config{})
if s == "" {
t.Error("should not be empty")
}
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module github.com/aldy505/asciitxt
go 1.17

585
standard.go Normal file
View File

@ -0,0 +1,585 @@
package asciitxt
const StandardLength = 6
func getStandardLetter(letter string) []string {
switch letter {
case "A":
return []string{
` _ `,
` / \ `,
` / _ \ `,
` / ___ \ `,
`/_/ \_\`,
` `,
}
case "B":
return []string{
` ____ `,
`| __ ) `,
`| _ \ `,
`| |_) |`,
`|____/ `,
` `,
}
case "C":
return []string{
` ____ `,
` / ___|`,
`| | `,
`| |___ `,
` \____|`,
` `,
}
case "D":
return []string{
` ____ `,
`| _ \ `,
`| | | |`,
`| |_| |`,
`|____/ `,
` `,
}
case "E":
return []string{
` _____ `,
` | ____|`,
` | _| `,
` | |___ `,
` |_____|`,
` `,
}
case "F":
return []string{
` _____ `,
`| ___|`,
`| |_ `,
`| _| `,
`|_| `,
` `,
}
case "G":
return []string{
` ____ `,
` / ___|`,
`| | _ `,
`| |_| |`,
` \____|`,
` `,
}
case "H":
return []string{
` _ _ `,
`| | | |`,
`| |_| |`,
`| _ |`,
`|_| |_|`,
` `,
}
case "I":
return []string{
` ___ `,
`|_ _|`,
` | | `,
` | | `,
`|___|`,
` `,
}
case "J":
return []string{
` _ `,
` | |`,
` _ | |`,
`| |_| |`,
` \___/ `,
` `,
}
case "K":
return []string{
` _ __`,
`| |/ /`,
`| ' / `,
`| . \ `,
`|_|\_\`,
` `,
}
case "L":
return []string{
` _ `,
`| | `,
`| | `,
`| |___ `,
`|_____|`,
` `,
}
case "M":
return []string{
` __ __ `,
`| \/ |`,
`| |\/| |`,
`| | | |`,
`|_| |_|`,
` `,
}
case "N":
return []string{
` _ _ `,
`| \ | |`,
`| \| |`,
`| |\ |`,
`|_| \_|`,
` `,
}
case "O":
return []string{
` ___ `,
` / _ \ `,
`| | | |`,
`| |_| |`,
` \___/ `,
` `,
}
case "P":
return []string{
` ____ `,
`| _ \ `,
`| |_) |`,
`| __/ `,
`|_| `,
` `,
}
case "Q":
return []string{
` ___ `,
` / _ \ `,
`| | | |`,
`| |_| |`,
` \__\_\`,
` `,
}
case "R":
return []string{
` ____ `,
`| _ \ `,
`| |_) |`,
`| _ < `,
`|_| \_\`,
` `,
}
case "S":
return []string{
` ____ `,
`/ ___| `,
`\___ \ `,
` ___) |`,
`|____/ `,
` `,
}
case "T":
return []string{
` _____ `,
`|_ _|`,
` | | `,
` | | `,
` |_| `,
` `,
}
case "U":
return []string{
` _ _ `,
`| | | |`,
`| | | |`,
`| |_| |`,
` \___/ `,
` `,
}
case "V":
return []string{
`__ __`,
`\ \ / /`,
` \ \ / / `,
` \ V / `,
` \_/ `,
` `,
}
case "W":
return []string{
`__ __`,
`\ \ / /`,
` \ \ /\ / / `,
` \ V V / `,
` \_/\_/ `,
` `,
}
case "X":
return []string{
`__ __`,
`\ \/ /`,
` \ / `,
` / \ `,
`/_/\_\`,
` `,
}
case "Y":
return []string{
`__ __`,
`\ \ / /`,
` \ V / `,
` | | `,
` |_| `,
` `,
}
case "Z":
return []string{
` _____`,
`|__ /`,
` / / `,
` / /_ `,
`/____|`,
` `,
}
case "a":
return []string{
` `,
` __ _ `,
" / _` |",
`| (_| |`,
` \__,_|`,
` `,
}
case "b":
return []string{
` _ `,
`| |__ `,
`| '_ \ `,
`| |_) |`,
`|_.__/ `,
` `,
}
case "c":
return []string{
` `,
` ___ `,
` / __|`,
`| (__ `,
` \___|`,
` `,
}
case "d":
return []string{
` _ `,
` __| |`,
` / _ |`,
`| (_| |`,
` \__,_|`,
` `,
}
case "e":
return []string{
` `,
` ___ `,
` / _ \`,
`| __/`,
` \___|`,
` `,
}
case "f":
return []string{
` __ `,
` / _|`,
`| |_ `,
`| _|`,
`|_| `,
` `,
}
case "g":
return []string{
` `,
` __ _ `,
" / _` |",
`| (_| |`,
` \__, |`,
` |___/ `,
}
case "h":
return []string{
` _ `,
`| |__ `,
`| '_ \ `,
`| | | |`,
`|_| |_|`,
` `,
}
case "i":
return []string{
` _ `,
`(_)`,
`| |`,
`| |`,
`|_|`,
` `,
}
case "j":
return []string{
` _ `,
` (_)`,
` | |`,
` | |`,
` _/ |`,
`|__/ `,
}
case "k":
return []string{
` _ `,
`| | __`,
`| |/ /`,
`| < `,
`|_|\_\`,
` `,
}
case "l":
return []string{
` _ `,
`| |`,
`| |`,
`| |`,
`|_|`,
` `,
}
case "m":
return []string{
` `,
` _ __ ___ `,
"| '_ ` _ \\ ",
`| | | | | |`,
`|_| |_| |_|`,
` `,
}
case "n":
return []string{
` `,
` _ __ `,
`| '_ \`,
`| | | |`,
`|_| |_|`,
` `,
}
case "o":
return []string{
` `,
` ___ `,
` / _ \ `,
`| (_) |`,
` \___/ `,
` `,
}
case "p":
return []string{
` `,
` _ __ `,
`| '_ \ `,
`| |_) |`,
`| .__/ `,
`|_| `,
}
case "q":
return []string{
` `,
` __ _ `,
" / _` |",
`| (_| |`,
` \__, |`,
` |_|`,
}
case "r":
return []string{
` `,
` _ __ `,
`| '__|`,
`| | `,
`|_| `,
` `,
}
case "s":
return []string{
` `,
` ___ `,
`/ __|`,
`\__ \`,
`|___/`,
` `,
}
case "t":
return []string{
` _ `,
`| |_ `,
`| __|`,
`| |_ `,
` \__|`,
` `,
}
case "u":
return []string{
` `,
` _ _ `,
`| | | |`,
`| |_| |`,
` \__,_|`,
` `,
}
case "v":
return []string{
` `,
`__ __`,
`\ \ / /`,
` \ V / `,
` \_/ `,
` `,
}
case "w":
return []string{
` `,
`__ __`,
`\ \ /\ / /`,
` \ V V / `,
` \_/\_/ `,
` `,
}
case "x":
return []string{
` `,
`__ __`,
`\ \/ /`,
` > < `,
`/_/\_\`,
` `,
}
case "y":
return []string{
` `,
` _ _ `,
`| | | |`,
`| |_| |`,
` \__, |`,
` |___/ `,
}
case "z":
return []string{
` `,
` ____`,
`|_ /`,
` / / `,
`/___|`,
` `,
}
case "0":
return []string{
` ___ `,
` / _ \ `,
`| | | |`,
`| |_| |`,
` \___/ `,
` `,
}
case "1":
return []string{
` _ `,
`/ |`,
`| |`,
`| |`,
`|_|`,
` `,
}
case "2":
return []string{
` ____ `,
`|___ \ `,
` __) |`,
` / __/ `,
`|_____|`,
` `,
}
case "3":
return []string{
` _____ `,
`|___ / `,
` |_ \ `,
` ___) |`,
`|____/ `,
` `,
}
case "4":
return []string{
` _ _ `,
`| || | `,
`| || |_ `,
`|__ _|`,
` |_| `,
` `,
}
case "5":
return []string{
` ____ `,
`| ___| `,
`|___ \ `,
` ___) |`,
`|____/ `,
` `,
}
case "6":
return []string{
` __ `,
` / /_ `,
`| '_ \ `,
`| (_) |`,
` \___/ `,
` `,
}
case "7":
return []string{
` _____ `,
`|___ |`,
` / / `,
` / / `,
` /_/ `,
` `,
}
case "8":
return []string{
` ___ `,
` ( _ ) `,
` / _ \ `,
`| (_) |`,
` \___/ `,
` `,
}
case "9":
return []string{
` ___ `,
` / _ \ `,
`| (_) |`,
` \__, |`,
` /_/ `,
` `,
}
case " ":
return []string{
` `,
` `,
` `,
` `,
` `,
` `,
}
default:
return []string{
``,
``,
``,
``,
``,
``,
}
}
}