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

Commit

Permalink
Add write() and writeCharCode() to Logger (#42)
Browse files Browse the repository at this point in the history
Add write() and writeCharCode() methods to Logger
  • Loading branch information
srawlins authored Jun 3, 2020
1 parent 94889b7 commit a4d9ff3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
## 0.2.0

- Add `Logger.write` and `Logger.writeCharCode` methods which write without
printing a trailing newline.

## 0.1.4

- Add `Ansi.reversed` getter.

## 0.1.3+2

- Update Dart SDK constraint to < 3.0.0.

## 0.1.3+1

- Update Dart SDK to 2.0.0-dev.

## 0.1.3

- In verbose mode, instead of printing the diff from the last log message,
print the total time since the tool started
- Change to not buffer the last log message sent in verbose logging mode
Expand Down
44 changes: 35 additions & 9 deletions lib/cli_logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ abstract class Logger {
/// Print trace output.
void trace(String message);

/// Print text to stdout, without a trailing newline.
void write(String message);

/// Print a character code to stdout, without a trailing newline.
void writeCharCode(int charCode);

/// Start an indeterminate progress display.
Progress progress(String message);

Expand Down Expand Up @@ -122,27 +128,39 @@ class StandardLogger implements Logger {
Progress _currentProgress;

void stderr(String message) {
if (_currentProgress != null) {
Progress progress = _currentProgress;
_currentProgress = null;
progress.cancel();
}
_cancelProgress();

io.stderr.writeln(message);
}

void stdout(String message) {
_cancelProgress();

print(message);
}

void trace(String message) {}

void write(String message) {
_cancelProgress();

io.stdout.write(message);
}

void writeCharCode(int charCode) {
_cancelProgress();

io.stdout.writeCharCode(charCode);
}

void _cancelProgress() {
if (_currentProgress != null) {
Progress progress = _currentProgress;
_currentProgress = null;
progress.cancel();
}

print(message);
}

void trace(String message) {}

Progress progress(String message) {
if (_currentProgress != null) {
Progress progress = _currentProgress;
Expand Down Expand Up @@ -260,6 +278,14 @@ class VerboseLogger implements Logger {
io.stdout.writeln('${_createPrefix()}${ansi.gray}$message${ansi.none}');
}

void write(String message) {
io.stdout.write(message);
}

void writeCharCode(int charCode) {
io.stdout.writeCharCode(charCode);
}

Progress progress(String message) => new SimpleProgress(this, message);

@Deprecated('This method will be removed in the future')
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cli_util
version: 0.1.4
version: 0.2.0
author: Dart Team <misc@dartlang.org>
description: A library to help in building Dart command-line apps.
homepage: https://github.com/dart-lang/cli_util
Expand Down

0 comments on commit a4d9ff3

Please sign in to comment.