Skip to main content

syntax_noir 0.0.1 copy "syntax_noir: ^0.0.1" to clipboard
syntax_noir: ^0.0.1 copied to clipboard

Terminal widgets for syntax on noir: a code highlighter for noir's CodeView and a patch view with word-level changes, driven by TextMate grammars.

example/main.dart

import 'package:noir/noir.dart';
import 'package:syntax_core/langs/dart.dart';
import 'package:syntax_core/syntax.dart' as syntax;
import 'package:syntax_core/themes/github_dark.dart';
import 'package:syntax_noir/syntax_noir.dart';

// Run in a terminal: dart run example/main.dart
void main() => runTuiApp(const PatchDemo());

final highlighter = syntax.Highlighter(languages: [dartLanguage]);

const before = '''
class Counter {
  int count = 0;

  void increment() => count++;

  void reset() {
    count = 0;
  }
}
''';

const after = '''
class Counter {
  Counter({this.step = 1});

  final int step;
  int total = 0;

  void increment() => total += step;

  void reset() {
    total = 0;
  }
}
''';

/// The changes to a small class, unified. Arrow keys move, Enter expands
/// hidden lines or collapses the file.
class PatchDemo extends StatefulWidget {
  const PatchDemo({super.key});

  @override
  State<PatchDemo> createState() => _PatchDemoState();
}

class _PatchDemoState extends State<PatchDemo> {
  final Set<int> _collapsed = {};
  final Set<syntax.DiffGapId> _expanded = {};

  @override
  Widget build(BuildContext context) => PatchView.fromTexts(
    oldText: before,
    newText: after,
    path: 'lib/counter.dart',
    highlighter: highlighter,
    theme: githubDarkTheme,
    collapsed: _collapsed,
    expanded: _expanded,
    onToggleFile: (file) => setState(() {
      if (!_collapsed.remove(file)) _collapsed.add(file);
    }),
    onExpandGap: (id) => setState(() => _expanded.add(id)),
    autofocus: true,
  );
}
0
likes
160
points
17
downloads

Documentation

API reference

Publisher

verified publisherconcepta.dev

Weekly Downloads

Terminal widgets for syntax on noir: a code highlighter for noir's CodeView and a patch view with word-level changes, driven by TextMate grammars.

Homepage
Repository (GitHub)
View/report issues

Topics

#syntax-highlighting #tui #terminal #code

License

BSD-3-Clause (license)

Dependencies

noir, syntax_core

More

Packages that depend on syntax_noir