mirror of https://github.com/ericchiang/pup

262 changed files with 27 additions and 277806 deletions
@ -0,0 +1,27 @@
|
||||
name: test |
||||
on: |
||||
push: |
||||
branches: |
||||
- master |
||||
pull_request: |
||||
branches: |
||||
- master |
||||
|
||||
jobs: |
||||
test: |
||||
strategy: |
||||
matrix: |
||||
os: [ubuntu-latest] |
||||
go-version: [1.17.x, 1.16.x] |
||||
runs-on: ${{ matrix.os }} |
||||
steps: |
||||
- name: Install Go |
||||
uses: actions/setup-go@v2 |
||||
with: |
||||
go-version: ${{ matrix.go-version }} |
||||
- name: Checkout code |
||||
uses: actions/checkout@v2 |
||||
- name: Build |
||||
run: go build ./... |
||||
- name: Test |
||||
run: go test -v ./... |
@ -1,65 +0,0 @@
|
||||
#!/bin/bash |
||||
|
||||
set -e |
||||
|
||||
VERSION="0.4.0" |
||||
|
||||
rm -rf dist |
||||
mkdir dist |
||||
|
||||
for ENV in $( go tool dist list | grep -v 'android' | grep -v 'darwin/arm' | grep -v 's390x' | grep -v 'plan9/arm'); do |
||||
eval $( echo $ENV | tr '/' ' ' | xargs printf 'export GOOS=%s; export GOARCH=%s\n' ) |
||||
|
||||
GOOS=${GOOS:-linux} |
||||
GOARCH=${GOARCH:-amd64} |
||||
|
||||
BIN="pup" |
||||
if [ ${GOOS} == "windows" ]; then |
||||
BIN="pup.exe" |
||||
fi |
||||
|
||||
mkdir -p dist |
||||
|
||||
echo "Building for GOOS=$GOOS GOARCH=$GOARCH" |
||||
|
||||
sudo rkt run \ |
||||
--set-env=GOOS=${GOOS} \ |
||||
--set-env=GOARCH=${GOARCH} \ |
||||
--set-env=CGO_ENABLED=0 \ |
||||
--volume pup,kind=host,source=${PWD} \ |
||||
--mount volume=pup,target=/go/src/github.com/ericchiang/pup \ |
||||
--insecure-options=image \ |
||||
docker://golang:1.6.3 \ |
||||
--exec go -- build -v -a \ |
||||
-o /go/src/github.com/ericchiang/pup/dist/${BIN} \ |
||||
github.com/ericchiang/pup |
||||
|
||||
sudo rkt gc --grace-period=0s |
||||
|
||||
zip dist/pup_v${VERSION}_${GOOS}_${GOARCH}.zip -j dist/${BIN} |
||||
rm -f dist/${BIN} |
||||
done |
||||
|
||||
DARWIN_AMD64=pup_v${VERSION}_darwin_amd64.zip |
||||
DARWIN_386=pup_v${VERSION}_darwin_386.zip |
||||
|
||||
cat << EOF > pup.rb |
||||
# This file was generated by release.sh |
||||
require 'formula' |
||||
class Pup < Formula |
||||
homepage 'https://github.com/ericchiang/pup' |
||||
version '0.4.0' |
||||
|
||||
if Hardware::CPU.is_64_bit? |
||||
url 'https://github.com/ericchiang/pup/releases/download/v${VERSION}/${DARWIN_AMD64}' |
||||
sha256 '$( sha256sum dist/${DARWIN_AMD64} | awk '{ print $1 }' | xargs printf )' |
||||
else |
||||
url 'https://github.com/ericchiang/pup/releases/download/v${VERSION}/${DARWIN_386}' |
||||
sha256 '$( sha256sum dist/${DARWIN_386} | awk '{ print $1 }' | xargs printf )' |
||||
end |
||||
|
||||
def install |
||||
bin.install 'pup' |
||||
end |
||||
end |
||||
EOF |
@ -1,5 +0,0 @@
|
||||
language: go |
||||
go: |
||||
- 1.6 |
||||
- tip |
||||
|
@ -1,20 +0,0 @@
|
||||
The MIT License (MIT) |
||||
|
||||
Copyright (c) 2013 Fatih Arslan |
||||
|
||||
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. |
@ -1,154 +0,0 @@
|
||||
# Color [](http://godoc.org/github.com/fatih/color) [](https://travis-ci.org/fatih/color) |
||||
|
||||
|
||||
|
||||
Color lets you use colorized outputs in terms of [ANSI Escape |
||||
Codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors) in Go (Golang). It |
||||
has support for Windows too! The API can be used in several ways, pick one that |
||||
suits you. |
||||
|
||||
|
||||
|
||||
 |
||||
|
||||
|
||||
## Install |
||||
|
||||
```bash |
||||
go get github.com/fatih/color |
||||
``` |
||||
|
||||
## Examples |
||||
|
||||
### Standard colors |
||||
|
||||
```go |
||||
// Print with default helper functions |
||||
color.Cyan("Prints text in cyan.") |
||||
|
||||
// A newline will be appended automatically |
||||
color.Blue("Prints %s in blue.", "text") |
||||
|
||||
// These are using the default foreground colors |
||||
color.Red("We have red") |
||||
color.Magenta("And many others ..") |
||||
|
||||
``` |
||||
|
||||
### Mix and reuse colors |
||||
|
||||
```go |
||||
// Create a new color object |
||||
c := color.New(color.FgCyan).Add(color.Underline) |
||||
c.Println("Prints cyan text with an underline.") |
||||
|
||||
// Or just add them to New() |
||||
d := color.New(color.FgCyan, color.Bold) |
||||
d.Printf("This prints bold cyan %s\n", "too!.") |
||||
|
||||
// Mix up foreground and background colors, create new mixes! |
||||
red := color.New(color.FgRed) |
||||
|
||||
boldRed := red.Add(color.Bold) |
||||
boldRed.Println("This will print text in bold red.") |
||||
|
||||
whiteBackground := red.Add(color.BgWhite) |
||||
whiteBackground.Println("Red text with white background.") |
||||
``` |
||||
|
||||
### Custom print functions (PrintFunc) |
||||
|
||||
```go |
||||
// Create a custom print function for convenience |
||||
red := color.New(color.FgRed).PrintfFunc() |
||||
red("Warning") |
||||
red("Error: %s", err) |
||||
|
||||
// Mix up multiple attributes |
||||
notice := color.New(color.Bold, color.FgGreen).PrintlnFunc() |
||||
notice("Don't forget this...") |
||||
``` |
||||
|
||||
### Insert into noncolor strings (SprintFunc) |
||||
|
||||
```go |
||||
// Create SprintXxx functions to mix strings with other non-colorized strings: |
||||
yellow := color.New(color.FgYellow).SprintFunc() |
||||
red := color.New(color.FgRed).SprintFunc() |
||||
fmt.Printf("This is a %s and this is %s.\n", yellow("warning"), red("error")) |
||||
|
||||
info := color.New(color.FgWhite, color.BgGreen).SprintFunc() |
||||
fmt.Printf("This %s rocks!\n", info("package")) |
||||
|
||||
// Use helper functions |
||||
fmt.Printf("This", color.RedString("warning"), "should be not neglected.") |
||||
fmt.Printf(color.GreenString("Info:"), "an important message." ) |
||||
|
||||
// Windows supported too! Just don't forget to change the output to color.Output |
||||
fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS")) |
||||
``` |
||||
|
||||
### Plug into existing code |
||||
|
||||
```go |
||||
// Use handy standard colors |
||||
color.Set(color.FgYellow) |
||||
|
||||
fmt.Println("Existing text will now be in yellow") |
||||
fmt.Printf("This one %s\n", "too") |
||||
|
||||
color.Unset() // Don't forget to unset |
||||
|
||||
// You can mix up parameters |
||||
color.Set(color.FgMagenta, color.Bold) |
||||
defer color.Unset() // Use it in your function |
||||
|
||||
fmt.Println("All text will now be bold magenta.") |
||||
``` |
||||
|
||||
### Disable color |
||||
|
||||
There might be a case where you want to disable color output (for example to |
||||
pipe the standard output of your app to somewhere else). `Color` has support to |
||||
disable colors both globally and for single color definition. For example |
||||
suppose you have a CLI app and a `--no-color` bool flag. You can easily disable |
||||
the color output with: |
||||
|
||||
```go |
||||
|
||||
var flagNoColor = flag.Bool("no-color", false, "Disable color output") |
||||
|
||||
if *flagNoColor { |
||||
color.NoColor = true // disables colorized output |
||||
} |
||||
``` |
||||
|
||||
It also has support for single color definitions (local). You can |
||||
disable/enable color output on the fly: |
||||
|
||||
```go |
||||
c := color.New(color.FgCyan) |
||||
c.Println("Prints cyan text") |
||||
|
||||
c.DisableColor() |
||||
c.Println("This is printed without any color") |
||||
|
||||
c.EnableColor() |
||||
c.Println("This prints again cyan...") |
||||
``` |
||||
|
||||
## Todo |
||||
|
||||
* Save/Return previous values |
||||
* Evaluate fmt.Formatter interface |
||||
|
||||
|
||||
## Credits |
||||
|
||||
* [Fatih Arslan](https://github.com/fatih) |
||||
* Windows support via @mattn: [colorable](https://github.com/mattn/go-colorable) |
||||
|
||||
## License |
||||
|
||||
The MIT License (MIT) - see [`LICENSE.md`](https://github.com/fatih/color/blob/master/LICENSE.md) for more details |
||||
|
@ -1,402 +0,0 @@
|
||||
package color |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"strconv" |
||||
"strings" |
||||
|
||||
"github.com/mattn/go-colorable" |
||||
"github.com/mattn/go-isatty" |
||||
) |
||||
|
||||
// NoColor defines if the output is colorized or not. It's dynamically set to
|
||||
// false or true based on the stdout's file descriptor referring to a terminal
|
||||
// or not. This is a global option and affects all colors. For more control
|
||||
// over each color block use the methods DisableColor() individually.
|
||||
var NoColor = !isatty.IsTerminal(os.Stdout.Fd()) |
||||
|
||||
// Color defines a custom color object which is defined by SGR parameters.
|
||||
type Color struct { |
||||
params []Attribute |
||||
noColor *bool |
||||
} |
||||
|
||||
// Attribute defines a single SGR Code
|
||||
type Attribute int |
||||
|
||||
const escape = "\x1b" |
||||
|
||||
// Base attributes
|
||||
const ( |
||||
Reset Attribute = iota |
||||
Bold |
||||
Faint |
||||
Italic |
||||
Underline |
||||
BlinkSlow |
||||
BlinkRapid |
||||
ReverseVideo |
||||
Concealed |
||||
CrossedOut |
||||
) |
||||
|
||||
// Foreground text colors
|
||||
const ( |
||||
FgBlack Attribute = iota + 30 |
||||
FgRed |
||||
FgGreen |
||||
FgYellow |
||||
FgBlue |
||||
FgMagenta |
||||
FgCyan |
||||
FgWhite |
||||
) |
||||
|
||||
// Foreground Hi-Intensity text colors
|
||||
const ( |
||||
FgHiBlack Attribute = iota + 90 |
||||
FgHiRed |
||||
FgHiGreen |
||||
FgHiYellow |
||||
FgHiBlue |
||||
FgHiMagenta |
||||
FgHiCyan |
||||
FgHiWhite |
||||
) |
||||
|
||||
// Background text colors
|
||||
const ( |
||||
BgBlack Attribute = iota + 40 |
||||
BgRed |
||||
BgGreen |
||||
BgYellow |
||||
BgBlue |
||||
BgMagenta |
||||
BgCyan |
||||
BgWhite |
||||
) |
||||
|
||||
// Background Hi-Intensity text colors
|
||||
const ( |
||||
BgHiBlack Attribute = iota + 100 |
||||
BgHiRed |
||||
BgHiGreen |
||||
BgHiYellow |
||||
BgHiBlue |
||||
BgHiMagenta |
||||
BgHiCyan |
||||
BgHiWhite |
||||
) |
||||
|
||||
// New returns a newly created color object.
|
||||
func New(value ...Attribute) *Color { |
||||
c := &Color{params: make([]Attribute, 0)} |
||||
c.Add(value...) |
||||
return c |
||||
} |
||||
|
||||
// Set sets the given parameters immediately. It will change the color of
|
||||
// output with the given SGR parameters until color.Unset() is called.
|
||||
func Set(p ...Attribute) *Color { |
||||
c := New(p...) |
||||
c.Set() |
||||
return c |
||||
} |
||||
|
||||
// Unset resets all escape attributes and clears the output. Usually should
|
||||
// be called after Set().
|
||||
func Unset() { |
||||
if NoColor { |
||||
return |
||||
} |
||||
|
||||
fmt.Fprintf(Output, "%s[%dm", escape, Reset) |
||||
} |
||||
|
||||
// Set sets the SGR sequence.
|
||||
func (c *Color) Set() *Color { |
||||
if c.isNoColorSet() { |
||||
return c |
||||
} |
||||
|
||||
fmt.Fprintf(Output, c.format()) |
||||
return c |
||||
} |
||||
|
||||
func (c *Color) unset() { |
||||
if c.isNoColorSet() { |
||||
return |
||||
} |
||||
|
||||
Unset() |
||||
} |
||||
|
||||
// Add is used to chain SGR parameters. Use as many as parameters to combine
|
||||
// and create custom color objects. Example: Add(color.FgRed, color.Underline).
|
||||
func (c *Color) Add(value ...Attribute) *Color { |
||||
c.params = append(c.params, value...) |
||||
return c |
||||
} |
||||
|
||||
func (c *Color) prepend(value Attribute) { |
||||
c.params = append(c.params, 0) |
||||
copy(c.params[1:], c.params[0:]) |
||||
c.params[0] = value |
||||
} |
||||
|
||||
// Output defines the standard output of the print functions. By default
|
||||
// os.Stdout is used.
|
||||
var Output = colorable.NewColorableStdout() |
||||
|
||||
// Print formats using the default formats for its operands and writes to
|
||||
// standard output. Spaces are added between operands when neither is a
|
||||
// string. It returns the number of bytes written and any write error
|
||||
// encountered. This is the standard fmt.Print() method wrapped with the given
|
||||
// color.
|
||||
func (c *Color) Print(a ...interface{}) (n int, err error) { |
||||
c.Set() |
||||
defer c.unset() |
||||
|
||||
return fmt.Fprint(Output, a...) |
||||
} |
||||
|
||||
// Printf formats according to a format specifier and writes to standard output.
|
||||
// It returns the number of bytes written and any write error encountered.
|
||||
// This is the standard fmt.Printf() method wrapped with the given color.
|
||||
func (c *Color) Printf(format string, a ...interface{}) (n int, err error) { |
||||
c.Set() |
||||
defer c.unset() |
||||
|
||||
return fmt.Fprintf(Output, format, a...) |
||||
} |
||||
|
||||
// Println formats using the default formats for its operands and writes to
|
||||
// standard output. Spaces are always added between operands and a newline is
|
||||
// appended. It returns the number of bytes written and any write error
|
||||
// encountered. This is the standard fmt.Print() method wrapped with the given
|
||||
// color.
|
||||
func (c *Color) Println(a ...interface{}) (n int, err error) { |
||||
c.Set() |
||||
defer c.unset() |
||||
|
||||
return fmt.Fprintln(Output, a...) |
||||
} |
||||
|
||||
// PrintFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Print().
|
||||
func (c *Color) PrintFunc() func(a ...interface{}) { |
||||
return func(a ...interface{}) { c.Print(a...) } |
||||
} |
||||
|
||||
// PrintfFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Printf().
|
||||
func (c *Color) PrintfFunc() func(format string, a ...interface{}) { |
||||
return func(format string, a ...interface{}) { c.Printf(format, a...) } |
||||
} |
||||
|
||||
// PrintlnFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Println().
|
||||
func (c *Color) PrintlnFunc() func(a ...interface{}) { |
||||
return func(a ...interface{}) { c.Println(a...) } |
||||
} |
||||
|
||||
// SprintFunc returns a new function that returns colorized strings for the
|
||||
// given arguments with fmt.Sprint(). Useful to put into or mix into other
|
||||
// string. Windows users should use this in conjuction with color.Output, example:
|
||||
//
|
||||
// put := New(FgYellow).SprintFunc()
|
||||
// fmt.Fprintf(color.Output, "This is a %s", put("warning"))
|
||||
func (c *Color) SprintFunc() func(a ...interface{}) string { |
||||
return func(a ...interface{}) string { |
||||
return c.wrap(fmt.Sprint(a...)) |
||||
} |
||||
} |
||||
|
||||
// SprintfFunc returns a new function that returns colorized strings for the
|
||||
// given arguments with fmt.Sprintf(). Useful to put into or mix into other
|
||||
// string. Windows users should use this in conjuction with color.Output.
|
||||
func (c *Color) SprintfFunc() func(format string, a ...interface{}) string { |
||||
return func(format string, a ...interface{}) string { |
||||
return c.wrap(fmt.Sprintf(format, a...)) |
||||
} |
||||
} |
||||
|
||||
// SprintlnFunc returns a new function that returns colorized strings for the
|
||||
// given arguments with fmt.Sprintln(). Useful to put into or mix into other
|
||||
// string. Windows users should use this in conjuction with color.Output.
|
||||
func (c *Color) SprintlnFunc() func(a ...interface{}) string { |
||||
return func(a ...interface{}) string { |
||||
return c.wrap(fmt.Sprintln(a...)) |
||||
} |
||||
} |
||||
|
||||
// sequence returns a formated SGR sequence to be plugged into a "\x1b[...m"
|
||||
// an example output might be: "1;36" -> bold cyan
|
||||
func (c *Color) sequence() string { |
||||
format := make([]string, len(c.params)) |
||||
for i, v := range c.params { |
||||
format[i] = strconv.Itoa(int(v)) |
||||
} |
||||
|
||||
return strings.Join(format, ";") |
||||
} |
||||
|
||||
// wrap wraps the s string with the colors attributes. The string is ready to
|
||||
// be printed.
|
||||
func (c *Color) wrap(s string) string { |
||||
if c.isNoColorSet() { |
||||
return s |
||||
} |
||||
|
||||
return c.format() + s + c.unformat() |
||||
} |
||||
|
||||
func (c *Color) format() string { |
||||
return fmt.Sprintf("%s[%sm", escape, c.sequence()) |
||||
} |
||||
|
||||
func (c *Color) unformat() string { |
||||
return fmt.Sprintf("%s[%dm", escape, Reset) |
||||
} |
||||
|
||||
// DisableColor disables the color output. Useful to not change any existing
|
||||
// code and still being able to output. Can be used for flags like
|
||||
// "--no-color". To enable back use EnableColor() method.
|
||||
func (c *Color) DisableColor() { |
||||
c.noColor = boolPtr(true) |
||||
} |
||||
|
||||
// EnableColor enables the color output. Use it in conjuction with
|
||||
// DisableColor(). Otherwise this method has no side effects.
|
||||
func (c *Color) EnableColor() { |
||||
c.noColor = boolPtr(false) |
||||
} |
||||
|
||||
func (c *Color) isNoColorSet() bool { |
||||
// check first if we have user setted action
|
||||
if c.noColor != nil { |
||||
return *c.noColor |
||||
} |
||||
|
||||
// if not return the global option, which is disabled by default
|
||||
return NoColor |
||||
} |
||||
|
||||
// Equals returns a boolean value indicating whether two colors are equal.
|
||||
func (c *Color) Equals(c2 *Color) bool { |
||||
if len(c.params) != len(c2.params) { |
||||
return false |
||||
} |
||||
|
||||
for _, attr := range c.params { |
||||
if !c2.attrExists(attr) { |
||||
return false |
||||
} |
||||
} |
||||
|
||||
return true |
||||
} |
||||
|
||||
func (c *Color) attrExists(a Attribute) bool { |
||||
for _, attr := range c.params { |
||||
if attr == a { |
||||
return true |
||||
} |
||||
} |
||||
|
||||
return false |
||||
} |
||||
|
||||
func boolPtr(v bool) *bool { |
||||
return &v |
||||
} |
||||
|
||||
// Black is an convenient helper function to print with black foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Black(format string, a ...interface{}) { printColor(format, FgBlack, a...) } |
||||
|
||||
// Red is an convenient helper function to print with red foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Red(format string, a ...interface{}) { printColor(format, FgRed, a...) } |
||||
|
||||
// Green is an convenient helper function to print with green foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Green(format string, a ...interface{}) { printColor(format, FgGreen, a...) } |
||||
|
||||
// Yellow is an convenient helper function to print with yellow foreground.
|
||||
// A newline is appended to format by default.
|
||||
func Yellow(format string, a ...interface{}) { printColor(format, FgYellow, a...) } |
||||
|
||||
// Blue is an convenient helper function to print with blue foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Blue(format string, a ...interface{}) { printColor(format, FgBlue, a...) } |
||||
|
||||
// Magenta is an convenient helper function to print with magenta foreground.
|
||||
// A newline is appended to format by default.
|
||||
func Magenta(format string, a ...interface{}) { printColor(format, FgMagenta, a...) } |
||||
|
||||
// Cyan is an convenient helper function to print with cyan foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Cyan(format string, a ...interface{}) { printColor(format, FgCyan, a...) } |
||||
|
||||
// White is an convenient helper function to print with white foreground. A
|
||||
// newline is appended to format by default.
|
||||
func White(format string, a ...interface{}) { printColor(format, FgWhite, a...) } |
||||
|
||||
func printColor(format string, p Attribute, a ...interface{}) { |
||||
if !strings.HasSuffix(format, "\n") { |
||||
format += "\n" |
||||
} |
||||
|
||||
c := &Color{params: []Attribute{p}} |
||||
c.Printf(format, a...) |
||||
} |
||||
|
||||
// BlackString is an convenient helper function to return a string with black
|
||||
// foreground.
|
||||
func BlackString(format string, a ...interface{}) string { |
||||
return New(FgBlack).SprintfFunc()(format, a...) |
||||
} |
||||
|
||||
// RedString is an convenient helper function to return a string with red
|
||||
// foreground.
|
||||
func RedString(format string, a ...interface{}) string { |
||||
return New(FgRed).SprintfFunc()(format, a...) |
||||
} |
||||
|
||||
// GreenString is an convenient helper function to return a string with green
|
||||
// foreground.
|
||||
func GreenString(format string, a ...interface{}) string { |
||||
return New(FgGreen).SprintfFunc()(format, a...) |
||||
} |
||||
|
||||
// YellowString is an convenient helper function to return a string with yellow
|
||||
// foreground.
|
||||
func YellowString(format string, a ...interface{}) string { |
||||
return New(FgYellow).SprintfFunc()(format, a...) |
||||
} |
||||
|
||||
// BlueString is an convenient helper function to return a string with blue
|
||||
// foreground.
|
||||
func BlueString(format string, a ...interface{}) string { |
||||
return New(FgBlue).SprintfFunc()(format, a...) |
||||
} |
||||
|
||||
// MagentaString is an convenient helper function to return a string with magenta
|
||||
// foreground.
|
||||
func MagentaString(format string, a ...interface{}) string { |
||||
return New(FgMagenta).SprintfFunc()(format, a...) |
||||
} |
||||
|
||||
// CyanString is an convenient helper function to return a string with cyan
|
||||
// foreground.
|
||||
func CyanString(format string, a ...interface{}) string { |
||||
return New(FgCyan).SprintfFunc()(format, a...) |
||||
} |
||||
|
||||
// WhiteString is an convenient helper function to return a string with white
|
||||
// foreground.
|
||||
func WhiteString(format string, a ...interface{}) string { |
||||
return New(FgWhite).SprintfFunc()(format, a...) |
||||
} |
@ -1,114 +0,0 @@
|
||||
/* |
||||
Package color is an ANSI color package to output colorized or SGR defined |
||||
output to the standard output. The API can be used in several way, pick one |
||||
that suits you. |
||||
|
||||
Use simple and default helper functions with predefined foreground colors: |
||||
|
||||
color.Cyan("Prints text in cyan.") |
||||
|
||||
// a newline will be appended automatically
|
||||
color.Blue("Prints %s in blue.", "text") |
||||
|
||||
// More default foreground colors..
|
||||
color.Red("We have red") |
||||
color.Yellow("Yellow color too!") |
||||
color.Magenta("And many others ..") |
||||
|
||||
However there are times where custom color mixes are required. Below are some |
||||
examples to create custom color objects and use the print functions of each |
||||
separate color object. |
||||
|
||||
// Create a new color object
|
||||
c := color.New(color.FgCyan).Add(color.Underline) |
||||
c.Println("Prints cyan text with an underline.") |
||||
|
||||
// Or just add them to New()
|
||||
d := color.New(color.FgCyan, color.Bold) |
||||
d.Printf("This prints bold cyan %s\n", "too!.") |
||||
|
||||
|
||||
// Mix up foreground and background colors, create new mixes!
|
||||
red := color.New(color.FgRed) |
||||
|
||||
boldRed := red.Add(color.Bold) |
||||
boldRed.Println("This will print text in bold red.") |
||||
|
||||
whiteBackground := red.Add(color.BgWhite) |
||||
whiteBackground.Println("Red text with White background.") |
||||
|
||||
|
||||
You can create PrintXxx functions to simplify even more: |
||||
|
||||
// Create a custom print function for convenient
|
||||
red := color.New(color.FgRed).PrintfFunc() |
||||
red("warning") |
||||
red("error: %s", err) |
||||
|
||||
// Mix up multiple attributes
|
||||
notice := color.New(color.Bold, color.FgGreen).PrintlnFunc() |
||||
notice("don't forget this...") |
||||
|
||||
|
||||
Or create SprintXxx functions to mix strings with other non-colorized strings: |
||||
|
||||
yellow := New(FgYellow).SprintFunc() |
||||
red := New(FgRed).SprintFunc() |
||||
|
||||
fmt.Printf("this is a %s and this is %s.\n", yellow("warning"), red("error")) |
||||
|
||||
info := New(FgWhite, BgGreen).SprintFunc() |
||||
fmt.Printf("this %s rocks!\n", info("package")) |
||||
|
||||
Windows support is enabled by default. All Print functions works as intended. |
||||
However only for color.SprintXXX functions, user should use fmt.FprintXXX and |
||||
set the output to color.Output: |
||||
|
||||
fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS")) |
||||
|
||||
info := New(FgWhite, BgGreen).SprintFunc() |
||||
fmt.Fprintf(color.Output, "this %s rocks!\n", info("package")) |
||||
|
||||
Using with existing code is possible. Just use the Set() method to set the |
||||
standard output to the given parameters. That way a rewrite of an existing |
||||
code is not required. |
||||
|
||||
// Use handy standard colors.
|
||||
color.Set(color.FgYellow) |
||||
|
||||
fmt.Println("Existing text will be now in Yellow") |
||||
fmt.Printf("This one %s\n", "too") |
||||
|
||||
color.Unset() // don't forget to unset
|
||||
|
||||
// You can mix up parameters
|
||||
color.Set(color.FgMagenta, color.Bold) |
||||
defer color.Unset() // use it in your function
|
||||
|
||||
fmt.Println("All text will be now bold magenta.") |
||||
|
||||
There might be a case where you want to disable color output (for example to |
||||
pipe the standard output of your app to somewhere else). `Color` has support to |
||||
disable colors both globally and for single color definition. For example |
||||
suppose you have a CLI app and a `--no-color` bool flag. You can easily disable |
||||
the color output with: |
||||
|
||||
var flagNoColor = flag.Bool("no-color", false, "Disable color output") |
||||
|
||||
if *flagNoColor { |
||||
color.NoColor = true // disables colorized output
|
||||
} |
||||
|
||||
It also has support for single color definitions (local). You can |
||||
disable/enable color output on the fly: |
||||
|
||||
c := color.New(color.FgCyan) |
||||
c.Println("Prints cyan text") |
||||
|
||||
c.DisableColor() |
||||
c.Println("This is printed without any color") |
||||
|
||||
c.EnableColor() |
||||
c.Println("This prints again cyan...") |
||||
*/ |
||||
package color |
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT) |
||||
|
||||
Copyright (c) 2016 Yasuhiro Matsumoto |
||||
|
||||
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. |
@ -1,43 +0,0 @@
|
||||
# go-colorable |
||||
|
||||
Colorable writer for windows. |
||||
|
||||
For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But I don't want.) |
||||
This package is possible to handle escape sequence for ansi color on windows. |
||||
|
||||
## Too Bad! |
||||
|
||||
 |
||||
|
||||
|
||||
## So Good! |
||||
|
||||
 |
||||
|
||||
## Usage |
||||
|
||||
```go |
||||
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true}) |
||||
logrus.SetOutput(colorable.NewColorableStdout()) |
||||
|
||||
logrus.Info("succeeded") |
||||
logrus.Warn("not correct") |
||||
logrus.Error("something error") |
||||
logrus.Fatal("panic") |
||||
``` |
||||
|
||||
You can compile above code on non-windows OSs. |
||||
|
||||
## Installation |
||||
|
||||
``` |
||||
$ go get github.com/mattn/go-colorable |
||||
``` |
||||
|
||||
# License |
||||
|
||||
MIT |
||||
|
||||
# Author |
||||
|
||||
Yasuhiro Matsumoto (a.k.a mattn) |
@ -1,24 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package colorable |
||||
|
||||
import ( |
||||
"io" |
||||
"os" |
||||
) |
||||
|
||||
func NewColorable(file *os.File) io.Writer { |
||||
if file == nil { |
||||
panic("nil passed instead of *os.File to NewColorable()") |
||||
} |
||||
|
||||
return file |
||||
} |
||||
|
||||
func NewColorableStdout() io.Writer { |
||||
return os.Stdout |
||||
} |
||||
|
||||
func NewColorableStderr() io.Writer { |
||||
return os.Stderr |
||||
} |
@ -1,809 +0,0 @@
|
||||
package colorable |
||||
|
||||
import ( |
||||
"bytes" |
||||
"fmt" |
||||
"io" |
||||
"math" |
||||
"os" |
||||
"strconv" |
||||
"strings" |
||||
"syscall" |
||||
"unsafe" |
||||
|
||||
"github.com/mattn/go-isatty" |
||||
) |
||||
|
||||
const ( |
||||
foregroundBlue = 0x1 |
||||
foregroundGreen = 0x2 |
||||
foregroundRed = 0x4 |
||||
foregroundIntensity = 0x8 |
||||
foregroundMask = (foregroundRed | foregroundBlue | foregroundGreen | foregroundIntensity) |
||||
backgroundBlue = 0x10 |
||||
backgroundGreen = 0x20 |
||||
backgroundRed = 0x40 |
||||
backgroundIntensity = 0x80 |
||||
backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity) |
||||
) |
||||
|
||||
type wchar uint16 |
||||
type short int16 |
||||
type dword uint32 |
||||
type word uint16 |
||||
|
||||
type coord struct { |
||||
x short |
||||
y short |
||||
} |
||||
|
||||
type smallRect struct { |
||||
left short |
||||
top short |
||||
right short |
||||
bottom short |
||||
} |
||||
|
||||
type consoleScreenBufferInfo struct { |
||||
size coord |
||||
cursorPosition coord |
||||
attributes word |
||||
window smallRect |
||||
maximumWindowSize coord |
||||
} |
||||
|
||||
type consoleCursorInfo struct { |
||||
size dword |
||||
visible int32 |
||||
} |
||||
|
||||
var ( |
||||
kernel32 = syscall.NewLazyDLL("kernel32.dll") |
||||
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") |
||||
procSetConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute") |
||||
procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition") |
||||
procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW") |
||||
procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute") |
||||
procGetConsoleCursorInfo = kernel32.NewProc("GetConsoleCursorInfo") |
||||
procSetConsoleCursorInfo = kernel32.NewProc("SetConsoleCursorInfo") |
||||
) |
||||
|
||||
type Writer struct { |
||||
out io.Writer |
||||
handle syscall.Handle |
||||
lastbuf bytes.Buffer |
||||
oldattr word |
||||
} |
||||
|
||||
func NewColorable(file *os.File) io.Writer { |
||||
if file == nil { |
||||
panic("nil passed instead of *os.File to NewColorable()") |
||||
} |
||||
|
||||
if isatty.IsTerminal(file.Fd()) { |
||||
var csbi consoleScreenBufferInfo |
||||
handle := syscall.Handle(file.Fd()) |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) |
||||
return &Writer{out: file, handle: handle, oldattr: csbi.attributes} |
||||
} else { |
||||
return file |
||||
} |
||||
} |
||||
|
||||
func NewColorableStdout() io.Writer { |
||||
return NewColorable(os.Stdout) |
||||
} |
||||
|
||||
func NewColorableStderr() io.Writer { |
||||
return NewColorable(os.Stderr) |
||||
} |
||||
|
||||
var color256 = map[int]int{ |
||||
0: 0x000000, |
||||
1: 0x800000, |
||||
2: 0x008000, |
||||
3: 0x808000, |
||||
4: 0x000080, |
||||
5: 0x800080, |
||||
6: 0x008080, |
||||
7: 0xc0c0c0, |
||||
8: 0x808080, |
||||
9: 0xff0000, |
||||
10: 0x00ff00, |
||||
11: 0xffff00, |
||||
12: 0x0000ff, |
||||
13: 0xff00ff, |
||||
14: 0x00ffff, |
||||
15: 0xffffff, |
||||
16: 0x000000, |
||||
17: 0x00005f, |
||||
18: 0x000087, |
||||
19: 0x0000af, |
||||
20: 0x0000d7, |
||||
21: 0x0000ff, |
||||
22: 0x005f00, |
||||
23: 0x005f5f, |
||||
24: 0x005f87, |
||||
25: 0x005faf, |
||||
26: 0x005fd7, |
||||
27: 0x005fff, |
||||
28: 0x008700, |
||||
29: 0x00875f, |
||||
30: 0x008787, |
||||
31: 0x0087af, |
||||
32: 0x0087d7, |
||||
33: 0x0087ff, |
||||
34: 0x00af00, |
||||
35: 0x00af5f, |
||||
36: 0x00af87, |
||||
37: 0x00afaf, |
||||
38: 0x00afd7, |
||||
39: 0x00afff, |
||||
40: 0x00d700, |
||||
41: 0x00d75f, |
||||
42: 0x00d787, |
||||
43: 0x00d7af, |
||||
44: 0x00d7d7, |
||||
45: 0x00d7ff, |
||||
46: 0x00ff00, |
||||
47: 0x00ff5f, |
||||
48: 0x00ff87, |
||||
49: 0x00ffaf, |
||||
50: 0x00ffd7, |
||||
51: 0x00ffff, |
||||
52: 0x5f0000, |
||||
53: 0x5f005f, |
||||
54: 0x5f0087, |
||||
55: 0x5f00af, |
||||
56: 0x5f00d7, |
||||
57: 0x5f00ff, |
||||
58: 0x5f5f00, |
||||
59: 0x5f5f5f, |
||||
60: 0x5f5f87, |
||||
61: 0x5f5faf, |
||||
62: 0x5f5fd7, |
||||
63: 0x5f5fff, |
||||
64: 0x5f8700, |
||||
65: 0x5f875f, |
||||
66: 0x5f8787, |
||||
67: 0x5f87af, |
||||
68: 0x5f87d7, |
||||
69: 0x5f87ff, |
||||
70: 0x5faf00, |
||||
71: 0x5faf5f, |
||||
72: 0x5faf87, |
||||
73: 0x5fafaf, |
||||
74: 0x5fafd7, |
||||
75: 0x5fafff, |
||||
76: 0x5fd700, |
||||
77: 0x5fd75f, |
||||
78: 0x5fd787, |
||||
79: 0x5fd7af, |
||||
80: 0x5fd7d7, |
||||
81: 0x5fd7ff, |
||||
82: 0x5fff00, |
||||
83: 0x5fff5f, |
||||
84: 0x5fff87, |
||||
85: 0x5fffaf, |
||||
86: 0x5fffd7, |
||||
87: 0x5fffff, |
||||
88: 0x870000, |
||||
89: 0x87005f, |
||||
90: 0x870087, |
||||
91: 0x8700af, |
||||
92: 0x8700d7, |
||||
93: 0x8700ff, |
||||
94: 0x875f00, |
||||
95: 0x875f5f, |
||||
96: 0x875f87, |
||||
97: 0x875faf, |
||||
98: 0x875fd7, |
||||
99: 0x875fff, |
||||
100: 0x878700, |
||||
101: 0x87875f, |
||||
102: 0x878787, |
||||
103: 0x8787af, |
||||
104: 0x8787d7, |
||||
105: 0x8787ff, |
||||
106: 0x87af00, |
||||
107: 0x87af5f, |
||||
108: 0x87af87, |
||||
109: 0x87afaf, |
||||
110: 0x87afd7, |
||||
111: 0x87afff, |
||||
112: 0x87d700, |
||||
113: 0x87d75f, |
||||
114: 0x87d787, |
||||
115: 0x87d7af, |
||||
116: 0x87d7d7, |
||||
117: 0x87d7ff, |
||||
118: 0x87ff00, |
||||
119: 0x87ff5f, |
||||
120: 0x87ff87, |
||||
121: 0x87ffaf, |
||||
122: 0x87ffd7, |
||||
123: 0x87ffff, |
||||
124: 0xaf0000, |
||||
125: 0xaf005f, |
||||
126: 0xaf0087, |
||||
127: 0xaf00af, |
||||
128: 0xaf00d7, |
||||
129: 0xaf00ff, |
||||
130: 0xaf5f00, |
||||
131: 0xaf5f5f, |
||||
132: 0xaf5f87, |
||||
133: 0xaf5faf, |
||||
134: 0xaf5fd7, |
||||
135: 0xaf5fff, |
||||
136: 0xaf8700, |
||||
137: 0xaf875f, |
||||
138: 0xaf8787, |
||||
139: 0xaf87af, |
||||
140: 0xaf87d7, |
||||
141: 0xaf87ff, |
||||
142: 0xafaf00, |
||||
143: 0xafaf5f, |
||||
144: 0xafaf87, |
||||
145: 0xafafaf, |
||||
146: 0xafafd7, |
||||
147: 0xafafff, |
||||
148: 0xafd700, |
||||
149: 0xafd75f, |
||||
150: 0xafd787, |
||||
151: 0xafd7af, |
||||
152: 0xafd7d7, |
||||
153: 0xafd7ff, |
||||
154: 0xafff00, |
||||
155: 0xafff5f, |
||||
156: 0xafff87, |
||||
157: 0xafffaf, |
||||
158: 0xafffd7, |
||||
159: 0xafffff, |
||||
160: 0xd70000, |
||||
161: 0xd7005f, |
||||
162: 0xd70087, |
||||
163: 0xd700af, |
||||
164: 0xd700d7, |
||||
165: 0xd700ff, |
||||
166: 0xd75f00, |
||||
167: 0xd75f5f, |
||||
168: 0xd75f87, |
||||
169: 0xd75faf, |
||||
170: 0xd75fd7, |
||||
171: 0xd75fff, |
||||
172: 0xd78700, |
||||
173: 0xd7875f, |
||||
174: 0xd78787, |
||||
175: 0xd787af, |
||||
176: 0xd787d7, |
||||
177: 0xd787ff, |
||||
178: 0xd7af00, |
||||
179: 0xd7af5f, |
||||
180: 0xd7af87, |
||||
181: 0xd7afaf, |
||||
182: 0xd7afd7, |
||||
183: 0xd7afff, |
||||
184: 0xd7d700, |
||||
185: 0xd7d75f, |
||||
186: 0xd7d787, |
||||
187: 0xd7d7af, |
||||
188: 0xd7d7d7, |
||||
189: 0xd7d7ff, |
||||
190: 0xd7ff00, |
||||
191: 0xd7ff5f, |
||||
192: 0xd7ff87, |
||||
193: 0xd7ffaf, |
||||
194: 0xd7ffd7, |
||||
195: 0xd7ffff, |
||||
196: 0xff0000, |
||||
197: 0xff005f, |
||||
198: 0xff0087, |
||||
199: 0xff00af, |
||||
200: 0xff00d7, |
||||
201: 0xff00ff, |
||||
202: 0xff5f00, |
||||
203: 0xff5f5f, |
||||
204: 0xff5f87, |
||||
205: 0xff5faf, |
||||
206: 0xff5fd7, |
||||
207: 0xff5fff, |
||||
208: 0xff8700, |
||||
209: 0xff875f, |
||||
210: 0xff8787, |
||||
211: 0xff87af, |
||||
212: 0xff87d7, |
||||
213: 0xff87ff, |
||||
214: 0xffaf00, |
||||
215: 0xffaf5f, |
||||
216: 0xffaf87, |
||||
217: 0xffafaf, |
||||
218: 0xffafd7, |
||||
219: 0xffafff, |
||||
220: 0xffd700, |
||||
221: 0xffd75f, |
||||
222: 0xffd787, |
||||
223: 0xffd7af, |
||||
224: 0xffd7d7, |
||||
225: 0xffd7ff, |
||||
226: 0xffff00, |
||||
227: 0xffff5f, |
||||
228: 0xffff87, |
||||
229: 0xffffaf, |
||||
230: 0xffffd7, |
||||
231: 0xffffff, |
||||
232: 0x080808, |
||||
233: 0x121212, |
||||
234: 0x1c1c1c, |
||||
235: 0x262626, |
||||
236: 0x303030, |
||||
237: 0x3a3a3a, |
||||
238: 0x444444, |
||||
239: 0x4e4e4e, |
||||
240: 0x585858, |
||||
241: 0x626262, |
||||
242: 0x6c6c6c, |
||||
243: 0x767676, |
||||
244: 0x808080, |
||||
245: 0x8a8a8a, |
||||
246: 0x949494, |
||||
247: 0x9e9e9e, |
||||
248: 0xa8a8a8, |
||||
249: 0xb2b2b2, |
||||
250: 0xbcbcbc, |
||||
251: 0xc6c6c6, |
||||
252: 0xd0d0d0, |
||||
253: 0xdadada, |
||||
254: 0xe4e4e4, |
||||
255: 0xeeeeee, |
||||
} |
||||
|
||||
func (w *Writer) Write(data []byte) (n int, err error) { |
||||
var csbi consoleScreenBufferInfo |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
|
||||
er := bytes.NewBuffer(data) |
||||
loop: |
||||
for { |
||||
r1, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
if r1 == 0 { |
||||
break loop |
||||
} |
||||
|
||||
c1, _, err := er.ReadRune() |
||||
if err != nil { |
||||
break loop |
||||
} |
||||
if c1 != 0x1b { |
||||
fmt.Fprint(w.out, string(c1)) |
||||
continue |
||||
} |
||||
c2, _, err := er.ReadRune() |
||||
if err != nil { |
||||
w.lastbuf.WriteRune(c1) |
||||
break loop |
||||
} |
||||
if c2 != 0x5b { |
||||
w.lastbuf.WriteRune(c1) |
||||
w.lastbuf.WriteRune(c2) |
||||
continue |
||||
} |
||||
|
||||
var buf bytes.Buffer |
||||
var m rune |
||||
for { |
||||
c, _, err := er.ReadRune() |
||||
if err != nil { |
||||
w.lastbuf.WriteRune(c1) |
||||
w.lastbuf.WriteRune(c2) |
||||
w.lastbuf.Write(buf.Bytes()) |
||||
break loop |
||||
} |
||||
if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' { |
||||
m = c |
||||
break |
||||
} |
||||
buf.Write([]byte(string(c))) |
||||
} |
||||
|
||||
var csbi consoleScreenBufferInfo |
||||
switch m { |
||||
case 'A': |
||||
n, err = strconv.Atoi(buf.String()) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
csbi.cursorPosition.y -= short(n) |
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) |
||||
case 'B': |
||||
n, err = strconv.Atoi(buf.String()) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
csbi.cursorPosition.y += short(n) |
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) |
||||
case 'C': |
||||
n, err = strconv.Atoi(buf.String()) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
csbi.cursorPosition.x -= short(n) |
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) |
||||
case 'D': |
||||
n, err = strconv.Atoi(buf.String()) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
if n, err = strconv.Atoi(buf.String()); err == nil { |
||||
var csbi consoleScreenBufferInfo |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
csbi.cursorPosition.x += short(n) |
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) |
||||
} |
||||
case 'E': |
||||
n, err = strconv.Atoi(buf.String()) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
csbi.cursorPosition.x = 0 |
||||
csbi.cursorPosition.y += short(n) |
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) |
||||
case 'F': |
||||
n, err = strconv.Atoi(buf.String()) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
csbi.cursorPosition.x = 0 |
||||
csbi.cursorPosition.y -= short(n) |
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) |
||||
case 'G': |
||||
n, err = strconv.Atoi(buf.String()) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
csbi.cursorPosition.x = short(n) |
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) |
||||
case 'H': |
||||
token := strings.Split(buf.String(), ";") |
||||
if len(token) != 2 { |
||||
continue |
||||
} |
||||
n1, err := strconv.Atoi(token[0]) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
n2, err := strconv.Atoi(token[1]) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
csbi.cursorPosition.x = short(n2) |
||||
csbi.cursorPosition.y = short(n1) |
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition))) |
||||
case 'J': |
||||
n, err := strconv.Atoi(buf.String()) |
||||
if err != nil { |
||||
continue |
||||
} |
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) |
||||
var cursor coord |
||||
switch n { |
||||
case 0: |
||||
cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y} |
||||
case 1: |
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top} |
||||
case 2: |
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top} |
||||
} |
||||
var count, written dword |
||||
count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.size.y-csbi.cursorPosition.y)*csbi.size.x) |
||||
procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written))) |
||||
procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written))) |
||||
|