This repository has been archived by the owner on Jun 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
677 additions
and
439 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package tty | ||
|
||
func ColorfulError(msg string) { | ||
printlnError(msg) | ||
} |
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,10 @@ | ||
package tty | ||
|
||
import ( | ||
"fmt" | ||
"github.com/logrusorgru/aurora" | ||
) | ||
|
||
func printlnError(msg string) { | ||
fmt.Println(aurora.Red(msg)) | ||
} |
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,85 @@ | ||
// +build !linux | ||
|
||
package tty | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
type color uint16 | ||
|
||
const ( | ||
Red = color(0x000C) | ||
) | ||
|
||
const ( | ||
mask = uint16(Red) | ||
) | ||
|
||
var ( | ||
kernel32 = syscall.NewLazyDLL("kernel32.dll") | ||
procGetStdHandle = kernel32.NewProc("GetStdHandle") | ||
procSetConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute") | ||
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") | ||
hStdout uintptr | ||
initScreenInfo *consoleScreenBufferInfo | ||
) | ||
|
||
func setConsoleTextAttribute(hConsoleOutput uintptr, wAttributes uint16) bool { | ||
ret, _, _ := procSetConsoleTextAttribute.Call(hConsoleOutput, uintptr(wAttributes)) | ||
return ret != 0 | ||
} | ||
|
||
type coord struct { | ||
X, Y int16 | ||
} | ||
|
||
type smallRect struct { | ||
Left, Top, Right, Bottom int16 | ||
} | ||
|
||
type consoleScreenBufferInfo struct { | ||
DwSize coord | ||
DwCursorPosition coord | ||
WAttributes uint16 | ||
SrWindow smallRect | ||
DwMaximumWindowSize coord | ||
} | ||
|
||
func getConsoleScreenBufferInfo(hConsoleOutput uintptr) *consoleScreenBufferInfo { | ||
var csbi consoleScreenBufferInfo | ||
ret, _, _ := procGetConsoleScreenBufferInfo.Call(hConsoleOutput, uintptr(unsafe.Pointer(&csbi))) | ||
if ret == 0 { | ||
return nil | ||
} | ||
return &csbi | ||
} | ||
|
||
const ( | ||
stdOutputHandle = uint32(-11 & 0xFFFFFFFF) | ||
) | ||
|
||
func init() { | ||
hStdout, _, _ = procGetStdHandle.Call(uintptr(stdOutputHandle)) | ||
initScreenInfo = getConsoleScreenBufferInfo(hStdout) | ||
} | ||
|
||
func resetColor() { | ||
if initScreenInfo == nil { | ||
return | ||
} | ||
setConsoleTextAttribute(hStdout, initScreenInfo.WAttributes) | ||
} | ||
|
||
func changeColor(c color) { | ||
attr := uint16(0) & ^mask | uint16(c) | ||
setConsoleTextAttribute(hStdout, attr) | ||
} | ||
|
||
func printlnError(msg string) { | ||
changeColor(Red) | ||
fmt.Println(msg) | ||
resetColor() | ||
} |
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,52 +1,51 @@ | ||
package verify | ||
|
||
import ( | ||
"fmt" | ||
"github.com/logrusorgru/aurora" | ||
"github.com/MegaShow/goagenda/lib/tty" | ||
"os" | ||
"regexp" | ||
"time" | ||
) | ||
|
||
func AssertTimeEqual(t1, t2 time.Time, msg string) { | ||
if t1 != t2 { | ||
fmt.Println(aurora.Red(msg)) | ||
tty.ColorfulError(msg) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
func AssertTimeNonEqual(t1, t2 time.Time, msg string) { | ||
if t1 == t2 { | ||
fmt.Println(aurora.Red(msg)) | ||
tty.ColorfulError(msg) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
func AssertReg(pattern, s, msg string) { | ||
matched, err := regexp.MatchString(pattern, s) | ||
if err != nil || !matched { | ||
fmt.Println(aurora.Red(msg)) | ||
tty.ColorfulError(msg) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
func AssertNonNil(s, msg string) { | ||
if s == "" { | ||
fmt.Println(aurora.Red(msg)) | ||
tty.ColorfulError(msg) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
func AssertLength(minLen, maxLen int, s, msg string) { | ||
if len(s) < minLen || len(s) > maxLen { | ||
fmt.Println(aurora.Red(msg)) | ||
tty.ColorfulError(msg) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
func AssertArrayLength(minLen, maxLen int, arr []string, msg string) { | ||
if len(arr) < minLen || len(arr) > maxLen { | ||
fmt.Println(aurora.Red(msg)) | ||
tty.ColorfulError(msg) | ||
os.Exit(2) | ||
} | ||
} |
Oops, something went wrong.