Coder Social home page Coder Social logo

console.dart's People

Contributors

azenla avatar chalin avatar daniellukic avatar domesticmouse avatar eukreign avatar filiph avatar ibrahim-mubarak avatar jarrodcolburn avatar jeremymeadows avatar joseluis avatar jsanford42 avatar kendalharland avatar kubeliv avatar mbullington avatar mzdm avatar pacane avatar rinick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

console.dart's Issues

printTree(): add support for multiple root nodes

It would be nice if printTree() supported a list of root nodes in the initial call. This saves on screen space when rendering the tree; one extra column saved to fit longer node labels for example (by not having that huge vertical line from single root node to all child nodes).

Cursor().writeAt ignores row column.

The current writeAt command ignoes the passed row and column


  void writeAt(int column, int row, String text) {
    Console.saveCursor();
    write(text);
    Console.restoreCursor();
  }

It should be:


  void writeAt(int column, int row, String text) {
    Console.saveCursor();
    move(column, row);
    write(text);
    Console.restoreCursor();
  }

Errors regarding null-safety

When I try to use the null-safe version 4.0.0 of this package I get a lot of errors (see below).
Looking at the changes of #29 it seems to me that none of the actual null-safety migration has been done. #29 contains mainly changes from " to ' and some other refactorings, but for example none of the types that should be nullable have been marked nullable. Note that fixing these errors will likely not be enough. A proper null safety migration for example using the migration tool has to be done to ensure that all types that should be nullable are marked nullable and all types that should not be nullable are not marked nullable. My suggested course of action would be to revert 9d75fd4 and to a migration using the migration tool.

Here the errors:

../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/format.dart:111:3: Warning: Operand of null-aware operation '??=' has type 'VariableStyle' which excludes null.
 - 'VariableStyle' is from 'package:console/console.dart' ('../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/console.dart').
  style ??= VariableStyle.DEFAULT;
  ^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/color.dart:73:45: Warning: Operand of null-aware operation '??' has type 'StringBuffer' which excludes null.
 - 'StringBuffer' is from 'dart:core'.
  TextPen({StringBuffer buffer}) : buffer = buffer ?? StringBuffer();
                                            ^
Unable to spawn isolate: ../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/base.dart:12:16: Error: Field '_currentTextColor' should be initialized because its type 'Color' doesn't allow null.
 - 'Color' is from 'package:console/console.dart' ('../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/console.dart').
  static Color _currentTextColor;
               ^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/base.dart:13:16: Error: Field '_currentBackgroundColor' should be initialized because its type 'Color' doesn't allow null.
 - 'Color' is from 'package:console/console.dart' ('../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/console.dart').
  static Color _currentBackgroundColor;
               ^^^^^^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/base.dart:135:31: Error: The parameter 'row' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
  static void moveCursor({int row, int column}) {
                              ^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/base.dart:135:40: Error: The parameter 'column' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
  static void moveCursor({int row, int column}) {
                                       ^^^^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/base.dart:177:38: Error: The parameter 'params' can't have a value of 'null' because of its type 'List<int>', but the implicit default value is 'null'.
 - 'List' is from 'dart:core'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
  static void sgr(int id, [List<int> params]) {
                                     ^^^^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/format.dart:107:19: Error: The parameter 'args' can't have a value of 'null' because of its type 'List<String>', but the implicit default value is 'null'.
 - 'List' is from 'dart:core'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
    {List<String> args,
                  ^^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/format.dart:108:25: Error: The parameter 'replace' can't have a value of 'null' because of its type 'Map<String, String>', but the implicit default value is 'null'.
 - 'Map' is from 'dart:core'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
    Map<String, String> replace,
                        ^^^^^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/format.dart:109:19: Error: The parameter 'style' can't have a value of 'null' because of its type 'VariableStyle', but the implicit default value is 'null'.
 - 'VariableStyle' is from 'package:console/console.dart' ('../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/console.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
    VariableStyle style,
                  ^^^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/format.dart:110:22: Error: The parameter 'resolver' can't have a value of 'null' because of its type 'String Function(String)', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
    VariableResolver resolver}) {
                     ^^^^^^^^
../../../../../.pub-cache/hosted/pub.dartlang.org/console-4.0.0/lib/src/io.dart:3:41: Error: The parameter 'prefix' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
void inheritIO(Process process, {String prefix, bool lineBased = true}) {
                                        ^^^^^^

Terminal resize

Is there a way to respond to terminal resize events to get the new stdout.terminalColumns, etc?

I can't get console size when run from pub run

Hello,

It's pretty simple to reproduce.

When I do dart bin/printWindow.dart, everything is ok.

But when I call it through pub run my_package:printWindow I get:

Unhandled exception:
Uncaught Error: StdoutException: Could not get terminal size, OS Error: Inappropriate ioctl for device, errno = 25
Stack Trace:
#0      Stdout._terminalSize (dart:io-patch/stdio_patch.dart:74)
#1      Stdout._terminalColumns (dart:io-patch/stdio_patch.dart:68)
#2      Stdout.terminalColumns (dart:io/stdio.dart:182)
#3      StdioConsoleAdapter.columns (package:console/src/adapter.dart:21:29)
#4      Console.columns (package:console/src/base.dart:181:38)
#5      Window.draw (package:console/src/curses/window.dart:28:25)
#6      UserInterface.draw (package:db_init/src/user_interface.dart:21:15)
#7      Window.display (package:console/src/curses/window.dart:42:5)
#8      main.<main_async_body> (http://localhost:52545/db_init.dart:17:6)
#9      _RootZone.runUnary (dart:async/zone.dart:1166)
#10     _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:494)
#11     _Future._propagateToListeners (dart:async/future_impl.dart:577)
#12     _Future._propagateToListeners.handleWhenCompleteCallback.<anonymous closure> (dart:async/future_impl.dart:560)
#13     _RootZone.runUnary (dart:async/zone.dart:1166)
#14     _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:494)
#15     _Future._propagateToListeners (dart:async/future_impl.dart:577)
#16     _Future._completeWithValue (dart:async/future_impl.dart:368)
#17     _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:422)
#18     _microtaskLoop (dart:async/schedule_microtask.dart:43)
#19     _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
#20     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:96)
#21     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:149)

#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:895)
#1      _microtaskLoop (dart:async/schedule_microtask.dart:43)
#2      _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
#3      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:96)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:149)

Is it a problem of your library, or from pub run ?

Cannot measure terminal when run through 'pub run'

When running a file through pub run, Console cannot measure the console window. This might be an unsolvable problem if pub run runs everything in some sort of sandboxed mode, I don't know. But I thought you might want to know!

bin/main.dart

import 'package:console/console.dart';

main() {
  print(Console.columns);
}
$ pub run bin/main

This throws an error message as follows:

Unhandled exception:
StdoutException: Could not get terminal size, OS Error: Inappropriate ioctl for device, errno = 25
#0      Stdout._terminalSize (dart:io-patch/stdio_patch.dart:74)
#1      Stdout._terminalColumns (dart:io-patch/stdio_patch.dart:68)
#2      Stdout.terminalColumns (dart:io/stdio.dart:182)
#3      StdioConsoleAdapter.columns (package:console/src/adapter.dart:21:29)
#4      Console.columns (package:console/src/base.dart:181:38)
#5      main (http://localhost:63740/main.dart:4:17)
#6      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:255)
#7      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:142)

Can't exit without calling exit(0) after binding keyboard

I'd like to be able to close/end my application within unit tests without calling exit(0), because this exits from the unit test framework. But, if I don't call exit(0) the keyboard binding keeps the application alive forever. Ideally there would be a method to unbind all keys, and tell the Keyboard class to stop capturing input.
Thanks.

SignalException: Listening for signal SIGWINCH is not supported

image

I get the SignalException when run example/window.dart in PowerShell:

SignalException: Listening for signal SIGWINCH is not supported
#0      _ProcessUtils._watchSignal (dart:io-patch/process_patch.dart:159:7)
#1      ProcessSignal.watch (dart:io/process.dart:656:50)
#2      Console.onResize (package:console/src/base.dart:26:56)
#3      Window._init (package:console/src/curses/window.dart:21:13)
#4      new Window (package:console/src/curses/window.dart:12:5)

Documentation please?

So I want to use this library to build a menu system, but I can't find any documentation on most of the methods and classes. How do I use the Keyboard class for instance? Maybe I'm a noob at this, but normally there is some type of hint at how these things are supposed to work.

Console.getCursorPosition throws a FormatException

The following program throws a FormatException when you press 'a' with another key simultaneously (e.g., press and 'a' and 's' at the same time).

import "package:console/console.dart";

void main() {
  Keyboard.init();

  Keyboard.bindKey("a").listen((_) {
    final pos = Console.getCursorPosition();
    print(pos);
  });
}
Unhandled exception:
FormatException: Invalid radix-10 number
[21
#0      int._throwFormatException (dart:core-patch/integers_patch.dart:111)
#1      int._parse (dart:core-patch/integers_patch.dart:101)
#2      int.parse (dart:core-patch/integers_patch.dart:58)
#3      Console.getCursorPosition.<anonymous closure> (package:console/src/base.dart:226:97)
#4      MappedListIterable.elementAt (dart:_internal/iterable.dart:413)
#5      ListIterator.moveNext (dart:_internal/iterable.dart:341)
#6      List.List.from (dart:core-patch/array_patch.dart:40)
#7      Console.getCursorPosition (package:console/src/base.dart:226:27)
#8      main.<anonymous closure> (file:///Users/kseo/dart/console.dart/example/keyboard.dart:7:25)

Console.getCursorPosition() synchronously writes ANSI 6h and reads the position. The underlying assumption is that there is no other interfering character while you perform Console.getCursorPosition().

But the exception above is caused because there is 's' character in the buffer when the callback is invoked for 'a' key. It is a race condition because the exception won't happen if you type 's' slightly slower than 'a'.

The cause is clear, but I am not sure how to fix this. If you just skip 's' in the buffer and perform Console.getCursorPosition(), the exception will disappear but 's' will be lost too. Once you read 's', there is no way to put it back at the front of the buffer.

I think the fundamental problem lies in that the API of console package mixes both synchronous and asynchronous API in a non-compatible way. It seems we can't reliably use synchronous APIs like Console.getCursorPosition() under the asynchronous key callback because "mixing synchronous and asynchronous reads is undefined".

Any suggestion?

Provide Console.readKey

Currently, Console does not provide a way to read key synchronously. Something similar to C#'s Console.ReadKey will be helpful.

Keyboard class provides only asynchronous way to read keys, and ConsoleAdapter.readByte method does not handle escape sequences.

OS Error: Inappropriate ioctl for device, errno = 25

This is the entire code:

import 'package:console/console.dart';

void main() {
  Keyboard.init();
}

This is the error message

Unhandled exception:
StdinException: Error setting terminal echo mode, OS Error: Inappropriate ioctl for device, errno = 25
#0      Stdin.echoMode=  (dart:io-patch/stdio_patch.dart:84:7)
#1      Keyboard.init  package:console/src/keyboard.dart:45
#2      main bin/main.dart:4
#3      _startIsolate.<anonymous closure>  (dart:isolate-patch/isolate_patch.dart:301:19)
#4      _RawReceivePortImpl._handleMessage  (dart:isolate-patch/isolate_patch.dart:168:12)

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.