后端程序员之路 58、go wlog
daviddengcn/go-colortext: Change the color of console text.
https://github.com/daviddengcn/go-colortext
dixonwille/wlog: A simple logging interface that supports cross-platform color and concurrency.
https://github.com/dixonwille/wlog
package main import (
"strings"
"os"
. "github.com/dixonwille/wlog"
) func TestWLog() {
var ui UI
reader := strings.NewReader("User Input\r\n") //Simulate user typing "User Input" then pressing [enter] when reading from os.Stdin
ui = New(reader, os.Stdout, os.Stdout)
ui = AddConcurrent(ui) var addPrefixCases = []struct {
ask string
err string
inf string
log string
out string
suc string
run string
war string
}{
{" ", " ", " ", " ", " ", " ", " ", " "},
{" ", " ", " ", " ", " ", " ", " ", " "},
{Cross, Check, "!", "~", "@", "#", "+", "="},
{"%", "^", "&", "*", "@", ":", ",", "?"},
}
for _, c := range addPrefixCases {
prefix := AddPrefix(c.ask, c.err, c.inf, c.log, c.out, c.run, c.suc, c.war, ui)
prefix.Ask("Ask question", "")
prefix.Error("Error message")
prefix.Info("Info message")
prefix.Output("Output message")
prefix.Running("Running message")
prefix.Success("Success message")
prefix.Warn("Warning message")
} var addColorCases = []struct {
logColor Color
outputColor Color
successColor Color
infoColor Color
errorColor Color
warnColor Color
runningColor Color
askColor Color
responseColor Color
}{
{None, Blue, Green, Red, Yellow, Cyan, Magenta, White, Black},
{BrightBlue, BrightGreen, BrightRed, BrightYellow, BrightCyan, BrightMagenta, BrightWhite, BrightBlack, None},
}
for _, c := range addColorCases {
color := AddColor(c.askColor, c.errorColor, c.infoColor, c.logColor, c.outputColor, c.responseColor, c.runningColor, c.successColor, c.warnColor, ui)
color.Ask("Ask question", "")
color.Error("Error message")
color.Info("Info message")
color.Output("Output message")
color.Running("Running message")
color.Success("Success message")
color.Warn("Warning message")
}
}
后端程序员之路 58、go wlog的更多相关文章
- 后端程序员之路 59、go uiprogress
gosuri/uiprogress: A go library to render progress bars in terminal applicationshttps://github.com/g ...
- 后端程序员之路 43、Redis list
Redis数据类型之LIST类型 - Web程序猿 - 博客频道 - CSDN.NEThttp://blog.csdn.net/thinkercode/article/details/46565051 ...
- 后端程序员之路 22、RESTful API
理解RESTful架构 - 阮一峰的网络日志http://www.ruanyifeng.com/blog/2011/09/restful.html RESTful API 设计指南 - 阮一峰的网络日 ...
- 后端程序员之路 16、信息熵 、决策树、ID3
信息论的熵 - guisu,程序人生. 逆水行舟,不进则退. - 博客频道 - CSDN.NEThttp://blog.csdn.net/hguisu/article/details/27305435 ...
- 后端程序员之路 7、Zookeeper
Zookeeper是hadoop的一个子项目,提供分布式应用程序协调服务. Apache ZooKeeper - Homehttps://zookeeper.apache.org/ zookeeper ...
- 后端程序员之路 4、一种monitor的做法
record_t包含_sum._count._time_stamp._max._min最基础的一条记录,可以用来记录最大值.最小值.计数.总和metric_t含有RECORD_NUM(6)份recor ...
- 后端程序员之路 57、go json
go自带json处理库,位于encoding/json,里面的test很具参考意义,特别是example_test.go json - The Go Programming Languagehttps ...
- 后端程序员之路 56、go package
package分包.import导入包import . "package1" 省略前缀包名import p1 "package1" 起别名import _ & ...
- 后端程序员之路 55、go redis
redigo有点像hiredis,只提供了最基本的连接和执行命令接口. 找到个不错的redis库: https://github.com/go-redis/redis func ExampleNewC ...
随机推荐
- poj2778 DNA Sequence(AC自动机+矩阵快速幂)
Description It's well known that DNA Sequence is a sequence only contains A, C, T and G, and it's ve ...
- Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland
time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standa ...
- 牛客编程巅峰赛S1第11场 - 黄金&钻石 C.牛牛找子集 (二分)
题意:有一\(n\)个数,从中找数构成相同的子集,要求子集元素个数为\(k\),求构成子集个数最多的情况,输出子集(字典序最小). 题解:我们可以对子集的个数二分答案,首先用桶记录每个元素的个数,然后 ...
- 进程控制——fork-and-exec、system、wait
forc-and-exec流程 父进程与子进程之间的关系十分复杂,最大的复杂点在于进程间相互调用.Linux下这一流程称为fork-and-exec.父进程通过fork的方式产生一个一模一样的子进程, ...
- python xml转excle
<?xml version="1.0" encoding="UTF-8"?> <RECORDS xmlns:xsi="http:// ...
- 深入理解JavaScript垃圾回收
JavaScript中的垃圾回收是自动进行的,在平常开发中我们可能并不在意,但是深入理解JavaScript中的垃圾回收却是必要的; JavaScript 中主要的内存管理概念是 可达性,简而言之就是 ...
- u-boot 移植 --->1、u-boot配置(Kbuild)
早期的U-BOOT的裁剪是没有使用Kbuild工具的,后来就借鉴了Linux的Kbuild同时也是方便使用者裁剪,因为他的原理和Linux内核的配置裁剪原理是相同的.今天拿来分析的U-Boot的版本是 ...
- Cortex-M3 内核中悬起标志位细节逻辑
对于外设中断,如果通过NVIC_DisableIRQ(xxx)关闭对应NVIC里面的使能位,会导致对应中断Pend位置起,如果清除Pend位时不清外设的中断标志位将导致对应Pend位立刻再次置起.所以 ...
- μC/OS-III---I笔记5---多值信号量
多值信号量 操作系统中利用信号量解决进程间的同步和互斥(互斥信号量)的问题,在多道程序环境下,操作系统如何实现进程之间的同步和互斥显得极为重要.比如对同一部分资源的访问是要互斥,不能在另一个进程A在访 ...
- css sticky & 吸顶效果
css sticky & 吸顶效果 demo https://codepen.io/xgqfrms/pen/PoqyVYz css position sticky not working ht ...