Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
feat: Changed default branch name
Browse files Browse the repository at this point in the history
- Changed default branch name to main.
- Added GitHub action.
- Updated .gitignore.
- Improved tests.
- Updated go.mod version to 1.15.
- Updated README.md
  • Loading branch information
Taliesin Millhouse committed Nov 28, 2020
1 parent fe89613 commit 1ef66b1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 29 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Test
run: |
go test -v ./...
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
*.out

# Text editors/IDEs
.vscode
.vscode/
__debug_bin
.idea
.idea/

# Directories.
dist
bin/
dist/

# Env files
# Env files.
*.env
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# little colors
## A package for ANSI color formatting

![GitHub tag (latest SemVer pre-release)](https://img.shields.io/github/v/tag/gofor-little/colors?include_prereleases)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gofor-little/colors)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://raw.githubusercontent.com/gofor-little/colors/main/LICENSE)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/gofor-little/colors/Go)
[![Go Report Card](https://goreportcard.com/badge/github.com/gofor-little/colors)](https://goreportcard.com/report/github.com/gofor-little/colors)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/gofor-little/colors)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![GitHub release](https://img.shields.io/github/v/release/gofor-little/colors?include_prereleases)](https://github.com/gofor-little/colors/releases )
[![PkgGoDev](https://pkg.go.dev/badge/github.com/gofor-little/colors)](https://pkg.go.dev/github.com/gofor-little/colors)

## Example
### Introduction
* ANSI color formatting for consoles
* No dependencies outside the standard library

### Example
```go
package main

Expand Down Expand Up @@ -34,7 +40,8 @@ func main() {
fmt.Println(colors.WhiteBright("WhiteBright"))
}
```
![](https://github.com/gofor-little/colors/blob/main/example-dark.png)
![](https://github.com/gofor-little/colors/blob/main/example-light.png)

## Output
![](https://github.com/gofor-little/colors/blob/master/example-dark.png)
![](https://github.com/gofor-little/colors/blob/master/example-light.png)
### Testing
Run ```go test ./...``` in the root directory.
47 changes: 31 additions & 16 deletions colors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,35 @@ import (
)

func TestColors(t *testing.T) {
fmt.Println(colors.Black("Black"))
fmt.Println(colors.BlackBright("BlackBright"))
fmt.Println(colors.Red("Red"))
fmt.Println(colors.RedBright("RedBright"))
fmt.Println(colors.Green("Green"))
fmt.Println(colors.GreenBright("GreenBright"))
fmt.Println(colors.Yellow("Yellow"))
fmt.Println(colors.YellowBright("YellowBright"))
fmt.Println(colors.Blue("Blue"))
fmt.Println(colors.BlueBright("BlueBright"))
fmt.Println(colors.Magenta("Magenta"))
fmt.Println(colors.MagentaBright("MagentaBright"))
fmt.Println(colors.Cyan("Cyan"))
fmt.Println(colors.CyanBright("CyanBright"))
fmt.Println(colors.White("White"))
fmt.Println(colors.WhiteBright("WhiteBright"))
testCases := []struct {
name string
color func(...interface{}) string
s string
want string
}{
{name: "Test_colors.Black()", color: colors.Black, s: "Black", want: fmt.Sprintf("\u001B[1;30m%s\u001B[0m", "Black")},
{name: "Test_colors.BlackBright()", color: colors.BlackBright, s: "BlackBright", want: fmt.Sprintf("\u001B[1;90m%s\u001B[0m", "BlackBright")},
{name: "Test_colors.Red()", color: colors.Red, s: "Red", want: fmt.Sprintf("\u001B[1;31m%s\u001B[0m", "Red")},
{name: "Test_colors.RedBright()", color: colors.RedBright, s: "RedBright", want: fmt.Sprintf("\u001B[1;91m%s\u001B[0m", "RedBright")},
{name: "Test_colors.Green()", color: colors.Green, s: "Green", want: fmt.Sprintf("\u001B[1;32m%s\u001B[0m", "Green")},
{name: "Test_colors.GreenBright()", color: colors.GreenBright, s: "GreenBright", want: fmt.Sprintf("\u001B[1;92m%s\u001B[0m", "GreenBright")},
{name: "Test_colors.Yellow()", color: colors.Yellow, s: "Yellow", want: fmt.Sprintf("\u001B[1;33m%s\u001B[0m", "Yellow")},
{name: "Test_colors.YellowBright()", color: colors.YellowBright, s: "YellowBright", want: fmt.Sprintf("\u001B[1;93m%s\u001B[0m", "YellowBright")},
{name: "Test_colors.Blue()", color: colors.Blue, s: "Blue", want: fmt.Sprintf("\u001B[1;34m%s\u001B[0m", "Blue")},
{name: "Test_colors.BlueBright()", color: colors.BlueBright, s: "BlueBright", want: fmt.Sprintf("\u001B[1;94m%s\u001B[0m", "BlueBright")},
{name: "Test_colors.Magenta()", color: colors.Magenta, s: "Magenta", want: fmt.Sprintf("\u001B[1;35m%s\u001B[0m", "Magenta")},
{name: "Test_colors.MagentaBright()", color: colors.MagentaBright, s: "MagentaBright", want: fmt.Sprintf("\u001B[1;95m%s\u001B[0m", "MagentaBright")},
{name: "Test_colors.Cyan()", color: colors.Cyan, s: "Cyan", want: fmt.Sprintf("\u001B[1;36m%s\u001B[0m", "Cyan")},
{name: "Test_colors.CyanBright()", color: colors.CyanBright, s: "CyanBright", want: fmt.Sprintf("\u001B[1;96m%s\u001B[0m", "CyanBright")},
{name: "Test_colors.White()", color: colors.White, s: "White", want: fmt.Sprintf("\u001B[1;37m%s\u001B[0m", "White")},
{name: "Test_colors.WhiteBright()", color: colors.WhiteBright, s: "WhiteBright", want: fmt.Sprintf("\u001B[1;97m%s\u001B[0m", "WhiteBright")},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if got := tc.color(tc.s); got != tc.want {
t.Fatalf("unexpected result returned from string: %s, wanted: %s, got: %s", tc.s, tc.want, got)
}
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/gofor-little/colors

go 1.13
go 1.15

0 comments on commit 1ef66b1

Please sign in to comment.