-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: simplify code by removing unused methods and adjusting visi… #15
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
Changes from all commits
620d7e0
2b5c5c7
3fa893d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,15 +16,6 @@ pub enum Color { | |
| } | ||
|
|
||
| impl Color { | ||
| /// Convert the color to an ANSI escape code. | ||
| /// | ||
| /// Returns an ANSI escape code string for the color. | ||
| pub fn to_ansi(&self, fg: bool) -> String { | ||
| let mut buf = String::with_capacity(20); | ||
| self.write_ansi(fg, &mut buf); | ||
| buf | ||
| } | ||
|
|
||
| /// Write ANSI escape code directly into an existing buffer, avoiding allocation. | ||
| pub fn write_ansi(&self, fg: bool, buf: &mut String) { | ||
| use std::fmt::Write; | ||
|
Comment on lines
18
to
21
|
||
|
|
@@ -77,14 +68,4 @@ mod tests { | |
| let color = Color::default(); | ||
| assert_eq!(color, Color::None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_color_to_ansi() { | ||
| assert!(Color::Black.to_ansi(true).contains("30m")); | ||
| assert!(Color::Red.to_ansi(false).contains("41m")); | ||
| assert!(Color::RGB(255, 0, 0).to_ansi(true).contains("38;2;255;0;0")); | ||
| assert!(Color::HSV(0, 255, 255) | ||
| .to_ansi(true) | ||
| .contains("38;2;255;0;0")); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,10 +18,8 @@ The library is organized into several core modules: | |||||||||
| - [`framebuffer`] - Character grid for efficient rendering | ||||||||||
| - [`window`] - High-level windowing abstraction with thread management | ||||||||||
| - [`input`] - Non-blocking keyboard and mouse input handling | ||||||||||
| - [`term`] - Terminal colors, attributes, and ANSI escape sequences | ||||||||||
| - [`attr`] - Text attributes and styling | ||||||||||
| - [`color`] - Color manipulation and conversion utilities | ||||||||||
| - [`render`] - Rendering utilities and drawing primitives | ||||||||||
|
|
||||||||||
| ## Performance | ||||||||||
|
|
||||||||||
|
|
@@ -43,22 +41,22 @@ pub mod framebuffer; | |||||||||
| /// A module for handling user input. | ||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| pub mod input; | ||||||||||
| /// A module for a rendering context. | ||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| pub mod render; | ||||||||||
| /// A module for handling terminal colors and attributes. | ||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| pub mod term; | ||||||||||
| /// A module for handling windowing. | ||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| pub mod window; | ||||||||||
|
|
||||||||||
| mod macros; | ||||||||||
| /// A module for a rendering context. | ||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| pub(crate) mod render; | ||||||||||
| /// A module for handling terminal colors and attributes. | ||||||||||
| #[cfg(target_os = "linux")] | ||||||||||
| pub(crate) mod term; | ||||||||||
|
Comment on lines
+49
to
+53
|
||||||||||
|
|
||||||||||
| pub use attr::*; | ||||||||||
| pub use color::*; | ||||||||||
| pub use framebuffer::*; | ||||||||||
| pub use input::*; | ||||||||||
| pub use render::*; | ||||||||||
| pub use term::*; | ||||||||||
| pub use window::*; | ||||||||||
|
|
||||||||||
| pub(crate) use render::*; | ||||||||||
| pub(crate) use term::*; | ||||||||||
|
Comment on lines
+61
to
+62
|
||||||||||
| pub(crate) use render::*; | |
| pub(crate) use term::*; | |
| pub use render::*; | |
| pub use term::*; |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render and term are #[cfg(target_os = "linux")], but the pub(crate) use render::*; / pub(crate) use term::*; re-exports are unconditional. This will fail to compile on non-Linux targets because those modules won't exist. Gate these re-exports with the same cfg (or a broader cfg that matches intended platform support).
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,7 @@ use std::time; | |||||||
| use crate::Framebuffer; | ||||||||
|
|
||||||||
| /// Represents a render thread for rendering frames. | ||||||||
| pub struct RenderThread { | ||||||||
| pub(crate) struct RenderThread { | ||||||||
| /// The thread handle for the render thread. | ||||||||
| handle: Option<thread::JoinHandle<()>>, | ||||||||
| /// The stop signal sender for the render thread. | ||||||||
|
|
@@ -26,7 +26,7 @@ impl RenderThread { | |||||||
| /// * `rendering_rate` - The rate at which to render frames. | ||||||||
| /// | ||||||||
| /// Returns `RenderThread` instance. | ||||||||
| pub fn new( | ||||||||
| pub(crate) fn new( | ||||||||
| front_fb: Arc<Mutex<Framebuffer>>, | ||||||||
| back_fb: Arc<Mutex<Framebuffer>>, | ||||||||
| rendering_rate: time::Duration, | ||||||||
|
|
@@ -64,9 +64,7 @@ impl RenderThread { | |||||||
| } | ||||||||
| } | ||||||||
| Err(TryLockError::WouldBlock) => { | ||||||||
| // back_fb is locked by draw(); retry immediately without | ||||||||
| // resetting the frame timer so the next iteration does not | ||||||||
| // sleep a full rendering_rate before retrying. | ||||||||
| thread::yield_now(); // Yield to other threads if the back framebuffer is currently locked | ||||||||
|
||||||||
| thread::yield_now(); // Yield to other threads if the back framebuffer is currently locked | |
| thread::yield_now(); // Yield to other threads if the back framebuffer is currently locked | |
| continue; // Retry immediately instead of proceeding with frame pacing logic |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On WouldBlock, the render loop now yield_now() and immediately continues without any sleep/backoff. Because Window::draw() holds the back_fb lock across an arbitrary user-provided closure, this can result in a hot retry loop and elevated CPU usage when drawing takes longer than a frame. Consider adding a small bounded backoff (e.g., short sleep/spin with exponential backoff) or restructuring so the render thread blocks more efficiently when the back buffer is contended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attr::to_ansi()was removed, which is a breaking change for any downstream code that used it (even thoughwrite_ansiremains). Consider keepingto_ansias a thin wrapper aroundwrite_ansiand deprecating it, or ensure the crate versioning/docs clearly communicate the API removal.