vincentfoulon80 / console_engine Goto Github PK
View Code? Open in Web Editor NEWA simple terminal framework to draw things and manage user input
Home Page: https://crates.io/crates/console_engine
License: MIT License
A simple terminal framework to draw things and manage user input
Home Page: https://crates.io/crates/console_engine
License: MIT License
Since Crossterm 0.25, there are three new events we can probably add to console_engine:
FocusGained
and FocusLost
(Windows only)Paste
How one should enter the Backslash key? KeyCode::Char('\\')
seems to give an error?
Describe the bug
I'm finding that if I set target_fps
to anything over 1000, I get the following error:
thread 'main' panicked at 'attempt to calculate the remainder with a divisor of zero', /home/aaron/.cargo/registry/src/github.com-1ecc6299db9ec823/console_engine-2.5.0/src/lib.rs:737:17
stack backtrace:
0: rust_begin_unwind
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
2: core::panicking::panic
at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:48:5
3: console_engine::ConsoleEngine::poll
at /home/aaron/.cargo/registry/src/github.com-1ecc6299db9ec823/console_engine-2.5.0/src/lib.rs:737:17
...
Note this is only happening using the event
feature.
To Reproduce
use console_engine::events::Event;
use console_engine::pixel;
use console_engine::Color;
use console_engine::ConsoleEngine;
use console_engine::KeyCode;
let mut engine = console_engine::ConsoleEngine::init(10, 10, 1001).unwrap();
loop {
// Poll next event
match engine.poll() {
// A frame has passed
Event::Frame => {
// step(&mut engine, &mut world);
println!("hiya");
}
// A Key has been pressed
Event::Key(keyevent) => {
if keyevent.code == KeyCode::Char('q') {
break;
}
}
// Mouse has been moved or clicked
Event::Mouse(_mouseevent) => { /* ... */ }
// Window has been resized
Event::Resize(_w, _h) => { /* ... */ }
}
Expected behavior
Any value up to u32::MAX
can be used without any sort of error
Screenshots
N/A
Additional context
Looks like version 2.5.0 from the trace, and fwiw uname -a
gives me Linux dellbert 5.15.0-57-generic #63-Ubuntu SMP Thu Nov 24 13:43:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Additional additional context
Actually, it would be very nice if there didn't need to a frame rate set here, and instead there was an option to let it run as fast as possible. Maybe setting it to 0 means no delay at all, instead of panicking. Or maybe it could take an Option
and a None
could be passed in or something.
Describe the bug
When you lose the game after hitting the left "wall" you can no longer restart the game with space
. I tried to find out why but I have no clue. The game is still running telling you to press space, but it doesn't react to it.
Additional context
Windows 10, Windows terminal and Console host both have the issue.
Describe the bug
Using emojis in the console output will cause a shift when drawing shapes. I think this problem applies to all characters that use more than 1 bytes?
To Reproduce
use console_engine::screen::Screen;
use console_engine::pixel;
fn main() {
// create a screen of 20x11 characters
let mut scr = Screen::new(20,11);
// draw some shapes and prints some text
scr.rect(0,0, 19,10,pixel::pxl('#'));
scr.fill_circle(5,5, 3, pixel::pxl('*'));
scr.print(11,4, "๐ฅ");
scr.print(11,5, "World!");
// print the screen to the terminal
scr.draw();
}
Expected behavior
####################
# #
# *** #
# ***** #
# ******* ๐ฅ #
# ******* World! #
# ******* #
# ***** #
# *** #
# #
####################
Actual behavior
####################
# #
# *** #
# ***** #
# ******* ๐ฅ #
# ******* World! #
# ******* #
# ***** #
# *** #
# #
####################
Additional context
Running on macOS.
Is your feature request related to a problem? Please describe.
The current implementation means at only the moment is_key_pressed
or get_mouse_press
are called the state of the key/mouse is checked. This is a simple solution, but also introduces delays and at low framerates entire keypresses might go unnoticed.
Describe the solution you'd like
It would be significantly better if you were to hook/unhook eventHandlers to keys/mouse events, instead of checking in an endless loop.
Implementing on_key_down(Key, Function)
, on_key_up(Key, Function)
, on_mouse_move(Function)
, ...
I have no idea hot effectively check errors during executions.
I do cargo run => out.txt right now, and then I see the errors in the terminal, but it is not efficient.
This is not directly about console_engine, but I'm trying to do something similar with just crossterm.
But I noticed that if I try to draw too much at once with queue, MoveTo and Print it will always immediately flush before it reaches the flush function.
I was looking at how you did it
Line 572 in d56ea01
but the main difference is that you just try to avoid drawing as often for unchanged chars. Is that the only workaround for this, or are you doing something else that I missed?
Describe the bug
I changed some of the scroll
example movement to this:
engine.scroll(x, y, pixel::pxl_bg(' ', Color::Cyan));
engine.print_fbg(7, 10, &y.to_string(), Color::Black, Color::White);
// if engine.is_key_released(KeyCode::Up) && !engine.is_key_held(KeyCode::Down)
// || engine.is_key_released(KeyCode::Down) && !engine.is_key_held(KeyCode::Up)
// {
// y = 0;
// }
if engine.is_key_released(KeyCode::Up) && y == 1
|| engine.is_key_released(KeyCode::Down) && y == -1
{
y = 0;
}
if engine.is_key_held(KeyCode::Up) {
y = 1;
} else if engine.is_key_held(KeyCode::Down) {
y = -1;
}
I'm checking if a key is released AND the player is moving (y being 1 or -1) and then stop moving if true. But the player stops moving everytime shortly after you press a key. I feel like this has to do with is_key_held
event not appearing for a few frames but I still don't know why that's related to released
, as this was my way around that problem.
For some reason the is_key_released code gets triggered to set y back to 0 for a short time when all I'm doing is just pressing up
or down
to move without releasing anything.
I don't understand why this happens, I tried to see how it works on crossterm event examples and release only shows up if you actually release a key.
The commented out code is just to show what I'm trying to do, but that one makes sense why it doesn't work as is_held doesn't always return true when you are holding it at the start like on crossterm. So I tried the current way and was expecting it to work for smooth direction changing, but I can't find out what's wrong with it.
To Reproduce
Code above in the scroll
example
Expected behavior
is_key_released
should not get triggered when not releasing any keys, resulting in the code NOT being run that sets movement back to 0. This is a way to allow for smooth movement to occur that still accurately stops the player without needing accurate keyboard state.
Screenshots
cargo run --example event-poll-read
shows that there are no release events until you actually release a key.
Additional context
Windows 10
Hello !
This crate is my first ever program in rust.
So it's prone to various bad practices and for that I want to have a second (or whatever number) opinion on my code.
I want to improve myself in rust so any advice is welcome !
Let's use this issue to discuss about it !
Is your feature request related to a problem? Please describe.
I would like to add more depth to what is rendered, by using bold characters
Describe the solution you'd like
I would like to set some "pixel" to be rendered as bold. Maybe something like:
engine.set_pxl(1, 2, pixel::pxl_fg('Z', Color::Red).bold());
But I don't have much opinion on the API.
Describe alternatives you've considered
Aside using crosstem directly, I don't see how to achieve that via console_engine
Additional context
There might be other desirable styles such as italic, underline, etc.
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.