-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.fun
More file actions
executable file
·53 lines (42 loc) · 1.38 KB
/
progress.fun
File metadata and controls
executable file
·53 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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
*/
// 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%.
// 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)
/* Expected output:
Progress demo: 0..100
Downloading [=============================================================] 100%
Multiple phases demo
Phase 1 [=================================================================] 100%
Phase 2 [=================================================================] 100%
*/