Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 8a73cd7

Browse files
authored
Fix frozen spinner (#61)
Fixes #60 The `late final` field isn't instantiated until it is read, so without forcing instantiation in the constructor there is no timer updating the display. Move initialization back into the constructor. Other cleanup: - Remove the `_index` fields since it is otherwise identical to `_timer.ticks`. - Use a Github Action config that more closely matches our other packages. - Replace `homepage` with `repository` in the pubspec. There are no existing tests for the spinner, and adding one would be a large task - this code was not written with testability in mind. For now leave this untested.
1 parent 782a1d3 commit 8a73cd7

File tree

4 files changed

+56
-33
lines changed

4 files changed

+56
-33
lines changed

.github/workflows/build.yaml

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
1-
name: Dart
1+
name: Dart CI
22

33
on:
44
schedule:
55
# “At 00:00 (UTC) on Sunday.”
66
- cron: '0 0 * * 0'
77
pull_request:
8+
branches: [ master ]
89
push:
9-
branches:
10-
- master
10+
branches: [ master ]
11+
12+
env:
13+
PUB_ENVIRONMENT: bot.github
1114

1215
jobs:
13-
build:
16+
analyze:
1417
runs-on: ubuntu-latest
15-
16-
container:
17-
image: google/dart:dev
18-
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
sdk: [dev]
1922
steps:
20-
- uses: actions/checkout@v2
21-
22-
- name: Print Dart version
23-
run: dart --version
24-
25-
- name: pub get
26-
run: pub get
27-
28-
- name: dart format
29-
run: dart format --output=none --set-exit-if-changed .
30-
31-
- name: dart analyze
32-
run: dart analyze --fatal-infos
33-
34-
- name: dart test
35-
run: dart test
23+
- uses: actions/checkout@v2
24+
- uses: dart-lang/setup-dart@v1
25+
with:
26+
sdk: ${{ matrix.sdk }}
27+
- id: install
28+
name: Install dependencies
29+
run: dart pub get
30+
- name: Check formatting
31+
run: dart format --output=none --set-exit-if-changed .
32+
if: always() && steps.install.outcome == 'success'
33+
- name: Analyze code
34+
run: dart analyze --fatal-infos
35+
if: always() && steps.install.outcome == 'success'
36+
37+
test:
38+
needs: analyze
39+
runs-on: ${{ matrix.os }}
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
os: [ubuntu-latest]
44+
sdk: [2.12.0, dev]
45+
steps:
46+
- uses: actions/checkout@v2
47+
- uses: dart-lang/setup-dart@v1
48+
with:
49+
sdk: ${{ matrix.sdk }}
50+
- id: install
51+
name: Install dependencies
52+
run: dart pub get
53+
- name: Run tests
54+
run: dart test --test-randomize-ordering-seed=random
55+
if: always() && steps.install.outcome == 'success'

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.1
2+
3+
- Fix a bug in `AnsiProgress` where the spinning character doesn't every update.
4+
15
## 0.3.0
26

37
- Stable null safety release.

lib/cli_logging.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,12 @@ class AnsiProgress extends Progress {
200200

201201
final Ansi ansi;
202202

203-
int _index = 0;
204-
late final _timer = Timer.periodic(Duration(milliseconds: 80), (t) {
205-
_index++;
206-
_updateDisplay();
207-
});
203+
late final Timer _timer;
208204

209205
AnsiProgress(this.ansi, String message) : super(message) {
206+
_timer = Timer.periodic(Duration(milliseconds: 80), (t) {
207+
_updateDisplay();
208+
});
210209
io.stdout.write('$message... '.padRight(40));
211210
_updateDisplay();
212211
}
@@ -232,7 +231,7 @@ class AnsiProgress extends Progress {
232231
bool cancelled = false,
233232
String? message,
234233
bool showTiming = false}) {
235-
var char = kAnimationItems[_index % kAnimationItems.length];
234+
var char = kAnimationItems[_timer.tick % kAnimationItems.length];
236235
if (isFinal || cancelled) {
237236
char = '';
238237
}

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: cli_util
2-
version: 0.3.0
2+
version: 0.3.1
33
description: A library to help in building Dart command-line apps.
4-
homepage: https://github.com/dart-lang/cli_util
4+
repository: https://github.com/dart-lang/cli_util
55

66
environment:
7-
sdk: '>=2.12.0-0 <3.0.0'
7+
sdk: '>=2.12.0 <3.0.0'
88

99
dependencies:
1010
meta: ^1.3.0

0 commit comments

Comments
 (0)