progress_bar

所属分类:collect
开发工具:Crystal
文件大小:0KB
下载次数:0
上传日期:2023-04-10 13:24:13
上 传 者sh-1993
说明:  Crystal编程语言的ProgressBar实现,
(A ProgressBar implementation for the Crystal programming language,)

文件列表:
LICENSE (1061, 2023-04-10)
demo.gif (381181, 2023-04-10)
doc/ (0, 2023-04-10)
doc/IllegalCharSetException.html (2194, 2023-04-10)
doc/ProgressBarException.html (2364, 2023-04-10)
doc/ProgressCharsetException.html (1897, 2023-04-10)
doc/ProgressExceededException.html (1901, 2023-04-10)
doc/Progressbar.html (13268, 2023-04-10)
doc/css/ (0, 2023-04-10)
doc/css/style.css (6733, 2023-04-10)
doc/index.html (5214, 2023-04-10)
doc/js/ (0, 2023-04-10)
doc/js/doc.js (3757, 2023-04-10)
docs/ (0, 2023-04-10)
docs/ProgressBar.html (14628, 2023-04-10)
docs/ProgressCharsetException.html (2340, 2023-04-10)
docs/ProgressExceededException.html (2344, 2023-04-10)
docs/css/ (0, 2023-04-10)
docs/css/style.css (10510, 2023-04-10)
docs/index.html (5679, 2023-04-10)
docs/index.json (19087, 2023-04-10)
docs/js/ (0, 2023-04-10)
docs/js/doc.js (29573, 2023-04-10)
docs/search-index.js (19122, 2023-04-10)
example.cr (563, 2023-04-10)
shard.yml (102, 2023-04-10)
spec/ (0, 2023-04-10)
spec/progress_bar_spec.cr (2971, 2023-04-10)
src/ (0, 2023-04-10)
src/progress_bar.cr (3583, 2023-04-10)

# ProgressBar.cr ###### This project is being built weekly with the latest crystal version (works with v1.7.2 ) ![progress animation](https://github.com/tpei/progress_bar.cr/raw/master/demo.gif) ## Installation Add to your shard.yml ```yaml dependencies: progress_bar.cr: github: tpei/progress_bar.cr branch: master ``` and then install the library into your project with ```bash $ shards install ``` ## Usage ```crystal require "require "progress_bar.cr/progress_bar"" # simple pb = ProgressBar.new # print empty progress bar pb.init pb.message("Setting up now...") 10.times do sleep 0.1 # very time intense! pb.tick # increase bar progress by 1 end # => Setting up now... # => [##########] ``` ### Block Usage You can use the `with_progress` block to automatically reset and clean up the progress bar after your block is done. Block usage will also print the completion_message, even if you don't completely fill the bar. ```crystal pb = ProgressBar.new(completion_message: "DONE?") pb.with_progress do pb.init 5.times do sleep 0.1 # very time intense! pb.tick # increase bar progress by 1 end end # => [######## ] # => DONE? ``` ### Available Methods ```crystal pb.init # prints empty bar pb.tick: # increases bar filling by one and reprints pb.message: # allows for printing progress messages pb.progress(by: 10) # increases bar by desired number pb.set(5) # set bar to given number pb.set?(5) # try setting bar => true / false pb.count # get current count pb.reset # resets the progress bar to 0, without redrawing, making it pb.complete # prints finish message, sets bar to max reusable ``` ## initialize options - ticks: length the bar is made for. calling #tick more often raises an error (default is 10) - show_percentage: true / false - whether or not to display the percentage next to the bar - completion_message: message to be displayed after progress reaches 100% - charset / chars: characters to display for bar ### Characters The bar basically consists of two different types of characters: one signifying emptiness, one a filled state. There are a number of different predefined char sets, that you can use: - :default => [##### ] - :line => [----- ] - :equals => [===== ] - :bar => [█████] `ProgressBar.new(charset: :equals)` You can also just hand in two characters of your own choosing: `ProgressBar.new(chars: ["O", "X"] # => [XXXXX00000]` ## Errors Don't exceed the tick number, will throw an exception! ```crystal # count already == ticks begin pb.tick # => (ProgressExceededException) rescue puts "Sorry, installation taking longer than expected" end sleep 0.1 ```

近期下载者

相关文件


收藏者