#progress-bar #border #terminal #cli

borderline

一个简单的库,用于在终端中使用边框

1 个稳定版本

1.0.0 2023年11月8日

#608命令行界面

MIT 许可证

13KB
168

Borderline

Borderline 是一个用于在终端中渲染边框的库。您可以在边框内放置文本或进度条。使用方法非常简单:

use borderline::LineBuilder;

// Create a line builder:
let mut lb = LineBuilder::new();

// Print the header first:
borderline::print_header("Borderline Test-Drive");

// Now, we are able to attach as many "line" as we want.
// Every line must be started with a call to `line_begin`
// and ended with a call to `line_end`:
lb.line_begin("- Loading...");

// perform other actions here...

// When ending a line, you can specify the second part
// of the line, which will be printed on the right side:
lb.line_end("done.");

// You can also print a progress bar:
lb.line_begin("- Loading many files:");

// Set up the progress bar using the total number of steps:
lb.progress_bar_setup(1_000);

// Do some work and update the progress bar:
for i in 0..1_000 {
    sleep(std::time::Duration::from_millis(50));
    lb.progress_bar_update(i);
}

// End the progress bar:
lb.progressbar_end();

// End the line and print the second text part:
lb.line_end("done.");

// At the end, we can print the closing border:
borderline::print_border();

当进度条活动时: progressbar.png

当程序完成时: done.png

如果给定的文本太长,它将在单词边界处换行。如果不可能,文本将在给定的宽度处换行。

变更日志

版本 1.0.0

  • 首次发布

无运行时依赖