Coder Social home page Coder Social logo

vincentfoulon80 / console_engine Goto Github PK

View Code? Open in Web Editor NEW
212.0 212.0 7.0 2.46 MB

A simple terminal framework to draw things and manage user input

Home Page: https://crates.io/crates/console_engine

License: MIT License

Rust 100.00%
input terminal tui

console_engine's People

Contributors

0lucasmoura avatar lainez avatar lesleyrs avatar r59q avatar vincentfoulon80 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

console_engine's Issues

What about Backslash?

How one should enter the Backslash key? KeyCode::Char('\\') seems to give an error?

in ConsoleEngine::init, a target_fps > 1000 results in a division by 0 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.

On windows 10 you can't restart snake example if you hit left wall

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.

Emojis causing trouble

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.

Switch to Key/Mouse EventHandlers

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), ...

How to see errors from console engine?

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.

Is it possible to stop the buffer from overflowing if you re-draw the entire screen?

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

pub fn draw(&mut self) {

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?

`is_key_released` gets triggered when the key isn't being released

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.
image

Additional context
Windows 10

Code Review Needed !

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 !

Bump crossterm version to 0.25

crossterm is the main library we use for this engine, it recently got updated to 0.25, introducing new events and also a breaking on the Copy trait of these events.

We need to implement them onto console_engine, and also address all the issues that'll appear from upgrading the crossterm's version.

Bold pixels

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.

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.