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

Commit a4d9ff3

Browse files
authored
Add write() and writeCharCode() to Logger (#42)
Add write() and writeCharCode() methods to Logger
1 parent 94889b7 commit a4d9ff3

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
## 0.2.0
2+
3+
- Add `Logger.write` and `Logger.writeCharCode` methods which write without
4+
printing a trailing newline.
5+
16
## 0.1.4
7+
28
- Add `Ansi.reversed` getter.
39

410
## 0.1.3+2
11+
512
- Update Dart SDK constraint to < 3.0.0.
613

714
## 0.1.3+1
15+
816
- Update Dart SDK to 2.0.0-dev.
917

1018
## 0.1.3
19+
1120
- In verbose mode, instead of printing the diff from the last log message,
1221
print the total time since the tool started
1322
- Change to not buffer the last log message sent in verbose logging mode

lib/cli_logging.dart

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ abstract class Logger {
8686
/// Print trace output.
8787
void trace(String message);
8888

89+
/// Print text to stdout, without a trailing newline.
90+
void write(String message);
91+
92+
/// Print a character code to stdout, without a trailing newline.
93+
void writeCharCode(int charCode);
94+
8995
/// Start an indeterminate progress display.
9096
Progress progress(String message);
9197

@@ -122,27 +128,39 @@ class StandardLogger implements Logger {
122128
Progress _currentProgress;
123129

124130
void stderr(String message) {
125-
if (_currentProgress != null) {
126-
Progress progress = _currentProgress;
127-
_currentProgress = null;
128-
progress.cancel();
129-
}
131+
_cancelProgress();
130132

131133
io.stderr.writeln(message);
132134
}
133135

134136
void stdout(String message) {
137+
_cancelProgress();
138+
139+
print(message);
140+
}
141+
142+
void trace(String message) {}
143+
144+
void write(String message) {
145+
_cancelProgress();
146+
147+
io.stdout.write(message);
148+
}
149+
150+
void writeCharCode(int charCode) {
151+
_cancelProgress();
152+
153+
io.stdout.writeCharCode(charCode);
154+
}
155+
156+
void _cancelProgress() {
135157
if (_currentProgress != null) {
136158
Progress progress = _currentProgress;
137159
_currentProgress = null;
138160
progress.cancel();
139161
}
140-
141-
print(message);
142162
}
143163

144-
void trace(String message) {}
145-
146164
Progress progress(String message) {
147165
if (_currentProgress != null) {
148166
Progress progress = _currentProgress;
@@ -260,6 +278,14 @@ class VerboseLogger implements Logger {
260278
io.stdout.writeln('${_createPrefix()}${ansi.gray}$message${ansi.none}');
261279
}
262280

281+
void write(String message) {
282+
io.stdout.write(message);
283+
}
284+
285+
void writeCharCode(int charCode) {
286+
io.stdout.writeCharCode(charCode);
287+
}
288+
263289
Progress progress(String message) => new SimpleProgress(this, message);
264290

265291
@Deprecated('This method will be removed in the future')

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: cli_util
2-
version: 0.1.4
2+
version: 0.2.0
33
author: Dart Team <[email protected]>
44
description: A library to help in building Dart command-line apps.
55
homepage: https://github.com/dart-lang/cli_util

0 commit comments

Comments
 (0)