ansicolor icon indicating copy to clipboard operation
ansicolor copied to clipboard

Determine correct window handle

Open maja42 opened this issue 6 years ago • 1 comments

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.

maja42 avatar Feb 22 '19 14:02 maja42

I managed to solve this issue by overwriting syscall.Stdout, syscall.Stderr and syscall.Stdin to the streams acquired after creating a new terminal window (Before, my code only overwrote os.Stdout/err/in).

I suppose it is not an intended use case to overwrite these exported variables, but on the other hand go itself doesn't seep to support attaching different terminal windows at runtime.

So this issue can be closed from my side.

maja42 avatar Mar 11 '19 12:03 maja42