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

search: Show progress on stderr #4938

Merged
merged 2 commits into from
Feb 26, 2025

Conversation

kazarmy
Copy link
Member

@kazarmy kazarmy commented Feb 26, 2025

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository.
  • I made sure to follow the project's coding style.
  • I've documented every RZ_API function and struct this PR changes.
  • I've added tests that prove my changes are effective (required for changes to RZ_API).
  • I've updated the Rizin book with the relevant information (if needed).

Detailed description

This pr makes the search module show progress on stderr instead of stdout because the progress notifications:

  1. Are not part of the results.
  2. Messes up grep.

Test plan

All builds are green.

Closing issues

...

@@ -2436,7 +2436,7 @@ static int pass_to_legacy_api(RzCore *core, int argc, const char **argv, RzOutpu
static bool cmd_search_progress_cancel(void *user, size_t n_hits, RzSearchCancelReason invoke_reason) {
if (user) {
// we have RzCmdStateOutput state
rz_cons_printf("Searching... hits: %" PFMTSZu "\r", n_hits);
eprintf("Searching... hits: %" PFMTSZu "\r", n_hits);
Copy link
Member

Choose a reason for hiding this comment

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

In general yes, but didn't we want to remove the usage of eprintf?
Maybe add a rz_cons_eprintf() function.

Copy link
Member

Choose a reason for hiding this comment

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

So we have at least a central point to start refactoring, once we start with the TUI.

Copy link
Member Author

Choose a reason for hiding this comment

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

What would rz_cons_eprintf() do?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind. I just recognized I probably don't understand rz_cons. Keep it like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was about to push

diff --git a/librz/core/cmd/cmd_search.c b/librz/core/cmd/cmd_search.c
index 5c4135e22a..6636ed1389 100644
--- a/librz/core/cmd/cmd_search.c
+++ b/librz/core/cmd/cmd_search.c
@@ -2436,7 +2436,7 @@ static int pass_to_legacy_api(RzCore *core, int argc, const char **argv, RzOutpu
 static bool cmd_search_progress_cancel(void *user, size_t n_hits, RzSearchCancelReason invoke_reason) {
        if (user) {
                // we have RzCmdStateOutput state
-               eprintf("Searching... hits: %" PFMTSZu "\r", n_hits);
+               rz_cons_eprintf("Searching... hits: %" PFMTSZu "\r", n_hits);
        }
        return rz_cons_is_breaked();
 }
diff --git a/librz/include/rz_cons.h b/librz/include/rz_cons.h
index 0e2bee4438..578cf9efb6 100644
--- a/librz/include/rz_cons.h
+++ b/librz/include/rz_cons.h
@@ -956,6 +956,7 @@ RZ_API void rz_cons_grep(const char *grep);
 /* output */
 RZ_API int rz_cons_printf(const char *format, ...) RZ_PRINTF_CHECK(1, 2);
 RZ_API void rz_cons_printf_list(const char *format, va_list ap);
+#define rz_cons_eprintf(...) eprintf(__VA_ARGS__)
 RZ_API void rz_cons_strcat(const char *str);
 RZ_API void rz_cons_strcat_at(const char *str, int x, char y, int w, int h);
 #define rz_cons_print(x) rz_cons_strcat(x)

but that rz_cons_eprintf() macro is basically an outsider i.e. definitely not involved with the internals of rz_cons so I think using eprintf() is better.

Copy link
Member

Choose a reason for hiding this comment

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

lgtm as well

Copy link
Member Author

Choose a reason for hiding this comment

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

But who knows you might want to control where stderr output is going to e.g. a TUI panel.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just a simple pr though.

Copy link
Member

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

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

Happy merging

@kazarmy kazarmy merged commit c60fe9a into rizinorg:dev Feb 26, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants