Added some progress bar foo to Console class. (0.37.48)
This commit is contained in:
parent
231c738016
commit
44cf629016
5 changed files with 147 additions and 7 deletions
42
examples/progress.fun
Executable file
42
examples/progress.fun
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2026-01-12
|
||||
*/
|
||||
|
||||
// Demonstrates system library includes after installation to /usr/lib/fun
|
||||
|
||||
// includes can also be done with a leading # like in C, but some programmers maybe like more clean code without a
|
||||
// leading #.
|
||||
include <io/console.fun>
|
||||
include <utils/datetime.fun> // for sleep()
|
||||
|
||||
c = Console()
|
||||
|
||||
print("Progress demo: 0..100")
|
||||
|
||||
total = 100
|
||||
for i in range(0, total + 1)
|
||||
c.progress(i, total, "Downloading")
|
||||
sleep(30) // milliseconds
|
||||
|
||||
print("\nMultiple phases demo")
|
||||
|
||||
// Phase 1
|
||||
phase_total = 40
|
||||
for i in range(0, phase_total + 1)
|
||||
c.progress(i, phase_total, "Phase 1")
|
||||
sleep(20)
|
||||
|
||||
// Phase 2
|
||||
phase_total = 60
|
||||
for i in range(0, phase_total + 1)
|
||||
c.progress(i, phase_total, "Phase 2")
|
||||
sleep(15)
|
||||
29
examples/progress_inline.fun
Normal file
29
examples/progress_inline.fun
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2026 Johannes Findeisen
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2026-01-13
|
||||
*/
|
||||
|
||||
// Realtime progress bar demo without printing extra newlines.
|
||||
// It only updates a single console line in-place. The progress()
|
||||
// helper emits one trailing newline automatically at 100%.
|
||||
|
||||
include <io/console.fun>
|
||||
include <utils/datetime.fun> // for sleep()
|
||||
|
||||
c = Console()
|
||||
|
||||
total = 100
|
||||
for i in range(0, total + 1)
|
||||
c.progress(i, total, "Downloading")
|
||||
sleep(20) // milliseconds
|
||||
|
||||
// Done. No additional prints/newlines here; progress() already
|
||||
// finalized the line when it reached 100%.
|
||||
Loading…
Add table
Add a link
Reference in a new issue