Skip to content
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

Godzie44/run as widget #73

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

godzie44
Copy link
Contributor

@godzie44 godzie44 commented Oct 7, 2024

Description of change

Tui component has been removed. Integration with third-party applications has been simplified.

@godzie44 godzie44 mentioned this pull request Oct 7, 2024
@orhun
Copy link
Owner

orhun commented Oct 8, 2024

Can you go through your changes a bit and tell me about the rationales? Comparing widget.rs with the current demo.rs, I don't see how this makes things more simple 🤔

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 111 lines in your changes missing coverage. Please review.

Project coverage is 3.31%. Comparing base (19bea73) to head (8395b85).

Files with missing lines Patch % Lines
src/lib.rs 0.00% 70 Missing ⚠️
src/tui/mod.rs 0.00% 18 Missing ⚠️
src/tui/event.rs 0.00% 10 Missing ⚠️
src/file.rs 0.00% 9 Missing ⚠️
src/app.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main     #73      +/-   ##
========================================
- Coverage   3.31%   3.31%   -0.00%     
========================================
  Files         19      19              
  Lines       2419    2422       +3     
========================================
  Hits          80      80              
- Misses      2339    2342       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@godzie44
Copy link
Contributor Author

godzie44 commented Oct 8, 2024

Currently it's make possible to handle restart event correctly - because now, only this event requires user implementation. Tui component removed, and manipulation with terminal at restart, or dynamic analysis removed too, I hope that this will allow to integrate binsider nto existing tui's like window-in-window.

About simplification - if you compare with demo.rs, then all event processing is now hidden in the handle_event function, and only cumbersome initialization remains (it can be hidden in the next step of refactoring)

@orhun
Copy link
Owner

orhun commented Oct 9, 2024

I see. I think it would be easier to review this after seeing the usage in action. So if you can incorporate these changes in #45, I can take a look again :)

@godzie44
Copy link
Contributor Author

godzie44 commented Oct 9, 2024

You can check this out now

Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was traveling - sorry for the delay. Just got a chance to look at this again :)

Comment on lines -19 to +25
pub struct FileInfo<'a> {
pub struct FileInfo {
/// Path of the file.
pub path: &'a str,
pub path: String,
/// Arguments of the file.
pub arguments: Option<Vec<&'a str>>,
pub arguments: Option<Vec<String>>,
/// Bytes of the file.
pub bytes: &'a [u8],
pub bytes: Box<[u8]>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to remove the lifetimes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short answer - beacause now all application live in one loop in lib.rs (without recreating it with run function).

More detailed. Reference path: &'a str removed because when wee create a new analyzer in Event::Restart handler live time of analizer (and FileInfo in it) is greater than the lifetime of the variable path from the event. &'a [u8] changed to Box<[u8]> with same reason, file data will be freed but we still need it in an analyzer. I dont think that this is a big problem at all, Box<[u8]> still protects us from copy of the file data, and own file path instead of reference to it - not a big overhead.

crossterm::event::{KeyCode},
Frame,
};
use binsider::prelude::Event;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the other implicit imports (e.g. binsider::file and so on) and use the prelude module? Feel free to update the prelude if we are not already covering some of the types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

binsider::app::Analyzer::new(file_info, 15, vec![]).unwrap();

state.change_analyzer(analyzer);
state.handle_tab().unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid unwraps in the example. I think we can return the error type from the library instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/tui/mod.rs Outdated
.store(self.paused, Ordering::Relaxed);
Ok(())
}
pub fn tui_toggle_pause(paused: &mut bool, events: &EventHandler) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on this change a bit and explain the rationale?

I honestly don't like the way that this currently works. Instead of taking a mutable reference to a bool, we should handle this in a more stateful way - that's why I had the Tui struct before.

Copy link
Contributor Author

@godzie44 godzie44 Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can remove paused variable and simply lock user input at Event::Trace event, and unlock at Event::TraceResult.

src/tui/state.rs Outdated
@@ -91,6 +91,10 @@ impl<'a> State<'a> {
state.handle_tab()?;
Ok(state)
}

pub fn change_analyzer(&mut self, analyzer: Analyzer<'a>) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

analyzer is a public field, do we need this function? (if so, let's rename it to update_analyzer)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, i think more consistently will be remove this

src/tui/mod.rs Outdated Show resolved Hide resolved
@godzie44 godzie44 force-pushed the godzie44/run_as_widget branch 2 times, most recently from f0fe341 to dc54752 Compare October 27, 2024 13:33
@godzie44 godzie44 marked this pull request as ready for review October 27, 2024 13:33
This will help to embedding binsider into another TUI applications.
@godzie44
Copy link
Contributor Author

godzie44 commented Nov 4, 2024

@orhun please check this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants