github.com/unionj-cloud/go-doudou/v2@v2.3.5/toolkit/dbvendor/mysql/parser/console/console.go (about)

     1  /*
     2   * MIT License
     3   *
     4   * Copyright (c) 2021 zeromicro
     5   *
     6   * Permission is hereby granted, free of charge, to any person obtaining a copy
     7   * of this software and associated documentation files (the "Software"), to deal
     8   * in the Software without restriction, including without limitation the rights
     9   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    10   * copies of the Software, and to permit persons to whom the Software is
    11   * furnished to do so, subject to the following conditions:
    12   *
    13   * The above copyright notice and this permission notice shall be included in all
    14   * copies or substantial portions of the Software.
    15   */
    16  
    17  package console
    18  
    19  import (
    20  	"fmt"
    21  	"log"
    22  
    23  	"github.com/logrusorgru/aurora"
    24  )
    25  
    26  // Console describes an abstract printer.
    27  type Console interface {
    28  	Info(msg ...interface{})
    29  	InfoF(format string, msg ...interface{})
    30  	Debug(msg ...interface{})
    31  	DebugF(format string, msg ...interface{})
    32  	Warning(msg ...interface{})
    33  	WarningF(format string, msg ...interface{})
    34  	Error(msg ...interface{})
    35  	ErrorF(format string, msg ...interface{})
    36  	Fatal(msg ...interface{})
    37  	FatalF(format string, msg ...interface{})
    38  	Panic(msg ...interface{})
    39  	PanicF(format string, msg ...interface{})
    40  }
    41  
    42  // Assert *colorConsole implements Console.
    43  var _ Console = (*colorConsole)(nil)
    44  
    45  // NewColorConsole returns an instance of Console.
    46  func NewColorConsole() Console {
    47  	return &colorConsole{}
    48  }
    49  
    50  type colorConsole struct{}
    51  
    52  func (c *colorConsole) Info(msg ...interface{}) {
    53  	fmt.Println(aurora.Green(fmt.Sprint(msg...)))
    54  }
    55  
    56  func (c *colorConsole) InfoF(format string, a ...interface{}) {
    57  	msg := fmt.Sprintf(format, a...)
    58  	fmt.Println(aurora.Green(msg))
    59  }
    60  
    61  func (c *colorConsole) Debug(msg ...interface{}) {
    62  	fmt.Println(aurora.Blue(fmt.Sprint(msg...)))
    63  }
    64  
    65  func (c *colorConsole) DebugF(format string, a ...interface{}) {
    66  	msg := fmt.Sprintf(format, a...)
    67  	fmt.Println(aurora.Blue(msg))
    68  }
    69  
    70  func (c *colorConsole) Warning(msg ...interface{}) {
    71  	fmt.Println(aurora.Yellow(fmt.Sprint(msg...)))
    72  }
    73  
    74  func (c *colorConsole) WarningF(format string, a ...interface{}) {
    75  	msg := fmt.Sprintf(format, a...)
    76  	fmt.Println(aurora.Yellow(msg))
    77  }
    78  
    79  func (c *colorConsole) Error(msg ...interface{}) {
    80  	fmt.Println(aurora.Red(fmt.Sprint(msg...)))
    81  }
    82  
    83  func (c *colorConsole) ErrorF(format string, a ...interface{}) {
    84  	msg := fmt.Sprintf(format, a...)
    85  	fmt.Println(aurora.Red(msg))
    86  }
    87  
    88  func (c *colorConsole) Fatal(msg ...interface{}) {
    89  	log.Fatalln(fmt.Sprint(msg...))
    90  }
    91  
    92  func (c *colorConsole) FatalF(format string, a ...interface{}) {
    93  	msg := fmt.Sprintf(format, a...)
    94  	log.Fatalln(aurora.Red(msg))
    95  }
    96  
    97  func (c *colorConsole) Panic(msg ...interface{}) {
    98  	panic(fmt.Sprint(msg...))
    99  }
   100  
   101  func (c *colorConsole) PanicF(format string, a ...interface{}) {
   102  	msg := fmt.Sprintf(format, a...)
   103  	panic(msg)
   104  }