Giter Site home page Giter Site logo

shiena / ansicolor Goto Github PK

View Code? Open in Web Editor NEW
228.0 228.0 41.0 37 KB

Ansicolor library provides color console in Windows as ANSICON for Golang.

Home Page: https://pkg.go.dev/github.com/shiena/ansicolor

License: MIT License

Go 100.00%
ansi-colors go windows

ansicolor's Introduction

Github Trophy



My Qiita

My Qiita posts My Qiita contributions My Qiita followers

ansicolor's People

Contributors

cxfksword avatar johnschnake avatar parkghost avatar shiena avatar techtonik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansicolor's Issues

Determine correct window handle

When setting the terminal color, ansicolor uses the file handle syscall.Stdout for the windows system calls.

In my use case, this is not sufficient. I am compiling my go application as a windows GUI application (no terminal) and, if the command-line argument "-console" is provided, I allocate a new console.

I'm using the following syscalls for that:

procAttachConsole = kernel32.MustFindProc("AttachConsole")
procAllocConsole  = kernel32.MustFindProc("AllocConsole")
procFreeConsole   = kernel32.MustFindProc("FreeConsole")

As a result, the syscall.stdout handle (=1) is not correct, but there is no way to configure another window handle.

panic: index out of range

I got the following panic from within this library:

panic: runtime error: slice bounds out of range

goroutine 21983 [running]:
myApp/vendor/github.com/shiena/ansicolor.(*ansiColorWriter).Write(0xc0421c2000, 0xc04f2485b0, 0xc1, 0xd0, 0xd0, 0x0, 0x0)
        myApp/vendor/github.com/shiena/ansicolor/ansicolor_windows.go:384 +0x52b
myApp/vendor/github.com/sirupsen/logrus.(*Entry).write(0xc04277e060)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:247 +0x158
myApp/vendor/github.com/sirupsen/logrus.Entry.log(0xc0421cc6c0, 0xc0577a6900, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:219 +0x1c8
myApp/vendor/github.com/sirupsen/logrus.(*Entry).Log(0xc0421b9e60, 0xc000000005, 0xc057793d70, 0x1, 0x1)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:256 +0xbe
myApp/vendor/github.com/sirupsen/logrus.(*Entry).Logf(0xc0421b9e60, 0x5, 0xa889c1, 0x5f, 0xc042047440, 0x4, 0x4)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:301 +0xe6
myApp/vendor/github.com/sirupsen/logrus.(*Entry).Debugf(0xc0421b9e60, 0xa889c1, 0x5f, 0xc042047440, 0x4, 0x4)
        myApp/vendor/github.com/sirupsen/logrus/entry.go:309 +0x6c
...

The offending line is nw, err = cw.w.Write(p[first:last])

When parameter has characters which current console can not display, the next one character disappears

At printing Japanese letter on chcp 65001, they are not displayed because the font is not enough. It is not problem. But, on printing next string, the first character is not displayed though it is alphabet.

(Japanese: chcp 65001 で、日本語を出そうとすると、フォントの関係で日本語が表示されません。それ自体は当然なのですが、それに続く次回の出力で表示可能なはずの1文字が欠けてしまう問題を確認しました。表示できない文字列が入力で入ってくる以上、正常動作できなくて当然ですが、もし可能であれば何かしら対応いただけると幸いです)

package main

import (
        "fmt"
        "os"

        "github.com/shiena/ansicolor"
)

func main() {
        w := ansicolor.NewAnsiColorWriter(os.Stdout)
        fmt.Fprint(w, "Green(\x1B[32mみどり\x1b[0m)")
        fmt.Fprint(w, "Blue(\x1B[34mあお\x1B[0m)")
        fmt.Fprint(w, "\n")
}

// vim:set fenc=utf8:

chcp-932

-> No Problem

chcp-65001

-> The Problem is that Blue's B is not displayed.

Wrong background yellow on Windows 10 1903

Not sure whether it is a Windows issue or ansicolor issue.
Light yellow and white works fine, but yellow broke.
image

package main

import (
	"io"
	"os"
	"sync"

	"github.com/shiena/ansicolor"
)

type logWriter struct {
	sync.Mutex
	writer io.Writer
}

func newLogWriter(wr io.Writer) *logWriter {
	return &logWriter{writer: wr}
}

func main() {
	w := newLogWriter(ansicolor.NewAnsiColorWriter(os.Stdout))
	w.writer.Write([]byte("\x1b[43m Yellow"))
	w.writer.Write([]byte("\x1b[103m Light Yellow"))
	w.writer.Write([]byte("\x1b[47m White \x1b[0m"))
}

Unknown escape sequences cause short write

Problem was discovered when using golangs ssh package. If an application tries to output escape sequences not recognized by ansicolor (e.g. if $TERM=xterm and you run top) then a short write error occurs and the stdout pipe would break (though the connection and stdin pipe still function).

Preferably, the unrecognized sequences would just be placed into the buffer untouched.

Expose ResetColor() and SetColor()

Hi @shiena

Thanks for this wonderful library. I'm curious if there is way to expose methods in the form of

ResetColor()
SetColor(atr ...Attribute)

So we could use it with conjunction :

SetColor("\x1b[30m", "\x1b[41m") // Black foreground, red background
fmt.Println("This text will be now in red background with black foregoreund)
fmt.Printf("This too!\n")
ResetColor() 

It would be very useful to change existing by wrapping it.

This library uses something similar: https://github.com/daviddengcn/go-colortext

I also use something similar but it doesn't have any windows support: https://github.com/fatih/color#plug-into-existing-code

could not import

I try to use the code, but get the following error
go get github.com/shiena/ansicolor
can't load package: package github.com/shiena/ansicolor: no buildable Go source
files in xxxx\github.com\shiena\ansicolor

Release?

Any chance you could take a SemVer based release for those of us who use versions? Something like 1.0.0 or v1.0.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.