-
Notifications
You must be signed in to change notification settings - Fork 1.6k
runmode-lists: Fix --list-runmodes table alignment and formatting #14012
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
base: main
Are you sure you want to change the base?
Conversation
- Align columns for RunMode Type, Custom Mode, and Description - Remove redundant horizontal separators for cleaner output - Show RunMode Type only once per multi-mode group - Improve readability and consistency of --list-runmodes table Signed-off-by: Promise Charles <[email protected]>
640e27e
to
5de7f85
Compare
NOTE: This PR may contain new authors. |
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.
Please:
- add tests if possible as asked on the previous rev.
- make sure the code compiles locally before sending a PR.
- fix commit message to follow proper guidelines. A recent example: 0af7793
* \brief Lists all registered runmodes. | ||
* \brief Lists all registered runmodes (optimized table output). | ||
*/ | ||
void RunModeListRunmodes(void) | ||
{ | ||
printf("------------------------------------- Runmodes -------------------" | ||
"-----------------------\n"); | ||
|
||
printf("| %-17s | %-17s | %-10s \n", | ||
"RunMode Type", "Custom Mode ", "Description"); | ||
printf("|-----------------------------------------------------------------" | ||
"-----------------------\n"); | ||
int i = RUNMODE_UNKNOWN + 1; | ||
int j = 0; | ||
for ( ; i < RUNMODE_USER_MAX; i++) { | ||
int mode_displayed = 0; | ||
for (j = 0; j < runmodes[i].cnt; j++) { | ||
if (mode_displayed == 1) { | ||
printf("| ----------------------------------------------" | ||
"-----------------------\n"); | ||
RunMode *runmode = &runmodes[i].runmodes[j]; | ||
printf("| %-17s | %-17s | %-27s \n", | ||
"", | ||
runmode->name, | ||
runmode->description); | ||
} else { | ||
RunMode *runmode = &runmodes[i].runmodes[j]; | ||
printf("| %-17s | %-17s | %-27s \n", | ||
RunModeTranslateModeToName(runmode->runmode), | ||
runmode->name, | ||
runmode->description); | ||
} | ||
if (mode_displayed == 0) | ||
mode_displayed = 1; | ||
int type_width = 12; | ||
int mode_width = 10; | ||
const int desc_width = 60; | ||
|
||
/* Dynamically calculate max column widths */ | ||
for (int i = RUNMODE_UNKNOWN + 1; i < RUNMODE_USER_MAX; i++) { | ||
for (int j = 0; j < runmodes[i].cnt; j++) { | ||
RunMode *r = &runmodes[i].runmodes[j]; | ||
int tlen = strlen(RunModeTranslateModeToName(r->runmode)); | ||
int mlen = strlen(r->name); | ||
if (tlen > type_width) | ||
type_width = tlen; | ||
if (mlen > mode_width) | ||
mode_width = mlen; | ||
} | ||
if (mode_displayed == 1) { | ||
printf("|-----------------------------------------------------------------" | ||
"-----------------------\n"); | ||
} | ||
|
||
/* Print header */ | ||
printf("\n%-*s\n", type_width + mode_width + desc_width + 10, | ||
"--------------------------- Runmodes ---------------------------"); | ||
printf("| %-*s | %-*s | %-*s |\n", | ||
type_width, "RunMode Type", | ||
mode_width, "Custom Mode", | ||
desc_width, "Description"); | ||
|
||
/* Separator function */ | ||
auto void PrintSeparator(void) { | ||
printf("|-%.*s-|-%.*s-|-%.*s-|\n", | ||
type_width + 2, "----------------------------------------", | ||
mode_width + 2, "----------------------------------------", | ||
desc_width + 2, "------------------------------------------------------------"); | ||
}; | ||
PrintSeparator(); | ||
|
||
/* Print runmodes */ | ||
for (int i = RUNMODE_UNKNOWN + 1; i < RUNMODE_USER_MAX; i++) { | ||
int printed = 0; | ||
for (int j = 0; j < runmodes[i].cnt; j++) { | ||
RunMode *r = &runmodes[i].runmodes[j]; | ||
const char *type_name = RunModeTranslateModeToName(r->runmode); | ||
|
||
printf("| %-*s | %-*s | %-*s |\n", | ||
printed ? 0 : type_width, | ||
printed ? "" : type_name, | ||
mode_width, r->name, | ||
desc_width, r->description); | ||
printed = 1; | ||
} | ||
if (printed) | ||
PrintSeparator(); | ||
} | ||
} | ||
|
||
printf("\n"); | ||
} |
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.
Any proposed modification must first go in Discord/Redmine. So, let's stick to what's required by the ticket you're working on for now and remove these changes.
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.
Any proposed modification must first go in Discord/Redmine. So, let's stick to what's required by the ticket you're working on for now and remove these changes.
Ok. will do that.
SCInstance *suri = &suricata; | ||
switch (suri->run_mode) { | ||
case RUNMODE_UNKNOWN: | ||
printf("\n[!] No capture/runmode specified.\n"); |
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.
Victor's review comments from the previous PR must be addressed.
Make sure these boxes are checked accordingly before submitting your Pull Request -- thank you.
Contribution style:
https://docs.suricata.io/en/latest/devguide/contributing/contribution-process.html
Our Contribution agreements:
https://suricata.io/about/contribution-agreement/ (note: this is only required once)
Changes (if applicable):
(including schema descriptions)
https://redmine.openinfosecfoundation.org/issues/6572
Link to ticket: https://redmine.openinfosecfoundation.org/issues/6572
Describe changes:
Provide values to any of the below to override the defaults.
link to the pull request in the respective
_BRANCH
variable.SV_REPO=
SV_BRANCH=
SU_REPO=
SU_BRANCH=