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

Add a new parameter max_width to MyPrettyTable #2426

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

DarkaMaul
Copy link
Contributor

@DarkaMaul DarkaMaul commented Apr 15, 2024

Add a new parameter max_width to MyPrettyTable to enhance its display for CLI usage

This PR adds a max_width parameter to MyPrettyTable to restrict the maximum width of its underlying table.

The value can be an integer, "max" (detect automatically the correct width) or None (no width limit)

The output is better, and will be even better once prettytable will be upgraded to 3.10.1 on PyPi
https://github.com/jazzband/prettytable/releases/tag/3.10.1

Summary by CodeRabbit

  • New Features

    • Introduced the ability to set a maximum width for tables, improving readability based on terminal size.
  • Bug Fixes

    • Cleaned up multi-line help information for better display in command line outputs.
  • Chores

    • Updated prettytable package version requirement to >=3.10.0.

…ay for CLI usage

This PR adds a `max_width` parameter to MyPrettyTable to restrict the maximum width of its underlying table.

The value can be an integer, "max" (detect automatically the correct width) or None (no width limit)
Copy link

coderabbitai bot commented Apr 15, 2024

Walkthrough

Walkthrough

The changes involve updating the version requirement for the prettytable package, improving the LocPrinter class by cleaning up multi-line strings, enhancing table formatting in command-line utilities, and adding a max_width parameter to the MyPrettyTable class. These updates improve code readability, table formatting, and functionality by allowing dynamic adjustment of table width based on terminal size.

Changes

Files/Directories Change Summary
setup.py Updated prettytable package version requirement from >=3.3.0 to >=3.10.0.
slither/printers/summary/loc.py Cleaned up trailing whitespace in the HELP attribute of the LocPrinter class.
slither/utils/command_line.py Improved table formatting in output_detectors and output_printers functions, including handling multi-line help information and setting table width.
slither/utils/myprettytable.py Added max_width parameter to MyPrettyTable class, allowing dynamic table width adjustment based on terminal size. Updated imports and methods accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CommandLine
    participant MyPrettyTable
    participant Terminal

    User->>CommandLine: Run a command
    CommandLine->>MyPrettyTable: Initialize table with max_width="max"
    MyPrettyTable->>Terminal: Get terminal size
    Terminal-->>MyPrettyTable: Return terminal dimensions
    MyPrettyTable->>CommandLine: Return formatted table
    CommandLine-->>User: Display formatted table
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DarkaMaul
Copy link
Contributor Author

I would keep this onhold until prettytable is upgraded upstream.

@0xalpharush 0xalpharush marked this pull request as ready for review June 3, 2024 16:55
@0xalpharush 0xalpharush marked this pull request as draft June 4, 2024 13:10
@DarkaMaul DarkaMaul marked this pull request as ready for review June 11, 2024 12:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (3)
setup.py (1)

Line range hint 3-3: Remove unnecessary open mode parameters.

- with open("README.md", "r", encoding="utf-8") as f:
+ with open("README.md", encoding="utf-8") as f:
slither/utils/command_line.py (2)

Line range hint 126-126: Convert to not in for membership tests to improve readability.

- if not filter_wiki in detector.WIKI:
+ if filter_wiki not in detector.WIKI:

Also applies to: 240-240


Line range hint 157-157: Consider renaming the variable l to something more descriptive to avoid ambiguity.

- for l in lines:
+ for line in lines:

Also applies to: 171-171

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 02df0dc and dbe67f3.

Files selected for processing (4)
  • setup.py (1 hunks)
  • slither/printers/summary/loc.py (1 hunks)
  • slither/utils/command_line.py (2 hunks)
  • slither/utils/myprettytable.py (5 hunks)
Files skipped from review due to trivial changes (1)
  • slither/printers/summary/loc.py
Additional context used
Ruff
setup.py

3-3: Unnecessary open mode parameters (UP015)

Remove open mode parameters

slither/utils/command_line.py

126-126: Test for membership should be not in (E713)

Convert to not in


157-157: Ambiguous variable name: l (E741)


171-171: Ambiguous variable name: l (E741)


240-240: Test for membership should be not in (E713)

Convert to not in

Additional comments not posted (3)
setup.py (1)

16-16: Update to prettytable version requirement is aligned with the PR's objectives.

slither/utils/myprettytable.py (1)

Line range hint 11-37: The implementation of the max_width parameter in MyPrettyTable is well-handled, including terminal size detection.

slither/utils/command_line.py (1)

275-277: The use of the max_width="max" parameter in output functions aligns with the PR's objectives to improve table formatting.

Also applies to: 359-359

slither/utils/myprettytable.py Show resolved Hide resolved
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.

None yet

1 participant