Contains utilities for the Dart VM's dart:io
.
NOTE: Due to the changing nature of the Dart SDK (towards 2.0.0), running
dartfmt
requires the local executable:
$ pub run dart_style:format
io.dart
isExecutable
#Returns whether a provided file path is considered executable on the host operating system.
ExitCode
#An enum
-like class that contains known exit codes.
ProcessManager
#A higher-level service for spawning and communicating with processes.
spawn
to create a process with std[in|out|err] forwarded by default/// Runs `dartfmt` commands and `pub publish`.
Future<Null> main() async {
final manager = new ProcessManager();
// Runs dartfmt --version and outputs the result via stdout.
print('Running dartfmt --version');
var spawn = await manager.spawn('dartfmt', ['--version']);
await spawn.exitCode;
// Runs dartfmt -n . and outputs the result via stdout.
print('Running dartfmt -n .');
spawn = await manager.spawn('dartfmt', ['-n', '.']);
await spawn.exitCode;
// Runs pub publish. Upon hitting a blocking stdin state, you may directly
// output to the processes's stdin via your own, similar to how a bash or
// shell script would spawn a process.
print('Running pub publish');
spawn = await manager.spawn('pub', ['publish']);
await spawn.exitCode;
// Closes stdin for the entire program.
await sharedStdIn.terminate();
}
sharedStdIn
#A safer version of the default stdin
stream from dart:io
that allows a
subscriber to cancel their subscription, and then allows a new subscriber to
start listening. This differs from the default behavior where only a single
listener is ever allowed in the application lifecycle:
test('should allow multiple subscribers', () async {
final logs = <String>[];
final asUtf8 = sharedStdIn.transform(UTF8.decoder);
// Wait for input for the user.
logs.add(await asUtf8.first);
// Wait for more input for the user.
logs.add(await asUtf8.first);
expect(logs, ['Hello World', 'Goodbye World']);
});
For testing, an instance of SharedStdIn
may be created directly.
ansi.dart
import 'dart:io' as io;
import 'package:io/ansi.dart';
void main() {
// To use one style, call the `wrap` method on one of the provided top-level
// values.
io.stderr.writeln(red.wrap("Bad error!"));
// To use multiple styles, call `wrapWith`.
print(wrapWith('** Important **', [red, styleBold, styleUnderlined]));
// The wrap functions will simply return the provided value unchanged if
// `ansiOutputEnabled` is false.
//
// You can override the value `ansiOutputEnabled` by wrapping code in
// `overrideAnsiOutput`.
overrideAnsiOutput(false, () {
assert('Normal text' == green.wrap('Normal text'));
});
}
Updates for Dart 2 constants. Require at least Dart 2.0.0-dev.54
.
Fix the type of StartProcess
typedef to match Process.start
from
dart:io
.
ansi.dart
ansiOutputEnabled
value. Affects
the escapeForScript
property on AnsiCode
and the wrap
and wrapWith
functions when forScript
is true.ansi.dart
Added forScript
named argument to top-level wrapWith
function.
AnsiCode
Added String get escapeForScript
property.
Added forScript
named argument to wrap
function.
SharedStdIn.nextLine
(similar to readLineSync
) and lines
:main() async {
// Prints the first line entered on stdin.
print(await sharedStdIn.nextLine());
// Prints all remaining lines.
await for (final line in sharedStdIn.lines) {
print(line);
}
}
Added a copyPath
and copyPathSync
function, similar to cp -R
.
Added a dependency on package:path
.
Added the remaining missing arguments to ProcessManager.spawnX
which
forward to Process.start
. It is now an interchangeable function for running
a process.
arguments
argument to ProcessManager.spawn
is
now positional (not named) and required. This makes it more similar to the
built-in Process.start
, and easier to use as a drop in replacement:main() {
processManager.spawn('dart', ['--version']);
}
Fixed a bug where processes created from ProcessManager.spawn
could not
have their stdout
/stderr
read through their respective getters (a runtime
error was always thrown).
Added ProcessMangaer#spawnBackground
, which does not forward stdin
.
Added ProcessManager#spawnDetached
, which does not forward any I/O.
Added the shellSplit()
function, which parses a list of arguments in the
same manner as the POSIX shell.
FutureOr<bool> String isExecutable(path)
.ExitCode
ProcessManager
and Spawn
sharedStdIn
and SharedStdIn
ansi.dart
library with support for formatting terminal outputAdd this to your package's pubspec.yaml file:
dependencies:
io: ^0.3.3
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:io/io.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.3.3 | Jul 12, 2018 |
|
|
0.3.2+1 | Jan 31, 2018 |
|
|
0.3.2 | Jan 30, 2018 |
|
|
0.3.1 | Dec 1, 2017 |
|
|
0.3.0 | Oct 12, 2017 |
|
|
0.2.0 | Aug 15, 2017 |
|
|
0.1.0-git | Jan 31, 2014 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
93
|
Health:
Code health derived from static analysis.
[more]
|
92
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
80
|
Overall:
Weighted score of the above.
[more]
|
90
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, other
Primary library:
package:io/io.dart
with components:io
.
Fix lib/src/process_manager.dart
. (-4.41 points)
Analysis of lib/src/process_manager.dart
reported 9 hints, including:
line 72 col 34: Use =
to separate a named parameter from its default value.
line 73 col 20: Use =
to separate a named parameter from its default value.
line 74 col 29: Use =
to separate a named parameter from its default value.
line 100 col 34: Use =
to separate a named parameter from its default value.
line 101 col 20: Use =
to separate a named parameter from its default value.
Fix lib/src/ansi_code.dart
. (-1.49 points)
Analysis of lib/src/ansi_code.dart
reported 3 hints:
line 84 col 38: Use =
to separate a named parameter from its default value.
line 99 col 44: Use =
to separate a named parameter from its default value.
line 124 col 20: Use =
to separate a named parameter from its default value.
Fix lib/src/permissions.dart
. (-1 points)
Analysis of lib/src/permissions.dart
reported 2 hints:
line 29 col 27: Use =
to separate a named parameter from its default value.
line 58 col 42: Use =
to separate a named parameter from its default value.
Fix lib/src/shared_stdin.dart
. (-1 points)
Analysis of lib/src/shared_stdin.dart
reported 2 hints:
line 39 col 45: Use =
to separate a named parameter from its default value.
line 54 col 42: Use =
to separate a named parameter from its default value.
The package description is too short. (-20 points)
Add more detail to the description
field of pubspec.yaml
. Use 60 to 180 characters to describe the package, what it does, and its target use case.
Maintain an example.
None of the files in the package's example/
directory matches known example patterns.
Common filename patterns include main.dart
, example.dart
, and io.dart
. Packages with multiple examples should provide example/README.md
.
For more information see the pub package layout conventions.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.54 <3.0.0 | ||
charcode | ^1.0.0 | 1.1.2 | |
meta | ^1.0.2 | 1.1.7 | |
path | ^1.5.1 | 1.6.2 | |
string_scanner | >=0.1.5 <2.0.0 | 1.0.4 | |
Transitive dependencies | |||
source_span | 1.5.4 | ||
term_glyph | 1.1.0 | ||
Dev dependencies | |||
dart_style | ^1.0.7 | ||
test | ^1.0.0 | ||
test_descriptor | ^1.0.0 |