GithubHelp home page GithubHelp logo

naveenadi / dart_console Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timsneath/dart_console

0.0 0.0 0.0 244 KB

Dart library for writing console applications

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%

dart_console's Introduction

A Dart library for building console applications.

pub package Language Build codecov

This library contains a variety of useful functions for console application development, including:

  • Reading the current window dimensions (height, width)
  • Reading and setting the cursor location
  • Setting foreground and background colors
  • Manipulating the console into "raw mode", which allows more advanced keyboard input processing than the default dart:io library.
  • Reading keys and control sequences from the keyboard
  • Writing aligned text to the screen
  • Tabular data display, including month calendar

The library has been used to implement a Dart version of the Kilo text editor; when compiled with Dart it results in a self-contained kilo executable. The library is sufficient for a reasonably complete set of usage, including readline-style CLI and basic text games.

The library assumes a terminal that recognizes and implements common ANSI escape sequences. The package has been tested on macOS, Linux and Windows 10. Note that Windows did not support ANSI escape sequences in earlier versions.

The library uses the win32 package for accessing the Win32 API through FFI. That package contains many examples of using Dart FFI for more complex examples.

Usage

A simple example for the dart_console package:

import 'package:dart_console/dart_console.dart';

main() {
  final console = Console();

  console.clearScreen();
  console.resetCursorPosition();

  console.writeLine(
    'Console size is ${console.windowWidth} cols and ${console.windowHeight} rows.',
    TextAlignment.center,
  );

  console.writeLine();

  return 0;
}

More comprehensive demos of the Console class are provided, as follows:

Example Description
demo.dart Suite of test demos that showcase various capabilities
main.dart Basic demo of how to get started with the dart_console
keys.dart Demonstrates how dart_console processes control characters
readline.dart Sample command-line interface / REPL
kilo.dart Rudimentary text editor
life.dart Game of Life
table.dart Demonstrates tabular data display
calendar.dart Prints a monthly calendar on the screen

Acknowledgements

Special thanks to Matt Sullivan (@mjohnsullivan) and Samir Jindel (@sjindel-google) for their help in explaining FFI to me when it was first introduced and still undocumented.

Thanks to @erf for contributing the Game of Life example.

Features and bugs

Please file feature requests and bugs at the issue tracker.

dart_console's People

Contributors

averynortonsmith avatar domesticmouse avatar erf avatar fafre avatar md-weber avatar mit-mit avatar mkustermann avatar ssaundersla avatar timsneath avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.