io
v1.1.0Utilities for the Dart VM Runtime including support for ANSI colors, file copying, and standard exit code values.
Архив пакета: https://pubdev.letsnova.ru/api/archives/io/1.1.0.tar.gz
dart pub add ioREADME
Contains utilities for the Dart VM's dart:io.
Usage - io.dart
Files
isExecutable
Returns whether a provided file path is considered executable on the host operating system.
Processes
ExitCode
An enum-like class that contains known exit codes.
ProcessManager
A higher-level service for spawning and communicating with processes.
Use spawn to create a process with std[in|out|err] forwarded by default
Future<void> main() async {
final manager = ProcessManager();
// Print `dart` tool version to stdout.
print('** Running `dart --version`');
var spawn = await manager.spawn('dart', ['--version']);
await spawn.exitCode;
// Check formatting and print the result to stdout.
print('** Running `dart format --output=none .`');
spawn = await manager.spawn('dart', ['format', '--output=none', '.']);
await spawn.exitCode;
// Check if a package is ready for publishing.
// 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('dart', ['pub', 'publish', '--dry-run']);
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.
Usage - 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'));
});
}
Publishing automation
For information about our publishing automation and release process, see https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.
История изменений
1.1.0
- Add a
deepCopyLinksargument tocopyPathandcopyPathSync. - Remove the
@visibleForTestingannotation fromSharedStdIn. - Potentially Breaking Make the stream parameter required for
SharedStdIn.new.- This is treated as non-breaking because the class was marked as visible for testing only.
- Potentially Breaking
AnsiCodeandAnsiCodeTypemarked final. These were never intended to support subclasses and were already closed for extension with private generative constructors. They are now markedfinaland statically restricted from use as an interface.
1.0.5
- Require Dart 3.4.
- Move to
dart-lang/toolsmonorepo.
1.0.4
- Updates to the readme.
1.0.3
- Revert
metaconstraint to^1.3.0.
1.0.2
- Update
metaconstraint to>=1.3.0 <3.0.0.
1.0.1
- Update code examples to call the unified
dartdeveloper tool.
1.0.0
- Migrate this package to null-safety.
- Require Dart >=2.12.
0.3.5
- Require Dart >=2.1.
- Remove dependency on
package:charcode.
0.3.4
- Fix a number of issues affecting the package score on
pub.dev.
0.3.3
-
Updates for Dart 2 constants. Require at least Dart
2.0.0-dev.54. -
Fix the type of
StartProcesstypedef to matchProcess.startfromdart:io.
0.3.2+1
-
ansi.dart- The "forScript" code paths now ignore the
ansiOutputEnabledvalue. Affects theescapeForScriptproperty onAnsiCodeand thewrapandwrapWithfunctions whenforScriptis true.
- The "forScript" code paths now ignore the
0.3.2
-
ansi.dart-
Added
forScriptnamed argument to top-levelwrapWithfunction. -
AnsiCode-
Added
String get escapeForScriptproperty. -
Added
forScriptnamed argument towrapfunction.
-
-
0.3.1
- Added
SharedStdIn.nextLine(similar toreadLineSync) andlines:
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
copyPathandcopyPathSyncfunction, similar tocp -R. -
Added a dependency on
package:path. -
Added the remaining missing arguments to
ProcessManager.spawnXwhich forward toProcess.start. It is now an interchangeable function for running a process.
0.3.0
- BREAKING CHANGE: The
argumentsargument toProcessManager.spawnis now positional (not named) and required. This makes it more similar to the built-inProcess.start, and easier to use as a drop in replacement:
main() {
processManager.spawn('dart', ['--version']);
}
-
Fixed a bug where processes created from
ProcessManager.spawncould not have theirstdout/stderrread through their respective getters (a runtime error was always thrown). -
Added
ProcessMangaer#spawnBackground, which does not forwardstdin. -
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.
0.2.0
- Initial commit of...
FutureOr<bool> String isExecutable(path).ExitCodeProcessManagerandSpawnsharedStdInandSharedStdInansi.dartlibrary with support for formatting terminal output
