Comments (4)
I set myself a similar task (to catch the TAB keystroke) and found this library. But the only problem is that, as it turned out, it works synchronously.
So far I've come to this solution:
- Disable echoMode and lineMode (in general, only lineMode should be disabled in this case, but the dart API documentation states the following "On Windows this mode can only be disabled if echoMode is disabled as well", so I had to disable both modes)
- Get BroadcastStream from stdin
- Make 2 subscriptions, one as before through
transform(utf8.decoder).transform(LineSplitter())
and the second already for direct listening from the stream and when you receive a press on tab (keyCode=9) perform any actions, otherwise write to stdoutstdout.writeCharCode(keyCode[0])
(remember I had to disable echoMode)
from dart_console.
UPD
I wrote a helper class
import 'dart:convert';
import 'dart:io';
class Console {
Console(Function(List<int>) onKeyListener, Function(String) onLineListener) {
stdin.echoMode = false;
stdin.lineMode = false;
stdin.asBroadcastStream()
..listen(onKeyListener)
..transform(Utf8Decoder())
.transform(LineSplitter())
.listen(onLineListener);
}
}
there was a little more code, but I cut out the excess
use:
Console((charCodes) {
// On key press event
stdout.write(charCodes);
}, (line) {
// On line print event
stdout.write(line);
});
from dart_console.
I would need the same feature.
Running a periodic timer next to a game loop but the readKey()
blocks exectution.
Timer.periodic(Duration(seconds: 1), (timer) {
print(timer); // fails
});
while(true) {
console.readKey();
}
from dart_console.
stdin is a stream with a listen method, if you combine this with placing stdin into non-line mode I think you might have a solution.
I've not tried it but something like
stdin.lineMode = false;
stdin.listen((data) -> print(data));
remember to place stdin back into lineMode before you exit
from dart_console.
Related Issues (20)
- Ctrl+M is mapping to enter HOT 1
- 'NoSuchMethodError: The getter 'col' was called on null.' when running readLine() with writeLine() in while loop while holding enter.
- Support for more function keys HOT 1
- windowWidth and windowHeight do not update on window resize (linux)
- Is it possibile to use Console on different CMD window? HOT 1
- Last symbol cannot be deleted with delete key or Ctrl-D when using Console().readLine()
- If stdin is closed cursorPosition throws a RangeError HOT 4
- usage with not standard streams (not stdin/stdout)
- Regression in 1.1: RangeError in `Console.cursorPosition`
- Console.writeLine does not align correctly with characters that do not have width 1
- `Console.readLine()` doesn't allow users to paste text into terminal HOT 2
- Extend `Console.readLine()` API to allow tab-completion of commands in a prompt HOT 1
- Versionbump win32 to 3.0.0 HOT 1
- Accessing `cursorPosition` may print debugging information
- Do not work
- Game: Run Console in Flutter Web? HOT 1
- The getter 'CONSOLE_MODE' isn't defined for the class 'TermLibWindows'. HOT 2
- Pasting clipboard content to readLine pastes only first character HOT 9
- NOTE: New issues should be raised against: https://onepub-dev/dart_console
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dart_console.