-
Notifications
You must be signed in to change notification settings - Fork 40
/
example_test.go
38 lines (31 loc) · 951 Bytes
/
example_test.go
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
package pb
import (
"log"
time "github.com/vadv/gopher-lua-libs/time"
lua "github.com/yuin/gopher-lua"
)
func ExampleAllParams() {
state := lua.NewState()
Preload(state)
time.Preload(state)
source := `
local pb = require('pb')
local time = require('time')
local count = 2
local bar = pb.new(count)
local template = string.format('%s {{ counters . }} {{percent . }} {{ etime . }}', '[custom template]')
err = bar:configure({writer='stdout', refresh_rate=3001, template=template})
if err then error(err) end
bar:start()
for i=1, count, 1 do
time.sleep(1)
bar:increment()
end
bar:finish()
`
if err := state.DoString(source); err != nil {
log.Fatal(err.Error())
}
// Output:
// [custom template] 2 / 2 100.00% 2s
}