renderStatus function

void renderStatus(
  1. LiveBlock block,
  2. String device,
  3. Map<String, Object?> status
)

Adds the live:status view of status for device to block.

Implementation

void renderStatus(LiveBlock block, String device, Map<String, Object?> status) {
  final Object? authenticated = status['authenticated'];
  final Object? commands = status['commands'];
  final String platform = [
    status['platform'],
    status['osVersion'],
  ].where((part) => part != null && '$part'.isNotEmpty).join(' · ');

  final List<List<String>> rows = [
    [
      'App',
      '${status['app'] ?? '-'}${status['env'] != null ? ' (${status['env']})' : ''}',
    ],
    ['Device', platform.isEmpty ? device : '$device · $platform'],
    ['Mode', '${status['mode'] ?? '-'}'],
    ['Route', '${status['route'] ?? '-'}'],
    ['Stack', _stack(status['stack'])],
    ['Locale', '${status['locale'] ?? '-'}'],
    ['Theme', '${status['theme'] ?? '-'}'],
    [
      'Authenticated',
      authenticated == null
          ? 'not configured'
          : (authenticated == true ? 'yes' : 'no'),
    ],
    [
      'Live commands',
      commands is List && commands.isNotEmpty ? commands.join(', ') : 'none',
    ],
    if (status['seeders'] case final Object? seeders?)
      [
        'Seeders',
        seeders is List && seeders.isNotEmpty ? seeders.join(', ') : 'none',
      ],
  ];
  final int width = rows
      .map((row) => row.first.length)
      .reduce((a, b) => a > b ? a : b);
  for (final List<String> row in rows) {
    block.plain('${row.first.padRight(width + 2)}${row.last}');
  }
}