-
-
Notifications
You must be signed in to change notification settings - Fork 39
Modifier and Blink Support #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 52 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
d1617b1
reversed and hidden work now
gold-silver-copper 64bae30
dimming works now
gold-silver-copper 45c7464
blinking works now
gold-silver-copper 769756f
blinking cursor works
gold-silver-copper 472fd3c
typos lol
gold-silver-copper c4dab80
Update main.rs
gold-silver-copper 2944165
Update colors.rs
gold-silver-copper 1d977a1
better frame count semantics
gold-silver-copper 6d1b4a5
Update backend.rs
gold-silver-copper 54e2b84
blinking enum, cleaned blink toggle code
gold-silver-copper 424c9cd
Update backend.rs
gold-silver-copper aaa11d9
inverse cursor, heapbuffer get_pixel
gold-silver-copper dd08fba
Added CursorStyle,CursorConfig,BlinkConfig
gold-silver-copper a823c50
Moved blink state to config
gold-silver-copper 4769fe5
Inverse as default
gold-silver-copper aee110d
Japanese style cursor
gold-silver-copper e59c5e8
fmt
gold-silver-copper be9e55c
clippy
gold-silver-copper 7dff734
better japanese cursor style
gold-silver-copper 76aea8a
Merge branch 'ratatui:main' into main
gold-silver-copper 23a5be9
feature flag blink, u16 frame count, removed floats, breaking changes md
gold-silver-copper 94c6a02
wat?
gold-silver-copper e638536
feature gate blink in cursor config, consolidate cfg flagged code
gold-silver-copper 115661b
md fmt
gold-silver-copper 34c4a32
md fmt2
gold-silver-copper 410cab6
one less cast in get_pixel
gold-silver-copper 6693e0b
make dim a bit more bright
gold-silver-copper ea88a92
fmt
gold-silver-copper 49d034d
Export all new configuration structs and enums, build docs with all-f…
gold-silver-copper ff55f0c
fmt
gold-silver-copper 3ec593f
add readme section, removed unnecessary cursor option and fn
gold-silver-copper bc00434
Update README.md
gold-silver-copper 8d8c7e1
ignore in the doc comments @_@
gold-silver-copper 87bb6a7
Update README.md
gold-silver-copper 857d94d
finale
gold-silver-copper 9de18b6
Update mousefood/src/backend.rs
gold-silver-copper 04d4e73
Update mousefood/src/backend.rs
gold-silver-copper 09e4d1b
Update mousefood/src/colors.rs
gold-silver-copper ec4ee8e
Update mousefood/src/colors.rs
gold-silver-copper 5a4c669
Update mousefood/src/backend.rs
gold-silver-copper 4f5ca06
Update mousefood/src/backend.rs
gold-silver-copper 3b90b06
Update mousefood/src/backend.rs
gold-silver-copper 1f9b1a4
cursor module, pub type Result
gold-silver-copper a966992
Update colors.rs
gold-silver-copper f06c008
Apply suggestion from @orhun
gold-silver-copper ad099f0
Apply suggestion from @orhun
gold-silver-copper ad34db7
Apply suggestion from @orhun
gold-silver-copper 2576b83
fmt
gold-silver-copper c487523
Merge branch 'main' into main
gold-silver-copper 827642f
clean up
gold-silver-copper c7047ff
Replaced simulator image with blink demo gif
gold-silver-copper 4e5073a
added modifiers demo, added modifiers gif to readme
gold-silver-copper 573252d
Update stuff
gold-silver-copper f7024b5
Update BREAKING-CHANGES.md
gold-silver-copper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| //! # Simulator | ||
| //! | ||
| //! Run mousefood apps on your computer inside a simulator! Uses [embedded-graphics-simulator](https://crates.io/crates/embedded-graphics-simulator). | ||
| //! | ||
| //! ## Requirements | ||
| //! | ||
| //! This app requires [SDL2](https://wiki.libsdl.org/SDL2/Installation) to be installed. | ||
| //! | ||
| //! If you use [nix](https://nixos.org) you can run `nix-shell -p SDL2` | ||
| //! before running the application. | ||
| //! | ||
| //! ## Run | ||
| //! | ||
| //! To start this demo, simply run: | ||
| //! | ||
| //! ```shell | ||
| //! cargo run -p simulator --bin mods | ||
| //! ``` | ||
| //! | ||
| //! A window will open with the simulator running. | ||
| //! Use arrow keys or WASD to move the cursor. | ||
|
|
||
| use embedded_graphics_simulator::{ | ||
| OutputSettings, SimulatorDisplay, SimulatorEvent, Window, sdl2::Keycode, | ||
| }; | ||
| use mousefood::embedded_graphics::geometry; | ||
| use mousefood::error::Error; | ||
| use mousefood::prelude::*; | ||
| use ratatui::backend::Backend; | ||
| use ratatui::widgets::{Block, Paragraph, Wrap}; | ||
| use ratatui::{Frame, Terminal, style::*}; | ||
| use std::cell::RefCell; | ||
| use std::rc::Rc; | ||
|
|
||
| fn main() -> Result<(), Error> { | ||
| let mut simulator_window = Window::new( | ||
| "mousefood simulator", | ||
| &OutputSettings { | ||
| scale: 4, | ||
| ..Default::default() | ||
| }, | ||
| ); | ||
| simulator_window.set_max_fps(30); | ||
|
|
||
| let mut display = SimulatorDisplay::<Bgr565>::new(geometry::Size::new(128, 64)); | ||
|
|
||
| let events: Rc<RefCell<Vec<SimulatorEvent>>> = Rc::new(RefCell::new(Vec::new())); | ||
| let events_cb = events.clone(); | ||
|
|
||
| let backend_config = EmbeddedBackendConfig { | ||
| flush_callback: Box::new(move |display| { | ||
| simulator_window.update(display); | ||
| let mut ev = events_cb.borrow_mut(); | ||
| ev.clear(); | ||
| ev.extend(simulator_window.events()); | ||
| }), | ||
| color_theme: ColorTheme::tokyo_night(), | ||
| ..Default::default() | ||
| }; | ||
| let backend: EmbeddedBackend<SimulatorDisplay<_>, _> = | ||
| EmbeddedBackend::new(&mut display, backend_config); | ||
|
|
||
| let mut terminal = Terminal::new(backend)?; | ||
| let mut cursor_x: u16 = 1; | ||
| let mut cursor_y: u16 = 1; | ||
|
|
||
| loop { | ||
| terminal.draw(|frame| draw(frame, cursor_x, cursor_y))?; | ||
|
|
||
| for event in events.borrow().iter() { | ||
| match event { | ||
| SimulatorEvent::KeyDown { keycode, .. } => match *keycode { | ||
| Keycode::Up | Keycode::W => { | ||
| cursor_y = cursor_y.saturating_sub(1); | ||
| } | ||
| Keycode::Down | Keycode::S => { | ||
| cursor_y = cursor_y.saturating_add(1); | ||
| } | ||
| Keycode::Left | Keycode::A => { | ||
| cursor_x = cursor_x.saturating_sub(1); | ||
| } | ||
| Keycode::Right | Keycode::D => { | ||
| cursor_x = cursor_x.saturating_add(1); | ||
| } | ||
| _ => {} | ||
| }, | ||
| SimulatorEvent::Quit => return Ok(()), | ||
| _ => {} | ||
| } | ||
| } | ||
|
|
||
| if let Ok(size) = terminal.backend_mut().size() { | ||
| cursor_x = cursor_x.min(size.width.saturating_sub(1)); | ||
| cursor_y = cursor_y.min(size.height.saturating_sub(1)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn draw(frame: &mut Frame, cursor_x: u16, cursor_y: u16) { | ||
| use ratatui::style::Modifier; | ||
| use ratatui::text::{Line, Span}; | ||
|
|
||
| let line = Line::from(vec![ | ||
| Span::styled(format!("F:{} ", frame.count()), Style::new().yellow()), | ||
| Span::styled("RED ", Style::new().fg(Color::Red)), | ||
| Span::styled( | ||
| "DIM ", | ||
| Style::new().fg(Color::Red).add_modifier(Modifier::DIM), | ||
| ), | ||
| Span::styled("UNDR ", Style::new().add_modifier(Modifier::UNDERLINED)), | ||
| Span::styled("SLOW ", Style::new().add_modifier(Modifier::SLOW_BLINK)), | ||
| Span::styled("FAST ", Style::new().add_modifier(Modifier::RAPID_BLINK)), | ||
| Span::styled("REV ", Style::new().add_modifier(Modifier::REVERSED)), | ||
| Span::styled("HIDE ", Style::new().add_modifier(Modifier::HIDDEN)), | ||
| Span::styled("XOUT ", Style::new().add_modifier(Modifier::CROSSED_OUT)), | ||
| Span::styled( | ||
| "D+U ", | ||
| Style::new().add_modifier(Modifier::DIM | Modifier::UNDERLINED), | ||
| ), | ||
| // combos | ||
| Span::styled( | ||
| "GHOST ", | ||
| Style::new() | ||
| .fg(Color::DarkGray) | ||
| .add_modifier(Modifier::DIM | Modifier::ITALIC), | ||
| ), | ||
| Span::styled( | ||
| "ALARM ", | ||
| Style::new() | ||
| .fg(Color::Red) | ||
| .add_modifier(Modifier::RAPID_BLINK | Modifier::REVERSED), | ||
| ), | ||
| Span::styled( | ||
| "DEAD ", | ||
| Style::new() | ||
| .fg(Color::Gray) | ||
| .add_modifier(Modifier::CROSSED_OUT | Modifier::DIM), | ||
| ), | ||
| Span::styled( | ||
| "SHOUT ", | ||
| Style::new() | ||
| .fg(Color::Yellow) | ||
| .add_modifier(Modifier::BOLD | Modifier::UNDERLINED), | ||
| ), | ||
| Span::styled( | ||
| "HAUNT ", | ||
| Style::new() | ||
| .fg(Color::Magenta) | ||
| .add_modifier(Modifier::SLOW_BLINK | Modifier::DIM), | ||
| ), | ||
| Span::styled( | ||
| "CRIT", | ||
| Style::new() | ||
| .fg(Color::White) | ||
| .bg(Color::Red) | ||
| .add_modifier(Modifier::BOLD | Modifier::RAPID_BLINK), | ||
| ), | ||
| ]); | ||
|
|
||
| let paragraph = Paragraph::new(vec![line]).wrap(Wrap { trim: true }); | ||
| let bordered_block = Block::bordered() | ||
| .border_style(Style::new().yellow()) | ||
| .title("Mods"); | ||
| frame.render_widget(paragraph.block(bordered_block), frame.area()); | ||
| frame.set_cursor_position((cursor_x, cursor_y)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.