Merge pull request #5 from GeneWang1226/release chore(release): sync documentation updates to mainRelease
Merge pull request #5 from GeneWang1226/release
chore(release): sync documentation updates to mainRelease
A pure-functional, zero-overhead, iterator-wrapping progress bar library for MoonBit, inspired by Python’s tqdm.
tqdm
中文文档
Iter[T]
update()
render()
BarStyle
moon add
# Add the latest version moon add GeneWang1226/tqdmoon # Or add a specific version moon add GeneWang1226/tqdmoon@0.1.1
Add to your moon.pkg:
moon.pkg
import { "GeneWang1226/tqdmoon", }
fn main { let items = [1, 2, 3, 4, 5].iter() for x in @tqdmoon.tqdm(items, total=Some(5)) { ignore(x) } }
Output: |████████████████████| 100% 5/5 [00:00<00:00, 30138.6 items/s]
|████████████████████| 100% 5/5 [00:00<00:00, 30138.6 items/s]
for x in @tqdmoon.tqdm([10, 20, 30].iter()) { ignore(x) }
Output: 3 items [00:00, 405405.4 items/s]
3 items [00:00, 405405.4 items/s]
Four built-in presets:
// tqdmoon_classic — default, solid block @tqdmoon.tqdm(items, total=Some(5), style=@tqdmoon.tqdmoon_classic) // tqdmoon_ascii — ASCII characters @tqdmoon.tqdm(items, total=Some(5), style=@tqdmoon.tqdmoon_ascii) // tqdmoon_style — moon phase icons @tqdmoon.tqdm(items, total=Some(5), style=@tqdmoon.tqdmoon_style) // tqdmoon_google — fun meme, chainable @tqdmoon.tqdm(items, total=Some(5)).set_style(@tqdmoon.tqdmoon_google)
Preview:
tqdmoon_classic
|████████░░░░░░░░░░░░| 50% 5/10
tqdmoon_ascii
[=====> ] 25%
tqdmoon_style
|🌕🌕🌕🌕🌕🌑🌑🌑🌑🌑| 50%
tqdmoon_google
tqdmooooooooooooooooooooon 100%
Construct a BarStyle to customize appearance:
let my_style = @tqdmoon.BarStyle::{ left: "(", right: ")", fill: "#", head: "", tail: "", empty: "-", width: 30, is_prefix: false, } for x in @tqdmoon.tqdm(items, total=Some(10), style=my_style) { ignore(x) }
// Create a progress bar pub fn[T] tqdm( iterable : Iter[T], total~ : Option[Int] = None, style~ : BarStyle = tqdmoon_classic, ) -> Tqdm[T] // Chainable skin switcher (returns a new instance) pub fn[T] Tqdm::set_style(self : Tqdm[T], style : BarStyle) -> Tqdm[T]
left
String
right
fill
head
tail
empty
width
Int
is_prefix
Bool
Run from the tqdmoon/ package directory:
tqdmoon/
cd tqdmoon # Run unit tests (22 cases) moon test # Run the skin showcase demo moon run cmd/main
tqdmoon/ ├── moon.pkg # Package dependency declaration ├── tqdmoon.mbt # Core library code ├── tqdmoon_test.mbt # Black-box tests (public API) ├── tqdmoon_wbtest.mbt # White-box tests (internal functions) └── cmd/main/ ├── moon.pkg └── main.mbt # Skin comparison demo
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802047560号
tqdmoon
中文文档
Features
Iter[T]in; counting, rendering, and terminal flushing are all automaticupdate()orrender()BarStyleImport
Using
moon add(Recommended)Manual Import
Add to your
moon.pkg:Quick Start
Basic Usage (with total)
Output:
|████████████████████| 100% 5/5 [00:00<00:00, 30138.6 items/s]Fallback Mode (without total)
Output:
3 items [00:00, 405405.4 items/s]Skins
Four built-in presets:
Preview:
tqdmoon_classic|████████░░░░░░░░░░░░| 50% 5/10tqdmoon_ascii[=====> ] 25%tqdmoon_style|🌕🌕🌕🌕🌕🌑🌑🌑🌑🌑| 50%tqdmoon_googletqdmooooooooooooooooooooon 100%Custom Skin
Construct a
BarStyleto customize appearance:API
BarStyle
leftStringrightStringfillStringheadStringtailStringemptyStringwidthIntis_prefixBooltqdmoon_google)Testing
Run from the
tqdmoon/package directory:Directory Structure