Git Product home page Git Product logo

io-1's Introduction

Contains utilities for the Dart VM's dart:io.

pub package Build Status

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
/// 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.

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'));
  });
}

io-1's People

Contributors

kevmoo avatar matanlurey avatar michaelrfairhurst avatar nex3 avatar srawlins avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.