Skip to main content

terminal_ui 0.2.1 copy "terminal_ui: ^0.2.1" to clipboard
terminal_ui: ^0.2.1 copied to clipboard

Terminal widgets for Flutter: an app drawn on a character grid, with box-drawn panes, bracketed buttons, inverse selection and keys beside every action.

example/lib/main.dart

// terminal_ui's example: the Overview first (the look at its best, what it
// is, the example app's screens and what the package holds), then every
// part's page from its index. The example app, slipway, is a small team's
// deploy console; open it from the Overview.
import 'package:material_ui/material_ui.dart';
import 'package:terminal_ui/terminal_ui.dart';

import 'gallery_pages.dart';
import 'kit_gallery/kit.dart';
import 'kit_gallery/overview.dart';
import 'kit_gallery/slipway.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // The faces before the first frame: the grid never starts in a fallback.
  await termLoadFonts();
  runApp(const TerminalExample());
}

/// The screens the Overview opens as the example app, not as parts.
const _screens = {
  'overview',
  'home',
  'runs',
  'run-detail',
  'deploy',
  'settings',
};

/// The example: the Overview, and the parts' pages it opens.
class TerminalExample extends StatefulWidget {
  /// The example, at night.
  const TerminalExample({super.key});

  @override
  State<TerminalExample> createState() => _TerminalExampleState();
}

class _TerminalExampleState extends State<TerminalExample> {
  // A link may open a page straight away: ?page=runs&theme=paper&dir=rtl,
  // one of slipway's screens (?place=diff) and a text scale (&scale=2).
  static final _query = Uri.base.queryParameters;
  static final _place = SlipwayPlace.values
      .where((p) => p.name == _query['place'])
      .firstOrNull;
  var _brightness = _query['theme'] == 'paper'
      ? Brightness.light
      : Brightness.dark;
  String? _part = galleryPages.any((p) => p.id == _query['page'])
      ? _query['page']
      : null;

  @override
  void initState() {
    super.initState();
    if (_query['dir'] == 'rtl') kitShownDirection = TextDirection.rtl;
    kitTextScale = double.tryParse(_query['scale'] ?? '') ?? 1;
  }

  @override
  Widget build(BuildContext context) {
    if (_place case final place?) {
      return slipwayApp(_brightness, place: place);
    }
    final part = _part;
    if (part != null) {
      final page = galleryPages.firstWhere((p) => p.id == part);
      kitOnBack = () => setState(() => _part = null);
      return KeyedSubtree(
        key: ValueKey('$part/${_brightness.name}'),
        child: page.build(_brightness),
      );
    }
    kitOnBack = null;
    return kitApp(
      brightness: _brightness,
      home: OverviewPage(
        onBrightness: () => setState(
          () => _brightness = _brightness == Brightness.dark
              ? Brightness.light
              : Brightness.dark,
        ),
        parts: [
          for (final p in galleryPages)
            if (!_screens.contains(p.id)) (id: p.id, title: p.title),
        ],
        onOpenPart: (id) => setState(() => _part = id),
      ),
    );
  }
}
1
likes
160
points
0
downloads
screenshot

Documentation

API reference

Publisher

verified publisherwenkaifan.com

Weekly Downloads

Terminal widgets for Flutter: an app drawn on a character grid, with box-drawn panes, bracketed buttons, inverse selection and keys beside every action.

Homepage
Repository (GitHub)
View/report issues

Topics

#design-system #widget #ui #theme #terminal

License

BSD-3-Clause (license)

Dependencies

flutter, material_ui, ui_core

More

Packages that depend on terminal_ui