zoukankan      html  css  js  c++  java
  • 后端程序员之路 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
    ") //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")
        }
    }
    

      

  • 相关阅读:
    USTC 软硕讯飞班参考资源
    nginx 负载均衡
    Meidawiki 配置
    10 款实用的jquery插件
    Mongodb 定时释放内存
    互联网产品精神解读
    简单的缓冲区溢出实验
    fatal error C1902: 程序数据库管理器不匹配;请检查安装解决
    C#的override、new、vitutal一例
    SQL Server 2008导入、导出数据库
  • 原文地址:https://www.cnblogs.com/zapline/p/7736044.html
Copyright © 2011-2022 走看看