show method

Future<void> show(
  1. Widget widget, {
  2. int? width,
})

Shows widget once, laid out at the terminal's width, or width columns, as tall as it is there; completes once it is written.

In the interactive mode it is committed to the terminal's history above what is live (the inline session is opened for it the first time). Elsewhere it is built and painted once, outside an app, and its rows written as lines: as text, with the styles' escapes where the terminal takes them; 80 columns wide where the output is no terminal and COLUMNS says nothing. Either way it is shown under the theme's CliTheme.data.

await Cli.current.show(
  const Column(
    children: [
      Text('Deployed', style: Style(attrs: Attr.bold)),
      Text('3 services'),
    ],
  ),
);

Implementation

Future<void> show(Widget widget, {int? width}) async {
  if (mode == CliMode.interactive && !_closed) {
    final session = await this.session();
    final shown = width == null
        ? widget
        // a Row asks its child for its height at its own width
        : Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [SizedBox(width: width, child: widget)],
          );
    await session.commit(shown);
    return;
  }
  final lines = widgetLines(
    widget,
    width ?? terminal.columns ?? 80,
    theme: theme.data,
    // the core's warnings about it are the console's, at their level
    onLog: (record) => switch (record.level) {
      LogLevel.error => err(record.message),
      LogLevel.warning => warn(record.message),
      LogLevel.info => info(record.message),
      LogLevel.debug => detail(record.message),
    },
    ansi: _caps.ansi,
    hyperlinks: _caps.hyperlinks,
    colorMode: _caps.colorMode,
    styledUnderlines: styledUnderlines,
  );
  final out = terminal.out;
  lines.forEach(out.writeln);
}