https://github.com/derv-dice/cfull
Simple Golang package to set RGB color of Terminal output
https://github.com/derv-dice/cfull
color fmt go golang output terminal
Last synced: 5 months ago
JSON representation
Simple Golang package to set RGB color of Terminal output
- Host: GitHub
- URL: https://github.com/derv-dice/cfull
- Owner: derv-dice
- License: mit
- Created: 2020-03-31T17:02:13.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-31T06:03:50.000Z (almost 6 years ago)
- Last Synced: 2026-01-15T06:56:56.165Z (5 months ago)
- Topics: color, fmt, go, golang, output, terminal
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cfull
Simple Golang package to set RGB color of fmt.Print output
> It has only one method - SetRGB, but this is enought to do full-color output in Terminal using `fmt.Print()`
>> You can use https://htmlcolorcodes.com/ to pick RGB color
## Using examples
### 1. Set only foreground color
- foreground =  `RGB(0, 153, 204)`
```golang
myColor := cfull.Color{
ColorFG: cfull.RGB{0, 153, 204},
}
fmt.Println(cfull.SetRGB("Hello, World!", myColor))
```
### 2. Set only background color
- background =  `RGB(231, 76, 60)`
```golang
myColor := cfull.Color{
ColorBG: cfull.RGB{231, 76, 60},
}
fmt.Println(cfull.SetRGB("Hello, World!", myColor))
```
### 3. Set background and foreground
- foreground =  `RGB(0, 0, 0)`
- background =  `RGB(231, 76, 60)`
```golang
myColor := cfull.Color{
ColorFG: cfull.RGB{0, 0, 0},
ColorBG: cfull.RGB{231, 76, 60},
}
fmt.Println(cfull.SetRGB("Hello, World!", myColor))
```
## Output exaple
```golang
ColorOne := cfull.Color{
ColorFG: cfull.RGB{0, 153, 204},
}
ColorTwo := cfull.Color{
ColorBG: cfull.RGB{231, 76, 60},
}
ColorThree := cfull.Color{
ColorFG: cfull.RGB{0, 0, 0},
ColorBG: cfull.RGB{231, 76, 60},
}
fmt.Println(cfull.SetRGB("Hello, World!", ColorOne))
fmt.Println(cfull.SetRGB("Hello, World!", ColorTwo))
fmt.Println(cfull.SetRGB("Hello, World!", ColorThree))
fmt.Println(
cfull.SetRGB("You can", ColorOne),
cfull.SetRGB("use different styles", ColorTwo),
cfull.SetRGB("in one output", ColorThree),
)
// returns:
```

## Another way
You can make colorfull output without this package (Please, star if it helps).
All you need is use one of construtcions below. Just place it into fmt.Print()
### 1. RGB Foreground:
```golang
// Set color by changing nums 255
fmt.Sprintf("\033[38;2;%d;%d;%dm%s\033[0m", 255, 255, 255, YourStringText)
```
### 2. RGB Background:
```golang
// Set color by changing nums 255
fmt.Sprintf("\033[48;2;%d;%d;%dm%s\033[0m", 255, 255, 255, YourStringText)
```
### 3. RGB Foreground + RGB Background:
```golang
// Set foreground color by changing first three numbers and background by changing last 3 numbers"
fmt.Sprintf("\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm%s\033[0m", 255, 255, 255, 255, 255, 255, YourStringText)
```