Skip to content

Instantly share code, notes, and snippets.

@mit-mit
Last active June 6, 2024 16:39
Show Gist options
  • Save mit-mit/faec2bfc1d1cef7cd09df917e531c5c0 to your computer and use it in GitHub Desktop.
Save mit-mit/faec2bfc1d1cef7cd09df917e531c5c0 to your computer and use it in GitHub Desktop.
import 'dart:io';
import 'dart:math';
import 'package:dart_console/dart_console.dart';
final console = Console();
final startRow = (console.windowHeight / 3).round() - 1;
// Small demo app announcing dart2native.
//
// This uses package https://pub.dev/packages/dart_console,
// and was heavily inspired by examples/demo.dart from that package.
main() {
progress('PREPARING ANNOUNCEMENT');
stars();
announce(
'ANNOUNCING: dart2native',
'Compile Dart to self-contained, native executables',
'for macOS, Windows, and Linux');
console
..resetColorAttributes()
..clearScreen();
}
progress(String text) {
console
..setColors(ConsoleColor.blue, ConsoleColor.white)
..writeLineAt(text, Coordinate(startRow, 0))
..hideCursor();
final barWidth = console.windowWidth - 8;
for (int i = 0; i <= barWidth - 3; i++) {
final bar = ('[' + ('#' * i)).padRight(barWidth - 2) + ']';
console.writeAt(bar, Coordinate(startRow + 2, 4));
sleep(Duration(milliseconds: 20));
}
}
stars() {
console
..setColors(ConsoleColor.black, ConsoleColor.red)
..hideCursor();
final random = Random();
for (int i = 0; i < 100; i++) {
console
..writeAt('*', Coordinate(startRow, 20 + random.nextInt(40)))
..writeAt(' ', Coordinate(startRow, 18 + random.nextInt(42)));
sleep(Duration(milliseconds: 10));
}
}
announce(String announce1, String announce2, String announce3) {
console
..setColors(ConsoleColor.black, ConsoleColor.brightRed)
..writeLineAt(announce2, Coordinate(startRow + 2, 0))
..writeLineAt(announce3, Coordinate(startRow + 3, 0))
..hideCursor();
for (int i = 0; i < 50; i++) {
console
..setForegroundExtendedColor(i * 3)
..writeLineAt(announce1, Coordinate(startRow, 0));
sleep(Duration(milliseconds: 100));
}
}
extension MyConsole on Console {
setColors(ConsoleColor foreground, ConsoleColor background) {
console
..resetColorAttributes()
..setBackgroundColor(foreground)
..setForegroundColor(background)
..clearScreen()
..showCursor();
}
writeLineAt(String text, Coordinate position) {
console
..cursorPosition = position
..writeLine(text, TextAlignment.center);
}
writeAt(String text, Coordinate position) {
console
..cursorPosition = position
..write(text);
}
}
name: announce
description: An announcement application.
environment:
sdk: '>=2.6.0 <3.0.0'
dependencies:
dart_console: ^0.4.0
@mit-mit
Copy link
Author

mit-mit commented Nov 1, 2019

pub get
dart2native bin/announce.dart -o announce
./announce

ann

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment