mirror of https://github.com/aldy505/asciitxt.git
docs: add more documentation
This commit is contained in:
parent
63062cab90
commit
1ee7ff17f9
|
@ -1,7 +1,11 @@
|
||||||
# ASCIITXT
|
_ ____ ____ ___ ___ _____ __ __ _____
|
||||||
|
/ \ / ___| / ___| |_ _| |_ _| |_ _| \ \/ / |_ _|
|
||||||
|
/ _ \ \___ \ | | | | | | | | \ / | |
|
||||||
|
/ ___ \ ___) | | |___ | | | | | | / \ | |
|
||||||
|
/_/ \_\ |____/ \____| |___| |___| |_| /_/\_\ |_|
|
||||||
|
|
||||||
|
|
||||||
```
|
Just a simple utility for creating...
|
||||||
Just a simple utilities for creating...
|
|
||||||
|
|
||||||
_____ _____ __ __ _____
|
_____ _____ __ __ _____
|
||||||
|_ _| | ____| \ \/ / |_ _|
|
|_ _| | ____| \ \/ / |_ _|
|
||||||
|
@ -21,6 +25,7 @@ Just a simple utilities for creating...
|
||||||
| | | _ | | | ___) |
|
| | | _ | | | ___) |
|
||||||
|_| |_| |_| |___| |____/
|
|_| |_| |_| |___| |____/
|
||||||
|
|
||||||
|
|
||||||
The usage is pretty straight forward, on your Go file:
|
The usage is pretty straight forward, on your Go file:
|
||||||
|
|
||||||
import "github.com/aldy505/asciitxt"
|
import "github.com/aldy505/asciitxt"
|
||||||
|
@ -42,5 +47,7 @@ But, for now that's a long term plan.
|
||||||
|
|
||||||
My current goal is to support most unicode letters and signs.
|
My current goal is to support most unicode letters and signs.
|
||||||
|
|
||||||
Licensed under MIT License. See the LICENSE file.
|
See Go Package documentation for more details: https://pkg.go.dev/github.com/aldy505/asciitxt
|
||||||
```
|
|
||||||
|
Licensed under MIT License.
|
||||||
|
See the LICENSE file.
|
24
asciitxt.go
24
asciitxt.go
|
@ -1,3 +1,4 @@
|
||||||
|
// ASCIITXT is a simple utility for creating ascii texts.
|
||||||
package asciitxt
|
package asciitxt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -7,20 +8,28 @@ import (
|
||||||
type Style int
|
type Style int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Standard Style = iota + 1
|
StyleStandard Style = iota + 1
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Style Style
|
Style Style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generates a multi-line ASCII string with the default style.
|
||||||
|
// As simple as that.
|
||||||
func New(txt string) string {
|
func New(txt string) string {
|
||||||
return WithConfig(txt, Config{Style: Standard})
|
return WithConfig(txt, Config{Style: StyleStandard})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generates a multi-line ASCII string from a defined Config.
|
||||||
|
// The config itself could be empty. It'll look for its' default value.
|
||||||
|
// But if you don't intend to put any config whatsoever, please use New().
|
||||||
|
//
|
||||||
|
// Please note that this function will panic if the config.Style
|
||||||
|
// is invalid. Find the styles from the constants with Style prefix.
|
||||||
func WithConfig(txt string, config Config) string {
|
func WithConfig(txt string, config Config) string {
|
||||||
if config.Style == 0 {
|
if config.Style == 0 {
|
||||||
config.Style = Standard
|
config.Style = StyleStandard
|
||||||
}
|
}
|
||||||
|
|
||||||
letters := strings.Split(txt, "")
|
letters := strings.Split(txt, "")
|
||||||
|
@ -48,10 +57,11 @@ func WithConfig(txt string, config Config) string {
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
func getStyleLength(style Style) int {
|
func getStyleLength(style Style) int {
|
||||||
switch style {
|
switch style {
|
||||||
case Standard:
|
case StyleStandard:
|
||||||
return StandardLength
|
return standardLength
|
||||||
default:
|
default:
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -59,9 +69,9 @@ func getStyleLength(style Style) int {
|
||||||
|
|
||||||
func getStyleLetter(style Style, letter string) []string {
|
func getStyleLetter(style Style, letter string) []string {
|
||||||
switch style {
|
switch style {
|
||||||
case Standard:
|
case StyleStandard:
|
||||||
return getStandardLetter(letter)
|
return getStandardLetter(letter)
|
||||||
default:
|
default:
|
||||||
panic("invalid style was given")
|
panic("invalid style was given")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestNew(t *testing.T) {
|
||||||
}
|
}
|
||||||
func TestWithConfig(t *testing.T) {
|
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{})
|
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 == "" {
|
if s == "" {
|
||||||
t.Error("should not be empty")
|
t.Error("should not be empty")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package asciitxt
|
package asciitxt
|
||||||
|
|
||||||
const StandardLength = 6
|
const standardLength = 6
|
||||||
|
|
||||||
func getStandardLetter(letter string) []string {
|
func getStandardLetter(letter string) []string {
|
||||||
switch letter {
|
switch letter {
|
||||||
|
|
Loading…
Reference in New Issue