-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format/dots: print one package per line
Replace the simple implementation with something a little fancier.
- Loading branch information
Showing
19 changed files
with
984 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
=========== | ||
|
||
Copyright (c) 2015, Greg Osuri | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This package contains a striped down and modified version of | ||
https://github.com/gosuri/uilive. The original package did not work with | ||
terminal colors, and had some bits that were unnecessary for gotestsum. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*Package dotwriter implements a buffered Writer for updating progress on the | ||
terminal. | ||
*/ | ||
package dotwriter | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
) | ||
|
||
// ESC is the ASCII code for escape character | ||
const ESC = 27 | ||
|
||
// Writer buffers writes until Flush is called. Flush clears previously written | ||
// lines before writing new lines from the buffer. | ||
type Writer struct { | ||
out io.Writer | ||
buf bytes.Buffer | ||
lineCount int | ||
} | ||
|
||
// New returns a new Writer | ||
func New(out io.Writer) *Writer { | ||
return &Writer{out: out} | ||
} | ||
|
||
// Flush the buffer, writing all buffered lines to out | ||
func (w *Writer) Flush() error { | ||
if w.buf.Len() == 0 { | ||
return nil | ||
} | ||
w.clearLines() | ||
w.lineCount = bytes.Count(w.buf.Bytes(), []byte{'\n'}) | ||
_, err := w.out.Write(w.buf.Bytes()) | ||
w.buf.Reset() | ||
return err | ||
} | ||
|
||
// Write saves buf to a buffer | ||
func (w *Writer) Write(buf []byte) (int, error) { | ||
return w.buf.Write(buf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// +build !windows | ||
|
||
package dotwriter | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// clear the line and move the cursor up | ||
var clear = fmt.Sprintf("%c[%dA%c[2K", ESC, 1, ESC) | ||
|
||
func (w *Writer) clearLines() { | ||
_, _ = fmt.Fprint(w.out, strings.Repeat(clear, w.lineCount)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// +build windows | ||
|
||
package dotwriter | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
"syscall" | ||
"unsafe" | ||
|
||
isatty "github.com/mattn/go-isatty" | ||
) | ||
|
||
var kernel32 = syscall.NewLazyDLL("kernel32.dll") | ||
|
||
var ( | ||
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") | ||
procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition") | ||
procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW") | ||
) | ||
|
||
// clear the line and move the cursor up | ||
var clear = fmt.Sprintf("%c[%dA%c[2K\r", ESC, 0, ESC) | ||
|
||
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 fdWriter interface { | ||
io.Writer | ||
Fd() uintptr | ||
} | ||
|
||
func (w *Writer) clearLines() { | ||
f, ok := w.out.(fdWriter) | ||
if ok && !isatty.IsTerminal(f.Fd()) { | ||
ok = false | ||
} | ||
if !ok { | ||
_, _ = fmt.Fprint(w.out, strings.Repeat(clear, w.lineCount)) | ||
return | ||
} | ||
fd := f.Fd() | ||
var csbi consoleScreenBufferInfo | ||
_, _, _ = procGetConsoleScreenBufferInfo.Call(fd, uintptr(unsafe.Pointer(&csbi))) | ||
|
||
for i := 0; i < w.lineCount; i++ { | ||
// move the cursor up | ||
csbi.cursorPosition.y-- | ||
_, _, _ = procSetConsoleCursorPosition.Call(fd, uintptr(*(*int32)(unsafe.Pointer(&csbi.cursorPosition)))) | ||
// clear the line | ||
cursor := coord{ | ||
x: csbi.window.left, | ||
y: csbi.window.top + csbi.cursorPosition.y, | ||
} | ||
var count, w dword | ||
count = dword(csbi.size.x) | ||
_, _, _ = procFillConsoleOutputCharacter.Call(fd, uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&w))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
/*Package testjson scans test2json output and builds up a summary of the events. | ||
Events are passed to a formatter for output. | ||
*/ | ||
package testjson // import "gotest.tools/gotestsum/testjson" |
Oops, something went wrong.