Exemple #1
0
func winCmdOut(level string, catalog string, callin int, v ...interface{}) {
	level = strings.TrimSpace(level)
	level = strings.ToUpper(level)
	//callin = 3
	msg := fmt.Sprint(v...)
	createTime := time.Now()
	_, file, line, ok := runtime.Caller(callin)
	if !ok {
		file = "???"
		line = 0
	}
	fmt.Fprintf(os.Stderr, "%v %s:%d", createTime, file, line)

	logMsg := fmt.Sprintf("\n[%s] %s: %s\n", level, catalog, msg)

	switch level {
	case "TRACE":
		mcon.PrintMagenta(logMsg)
	case "DEBUG":
		mcon.PrintCyan(logMsg)
	case "INFO":
		mcon.PrintGreen(logMsg)
	case "WARN":
		mcon.PrintYellow(logMsg)
	case "ERROR":
		mcon.PrintRed(logMsg)
	default:
		fmt.Fprint(os.Stderr, logMsg)
	}
}
Exemple #2
0
// ReadLineWithMsg .
func ReadLineWithMsg(msgs ...interface{}) string {
	msg := fmt.Sprint(msgs...)
	if !String(msg).IsEndWith(":") {
		msg = msg + ":"
	}
	mcon.PrintGreen(msg)
	return ReadLine()
}
Exemple #3
0
func Search(path string, exts string, recursive bool, skipDirs, skipFiles, content string) {
	files := mcore.GetSubFiles(path, recursive, exts, skipDirs, skipFiles)
	for _, item := range files {
		text, err := mcore.ReadFileAll(item)
		if nil != err {
			continue
		}

		if !strings.Contains(text, content) {
			if verbose {
				fmt.Printf("File: %s not found matches\n", item)
			}
			continue
		} else {
			nums := strings.Count(text, content)
			fmt.Printf("File: %s found %d matches.\n", item, nums)
		}

		//found
		data, err := mcore.ReadFileLines(item)

		if err != nil {
			fmt.Println(err)
			continue
		}

		for lineNum, line := range data {
			if strings.Contains(line, content) {
				fmt.Printf("%d ", lineNum+1)
				lineA := mcore.String(line).Split(content)
				for i, v := range lineA {
					fmt.Printf(v)
					if i != len(lineA)-1 {
						mcon.PrintGreen(content)
					}
				}
				fmt.Println()
			}
		}
	}
}
Exemple #4
0
func Demo() {
	mcon.PrintGreen("Green\n")
}