timsneath / dart_console Goto Github PK
View Code? Open in Web Editor NEWDart library for writing console applications
License: BSD 3-Clause "New" or "Revised" License
Dart library for writing console applications
License: BSD 3-Clause "New" or "Revised" License
if stdin is closed (seems to be within docker)
hen the call to Console.cursorPosition will fail.
RangeError: Invalid value: Not in inclusive range 0..1114111: -1
new String.fromCharCode (dart:core-patch/string_patch.dart:45)
Console.cursorPosition (package:dart_console/src/console.dart:304)
looks like the results from the read need to be checked for -1 (end of file) before trying to decode as a char code.
Tim has asked me to take over maintenance of the dart_console project.
All future work will be done via:
https://onepub-dev/dart_console
So don't raise any new issues here.
The ControlCharacter
enum has F1-F4. I would like support for more F-n
keys like F5
I'd like to suggest adding an API for a callback for windows resize event.
If you for example are building a text editor, you'd like to redraw content on resize.
When using Console().readLine()
The last symbol cannot be deleted by pressing the delete key or Ctrl-D if the cursor is in front of that symbol.
example/readline.dart
aa
a
sa
is deleted as expecteda
is not deleted, even though it should be.I think the problem is with the line
dart_console/lib/src/console.dart
Line 670 in 0038bcb
if (index < buffer.length) {
.Hi i'm trying to follow your library to learn a bit more about dart ffi and i'm curious about this section
where the unix definition is
// cc_t c_cc[NCCS]; /* control chars */
but you chose to do
// This replaces c_cc[20]
@Int8()
int c_cc0;
@Int8()
int c_cc1;
@Int8()
int c_cc2;
@Int8()
int c_cc3;
@Int8()
int c_cc4;
@Int8()
int c_cc5;
@Int8()
int c_cc6;
@Int8()
int c_cc7;
@Int8()
int c_cc8;
@Int8()
int c_cc9;
@Int8()
int c_cc10;
@Int8()
int c_cc11;
@Int8()
int c_cc12;
@Int8()
int c_cc13;
@Int8()
int c_cc14;
@Int8()
int c_cc15;
@Int8()
int c_cc16; // VMIN
@Int8()
int c_cc17; // VTIME
@Int8()
int c_cc18;
@Int8()
int c_cc19;
is there a reference anywhere than explains this?
taken from here
If seems that accessing Console.cursorPosition
is implemented via writing escape sequences to stdout
and waiting in stdin
to receive the answer. That may be inherent in how terminals work.
That poses a problem when pasting longer text into the command prompt, since one may access cursorPosition
when there's remaining data to be read. This will cause the cursorPosition
to get into bad state (probably because it sees this other pasted - but not-yet-read data instead of the answer from cursor-position query).
It's hard to work around this problem with the current API, since one doesn't know whether there's data available before accessing cursorPosition
.
One suggestion I have is to provide a tryReadKey()
class Console {
Key readKey() { ... }
Key? tryReadKey() { ... }
}
If stdin
supports non-blocking IO, one could
dup2()
the stdin
file descriptor (to avoid clashing with other dart:io
functionality that assumes stdin
fd is blocking)Key
), or not if no data is available (return null
)This would give applications the option to manually call tryReadKey()
until it returns null
and only ask for cursorPosition
afterwards.
Would you consider adding 'italic' as a text style? it uses ansi '3' in the same position as 'bold' uses '1'. iTerm supports it, btw.
--Rob
String ansiSetTextStyles(
{bool bold = false,
bool underscore = false,
bool blink = false,
bool inverted = false,
bool italic = false}) {
var styles = [];
if (bold) styles.add(1);
if (underscore) styles.add(4);
if (blink) styles.add(5);
if (inverted) styles.add(7);
if (italic) styles.add(3);
return '\x1b[${styles.join(";")}m';
}
Hi!
Is it possible to use this module for not standard IO streams?
My use case: dartssh2 SSH server.
I'd like to use this module for emulating terminal session.
As this uses dart:ffi
it clearly won't work on dart 2.4.0:
Lines 7 to 8 in 492b876
side note, this is still pretty cool :)
Some function similar to the C# function Keyboard.IsKeyPressed(...).
If not. How would you go about, for example. printing a message every second until a key is pressed?
Sorry, beginner's question. I got the code for kilo.dart, but I can't seem to build it. Do I have to put the code for dart_console somewhere manually? Where??
I'd like to read input async, so that i can have a game loop going, without locking up the loop waiting for input.
Is this something you think is possible to implement or you'd like to add?
Probably caused by ed52d5b , though I'm not sure why the type of FillConsoleOutputCharacter changed.
../../../../../.pub-cache/hosted/pub.dartlang.org/dart_console-0.6.1/lib/src/ffi/win/termlib-win.dart:90:58: Error: The argument type 'Pointer<Uint32>' can't be assigned to the parameter type 'Pointer<Int32>'.
- 'Pointer' is from 'dart:ffi'.
- 'Uint32' is from 'dart:ffi'.
- 'Int32' is from 'dart:ffi'.
outputHandle, ' '.codeUnitAt(0), consoleSize, 0, pCharsWritten);
^
../../../../../.pub-cache/hosted/pub.dartlang.org/dart_console-0.6.1/lib/src/ffi/win/termlib-win.dart:95:63: Error: The argument type 'Pointer<Uint32>' can't be assigned to the parameter type 'Pointer<Int32>'.
- 'Pointer' is from 'dart:ffi'.
- 'Uint32' is from 'dart:ffi'.
- 'Int32' is from 'dart:ffi'.
outputHandle, bufferInfo.wAttributes, consoleSize, 0, pCharsWritten);
Hello,
I develop a roguelike game that runs in a Console.
To showcase the game I would like to embedd the Console in Flutter Web.
I realize that this is probably not possible due to technical limitations.
Or could it be done?
Thank you.
Tested in MacOS (no other O/S available for me). Create a simple Dart console app. Use console.readLine() to read a line.
Pasting clipboard content (%V in MacOS) doesn't work as expected. Only the first character would be pasted. I tried to write my own loop to use console.readKey() to get a full line. Same buggy behavior.
Using Dart's own stdin.readByteSync() in a loop to get a line does not have the same problem. %V works perfectly in that case.
A very common thing to do when developing interactive CLIs with prompts is to allow code completion of commands typed into the prompt.
The current API of Console.readLine()
makes this a little difficult, because it maintains it's own internal buffer of text that was inserted and its own cursor position. The callback
parameter that can be supplied cannot modify this internal state of readLine()
and therefore not e.g. auto complete.
A simple change that would allow tab-completion is the following
diff --git a/lib/src/console.dart b/lib/src/console.dart
index 9f7a7a0..48a2f58 100644
--- a/lib/src/console.dart
+++ b/lib/src/console.dart
@@ -534,7 +534,7 @@ class Console {
{bool cancelOnBreak = false,
bool cancelOnEscape = false,
bool cancelOnEOF = false,
- void Function(String text, Key lastPressed)? callback}) {
+ String? Function(String text, Key lastPressed)? callback}) {
var buffer = '';
var index = 0; // cursor position relative to buffer, not screen
@@ -650,7 +650,16 @@ class Console {
write(buffer); // allow for backspace condition
cursorPosition = Coordinate(screenRow, screenColOffset + index);
- if (callback != null) callback(buffer, key);
+ if (callback != null) {
+ final left = buffer.substring(0, index);
+ final right = buffer.substring(index);
+
+ final leftReplacement = callback(left, key);
+ if (leftReplacement != null) {
+ index = leftReplacement.length;
+ buffer = leftReplacement + right;
+ }
+ }
}
}
}
Using this change one can get tab-completion e.g. with this example:
import 'package:dart_console/dart_console.dart';
final console = Console.scrolling();
final commands = ['java', 'dart', 'pascal', 'delphi'];
String? completeCommand(String buffer) {
if (buffer.isEmpty) return null;
for (final command in commands) {
if (command.startsWith(buffer) && buffer.length < command.length) {
return command;
}
}
return null;
}
String? suggestedCompletion;
String? completion(String text, Key lastPressed) {
if (lastPressed.isControl) {
final completion = suggestedCompletion;
suggestedCompletion = null;
if (lastPressed.controlChar == ControlCharacter.tab && completion != null) {
// Write remaining characters to the screen.
console.write(completion.substring(text.length));
// Let the `Console.readLine()` API know the replacement text.
return completion;
}
return null;
}
final int prefixStart = text.lastIndexOf(' ');
var completion = completeCommand(text.substring(prefixStart + 1));
if (completion != null) {
if (prefixStart >= 0) {
completion = text.substring(0, prefixStart) + ' ' + completion;
}
suggestedCompletion = completion;
// Write the text that can be tab-completed in different color.
final old = console.cursorPosition;
console.setForegroundColor(ConsoleColor.brightWhite);
console.write(completion.substring(text.length));
console.cursorPosition = old;
// Reset color to what it used to be.
console.setForegroundColor(ConsoleColor.brightGreen);
}
return null;
}
void main() {
while (true) {
console.setForegroundColor(ConsoleColor.brightBlue);
console.write('>>> ');
console.resetColorAttributes();
console.setForegroundColor(ConsoleColor.brightGreen);
final response = console.readLine(cancelOnEOF: true, callback: completion);
if (response == null) break;
print(response.toUpperCase());
}
}
Though maybe a more direct API of the callback to the internal buffer and index would be better.
Would be wonderful have a way to build on package:dart_console
and get tab-completion working.
/cc @timsneath
I'm trying to use a console window as output and one as input field.
Is it possible open Console() on a different window, like in my idea?
I understand that is not very complicate to get the resize event for unix terminals like seen here
but is it actually possible to do it for windows?
Hi, Tim. Are you open to a pull request? I would like to use your dart_console library in a project I'm starting, but I was hoping for a readline that would handle using the up and down keys to scroll through previous lines. I see from your comment in console.dart ("TODO: Add multi-line input.") that this is an interest of yours as well. I have a local copy with this change if you would like to review it.
It seems that there's a mismatch between the source code and the documentation / examples / code on pub.dev. For example console.dart
shows a named constructor Console.scrolling(), but this is missing from the documentation and not present in the code downloaded from pub.dev.
Is there a way to resolve this mismatch? I'd love to be able to use the scrollback functionality.
Like the title says, the fields console.windowWidth
and console.windowHeight
work correctly, but do not update after a window resize. Here's an example:
import 'package:dart_console/dart_console.dart';
import 'dart:io';
void main() {
final console = Console();
while (true) {
var key = console.readKey();
if (key.char == 'q') {
break;
} else {
// Press some keys, resize the window, press some more keys
stdout.writeln('${console.windowWidth}x${console.windowHeight}'); // Does not update
stdout.writeln('${stdout.terminalColumns}x${stdout.terminalLines}'); // Updates
}
}
}
This was observed in gnome-terminal and vscode's integrated terminal.
When using Console.writeLine() to print strings that have either tabs or embedded ANSI codes. The resulting output is longer than the width of the screen so it appears that there are extra new lines but it's just the actual lines wrapped before the actual newline is printed.
I have worked around it with just using write() with an newline in the supplied string.
I double checked and the behavior is not present in 1.0. The change to have writeLine() call writeAligned() is likely the culprit and the non-single width characters are causing the alignment to be miscalculated.
I don't know this if this is even reasonable to fix as it would require knowing how the terminal is actually rendering the string.
So this is mostly to document, and suggest maybe changing current writeLine to writeLineAlinged and having writeLine behave as previously.
I run into this error.
Downloading Linux x64 Dart SDK 3.1.2...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
8 198M 8 16.0M 0 0 29.2M 0 0:00:06 --:--:-- 0:00:06 29.2M
36 198M 36 72.0M 0 0 46.6M 0 0:00:04 0:00:01 0:00:03 46.6M
90 198M 90 179M 0 0 71.2M 0 0:00:02 0:00:02 --:--:-- 71.2M
[10](https://github.com/customer/cnct-ui/actions/runs/8566330160/job/23481014239?pr=385#step:6:11)0 198M 100 198M 0 0 75.6M 0 0:00:02 0:00:02 --:--:-- 75.6M
Installing cnct command line application...
/home/runner/work/cnct-ui/cnct-ui/cnct_sidekick/tool/install.sh: 37: [[: not found
/home/runner/work/cnct-ui/cnct-ui/cnct_sidekick/tool/install.sh: 37: Linux: not found
- Getting dependencies
✔ Getting dependencies
- Bundling assets
✔ Bundling assets
- Compiling sidekick cli
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:35:22: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
final dwMode = (~CONSOLE_MODE.ENABLE_ECHO_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:36:[11](https://github.com/customer/cnct-ui/actions/runs/8566330160/job/23481014239?pr=385#step:6:12): Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_PROCESSED_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:37:11: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_LINE_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:38:11: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_WINDOW_INPUT);
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:44:20: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
final dwMode = CONSOLE_MODE.ENABLE_ECHO_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:45:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_EXTENDED_FLAGS &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:46:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_INSERT_MODE &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:47:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_LINE_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:48:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_MOUSE_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:49:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_PROCESSED_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:50:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_QUICK_EDIT_MODE &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:51:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_VIRTUAL_TERMINAL_INPUT;
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:111:33: Error: The getter 'STD_HANDLE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'STD_HANDLE'.
outputHandle = GetStdHandle(STD_HANDLE.STD_OUTPUT_HANDLE);
^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:1[12](https://github.com/customer/cnct-ui/actions/runs/8566330160/job/23481014239?pr=385#step:6:13):32: Error: The getter 'STD_HANDLE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'STD_HANDLE'.
inputHandle = GetStdHandle(STD_HANDLE.STD_INPUT_HANDLE);
^^^^^^^^^^
Error: AOT compilation failed
Generating AOT kernel dill failed!
Compilation failed. Trying dart pub upgrade (Retry 1)
- Compiling sidekick cli with updated dependencies
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:35:22: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
final dwMode = (~CONSOLE_MODE.ENABLE_ECHO_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:36:11: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_PROCESSED_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:37:11: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_LINE_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:38:11: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_WINDOW_INPUT);
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:44:[20](https://github.com/customer/cnct-ui/actions/runs/8566330160/job/23481014239?pr=385#step:6:21): Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
final dwMode = CONSOLE_MODE.ENABLE_ECHO_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:45:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_EXTENDED_FLAGS &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:46:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_INSERT_MODE &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:47:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_LINE_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:48:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_MOUSE_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:49:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_PROCESSED_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:50:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_QUICK_EDIT_MODE &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:51:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_VIRTUAL_TERMINAL_INPUT;
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:111:33: Error: The getter 'STD_HANDLE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'STD_HANDLE'.
outputHandle = GetStdHandle(STD_HANDLE.STD_OUTPUT_HANDLE);
^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:112:32: Error: The getter 'STD_HANDLE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'STD_HANDLE'.
inputHandle = GetStdHandle(STD_HANDLE.STD_INPUT_HANDLE);
^^^^^^^^^^
Error: AOT compilation failed
Generating AOT kernel dill failed!
Compilation failed again. Trying dart pub upgrade --major-versions (Retry 2)
- Compiling sidekick cli with major updated dependencies
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:35:[22](https://github.com/customer/cnct-ui/actions/runs/8566330160/job/23481014239?pr=385#step:6:23): Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
final dwMode = (~CONSOLE_MODE.ENABLE_ECHO_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:36:11: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_PROCESSED_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:37:11: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_LINE_INPUT) &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:38:11: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
(~CONSOLE_MODE.ENABLE_WINDOW_INPUT);
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:44:20: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
final dwMode = CONSOLE_MODE.ENABLE_ECHO_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:45:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_EXTENDED_FLAGS &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:46:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_INSERT_MODE &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:47:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_LINE_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:48:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_MOUSE_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:49:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_PROCESSED_INPUT &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:50:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_QUICK_EDIT_MODE &
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:51:9: Error: The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'CONSOLE_MODE'.
CONSOLE_MODE.ENABLE_VIRTUAL_TERMINAL_INPUT;
^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:111:33: Error: The getter 'STD_HANDLE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'STD_HANDLE'.
outputHandle = GetStdHandle(STD_HANDLE.STD_OUTPUT_HANDLE);
^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart:112:[32](https://github.com/customer/cnct-ui/actions/runs/8566330160/job/23481014239?pr=385#step:6:33): Error: The getter 'STD_HANDLE' isn't defined for the class 'TermLibWindows'.
- 'TermLibWindows' is from 'package:dart_console2/src/ffi/win/termlib_win.dart' ('../../../../.pub-cache/hosted/pub.dev/dart_console2-3.1.0/lib/src/ffi/win/termlib_win.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'STD_HANDLE'.
inputHandle = GetStdHandle(STD_HANDLE.STD_INPUT_HANDLE);
^^^^^^^^^^
Error: AOT compilation failed
Generating AOT kernel dill failed!
Compilation with updated and major updated dependencies failed. Restoring pubspec.lock
I'm unsure why dart_console2-3.1.0
is pulled at all. My pubspec.lock
file contains
dart_console2:
dependency: transitive
description:
name: dart_console2
sha256: "300833ffdd8c465d454cb5007c7f29d28ac8246af5abd922f8c490e1e87c894f"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
I pulled the dependencies on macos (where everything works. Linux seems to be incompatible with "3.0.0" and pulls the latest version.
Hi Tim,
is there anything I can do to help make the version bump for the win32 dependency? file_picker has already adopted the new win32 and due to transitive dependencies of msix I end up writing this issue :)
Normally one can past text into apps running on terminals: Be it a shell or interactive tools e.g. gdb
one can paste text into the terminal prompt.
Using package:dart_console
s Console.readLine()
api this is not possible, instead it will only take the first character and discard the rest of the pasted text. Simple reproduction
% dart example/readline_scrolling.dart
>>>
and try pasting some text with middle mouse button on linux.
The root cause of that is that Console.readLine()
is implemented by repeatedly calling Console.readKey()
which switches in/out of raw mode. The switching in/out of raw mode will cause remaining buffered input to be discarded.
The issue itself can be fixed by this small change
diff --git a/lib/src/ffi/unix/termlib_unix.dart b/lib/src/ffi/unix/termlib_unix.dart
index 1ef85ef..5d30b5c 100644
--- a/lib/src/ffi/unix/termlib_unix.dart
+++ b/lib/src/ffi/unix/termlib_unix.dart
@@ -52,7 +52,7 @@ class TermLibUnix implements TermLib {
..ref.c_ispeed = origTermIOS.c_ispeed
..ref.c_oflag = origTermIOS.c_ospeed;
- tcsetattr(STDIN_FILENO, TCSAFLUSH, newTermIOSPointer);
+ tcsetattr(STDIN_FILENO, TCSADRAIN, newTermIOSPointer);
calloc.free(newTermIOSPointer);
}
@@ -60,7 +60,7 @@ class TermLibUnix implements TermLib {
@override
void disableRawMode() {
if (nullptr == _origTermIOSPointer.cast()) return;
- tcsetattr(STDIN_FILENO, TCSAFLUSH, _origTermIOSPointer);
+ tcsetattr(STDIN_FILENO, TCSADRAIN, _origTermIOSPointer);
}
TermLibUnix() {
/cc @timsneath Do you think this is the right fix? (I'd really like to have the copy&paste into command prompt working - it's such an important use case)
Do not work in dart ( 3.0.0) console
I was having problems with extended chars in a linux terminal.
When I typed "è" I got "Ã".
Running the rawkeys example I got the following output:
c3 (Ã)
a8 (¨)
Giving a look at the Key.readKey function I saw this comment:
/// ... , certain keys may
/// be represented by multiple control key sequences. An example showing
/// basic key handling can be found in the `example/command_line.dart`
/// file in the package source code.
But I could not find the example "command_line"
So I did the following:
I copied the readKey function into an extension function and I did the following changes:
Original:
Key readKey() {
Key key;
int charCode;
int codeUnit = 0;
rawMode = true;
while (codeUnit <= 0) {
codeUnit = stdin.readByteSync();
}
if (codeUnit >= 0x01 && codeUnit <= 0x1a) {
....
Modified:
Key readSystemKey() {
Key key;
int charCode;
var codeUnit;
var bytes = <int>[];
rawMode = true;
while (key == null) {
codeUnit = 0;
while (codeUnit <= 0) {
codeUnit = stdin.readByteSync();
}
if (codeUnit >= 0x01 && codeUnit <= 0x1a) {
...
Original end of method:
} else {
// assume other characters are printable
key = Key.printable(String.fromCharCode(codeUnit));
}
rawMode = false;
return key;
}
Modified end of method:
} else {
// assume other characters are printable
try {
bytes.add(codeUnit);
key = Key.printable(systemEncoding.decode(bytes));
bytes.clear();
} on FormatException catch (_) {
if (bytes.length > 4) {
rethrow;
}
}
}
}
rawMode = false;
return key;
}
It works for my needs, but probably this logic should be added in other points of the package and tested with different OSs.
Another option would be to let the user set a specific encoding, if needed.
Let me know what do you think about.
Your example in the README:
import 'package:dart_console/dart_console.dart';
main() {
final console = Console();
console.clearScreen();
console.resetCursorPosition();
console.writeAligned(
'Console size is ${console.windowWidth} cols and ${console.windowHeight} rows.',
TextAlignment.Center);
console.writeLine();
return 0;
}
doesn't work because Console.writeAligned
doesn't exist.
Ctrl+I is mapping to tab, F5 is unknown
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.