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!
    
  • 相关阅读:
    开启Spring Boot 之旅
    Java笔试面试练习题---集合
    Python
    Python
    Redis -下载与基本使用
    Git
    Vue全家桶-Vue-router&Vuex
    Es6
    Vue-前端
    Django基础及实战
  • 原文地址:https://www.cnblogs.com/leafs99/p/golang_playground_clear.html
Copyright © 2011-2022 走看看