zoukankan      html  css  js  c++  java
  • Golang Playground 进度条示例

    Golang Playground 进度条示例

    package main
    
    import (
    	"fmt"
    	"strings"
    	"time"
    )
    
    func main() {
    	const col = 30
    	// Clear the screen by printing x0c.
    	bar := fmt.Sprintf("x0c[%%-%vs]", col)
    	for i := 0; i < col; i++ {
    		fmt.Printf(bar, strings.Repeat("=", i)+">")
    		time.Sleep(100 * time.Millisecond)
    	}
    	fmt.Printf(bar+" Done!", strings.Repeat("=", col))
    }
    
    
    • 符号 x0c
    Oct Dec Char Hex CTRL Key Comments
    14 12 FF x0C ^L f (Form feed)

    换页符

    • bar := fmt.Sprintf("x0c[%%-%vs]", col) 会生成 "%-30s",其中 - 表示左对齐,不足的部分使用空白填充,30 表示需要填充的长度,x0c 起到 clear 的作用
    • bar 可以再次作为格式化的字符串使用

    输出:

    [======>                       ]
    ...
    [============================> ]
    ...
    [==============================] Done!
    
  • 相关阅读:
    2-Rsync备份-全网备份
    1-Rsync备份-备份概述
    复杂声明学习总结
    EasyExcel的用法
    listvue
    解决Error: Cannot find module 'node-sass'问题
    Webpack
    babel的使用
    nodejs的使用
    vue入门
  • 原文地址:https://www.cnblogs.com/leafs99/p/golang_playground_clear.html
Copyright © 2011-2022 走看看