runWith<T> static method

T runWith<T>(
  1. Terminal terminal,
  2. T body()
)

Runs body with terminal installed as current.

The previous context is restored when body returns or throws. If the context was uninitialized before this call, it is restored to that same uninitialized state.

Implementation

static T runWith<T>(Terminal terminal, T Function() body) {
  final previous = capture();
  current = terminal;
  try {
    return body();
  } finally {
    previous.restore();
  }
}