Skip to content

refactor: consolidate packages and add shared terminal module#75

Merged
jiacai2050 merged 5 commits intomainfrom
refactor
Mar 21, 2026
Merged

refactor: consolidate packages and add shared terminal module#75
jiacai2050 merged 5 commits intomainfrom
refactor

Conversation

@jiacai2050
Copy link
Copy Markdown
Owner

Consolidates packages behind a single root library to simplify import statements. Renames simargs to structargs for clarity and introduces a shared term module for styling and utilities.

Consolidates packages behind a single root library to simplify
import statements. Renames simargs to structargs for clarity
and introduces a shared term module for styling and utilities.
Copilot AI review requested due to automatic review settings March 21, 2026 13:04
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the project's module structure by consolidating individual packages under a unified zigcli root module. This change simplifies import statements for consumers and enhances the overall organization of the library. Additionally, the argument parsing module has been renamed for better clarity, and a new module for terminal styling and utilities has been introduced, centralizing common terminal interactions.

Highlights

  • Package Consolidation: The zigcli project's reusable Zig packages (simargs, pretty-table, gitignore) have been consolidated behind a single root module named zigcli. Consumers now import zigcli once and access submodules like zigcli.structargs.
  • Argument Parser Renaming: The simargs module, a struct-based CLI argument parser, has been renamed to structargs for improved clarity. All references and documentation have been updated accordingly.
  • New Terminal Module: A new shared term module has been introduced, providing utilities for ANSI colors, terminal styling (term.Style), and terminal capability helpers like isTty and terminalWidth.
  • Improved Error Handling for structargs: The structargs module now includes enhanced error handling, specifically, print_help_on_error will print the subcommand-specific help context when a subcommand parsing fails, rather than always falling back to the top-level command's help.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a significant and well-executed refactoring that improves the project's structure and maintainability. Consolidating packages under a single zigcli root module, renaming simargs to the more descriptive structargs, and introducing a shared term module for terminal utilities are all excellent changes. The updates are consistently applied across the codebase, including documentation, examples, and the build system. The addition of subcommand-specific help on error in structargs is also a great feature enhancement. I have one minor suggestion for the build script to make it slightly more robust.

build.zig Outdated
Comment on lines +187 to +192
if (b.modules.get("zigcli")) |zigcli_module| {
exe_tests.root_module.addImport("zigcli", zigcli_module);
}
if (b.modules.get("build_info")) |build_info_module| {
exe_tests.root_module.addImport("build_info", build_info_module);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The if checks for the existence of zigcli and build_info modules are a bit too defensive. Since addModules is called unconditionally at the start of the build, these modules should always be present. It would be more robust to assert their existence using .? to ensure that any build misconfiguration fails early and loudly.

Consider replacing this block with:

    exe_tests.root_module.addImport("zigcli", b.modules.get("zigcli").?);
    exe_tests.root_module.addImport("build_info", b.modules.get("build_info").?);

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Consolidates the repo’s reusable Zig modules behind a single zigcli root module, renames the CLI parser module to structargs, and introduces a shared term module for ANSI styling + terminal helpers.

Changes:

  • Added lib.zig root module exporting pretty_table, structargs, gitignore, and term; updated build wiring accordingly.
  • Moved ANSI styling + terminal-width probing into src/mod/term.zig and refactored pretty-table to use it.
  • Renamed/updated imports across binaries, examples, and docs from simargs/individual modules to zigcli.*; improved structargs help printing for subcommand parse errors.

Reviewed changes

Copilot reviewed 16 out of 28 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/mod/term.zig Adds shared ANSI style/color primitives and tty/width helpers.
src/mod/structargs.zig Adjusts help/usage formatting and prints subcommand-context help on parse errors.
src/mod/pretty-table.zig Removes local color impl; uses term.Style and term.terminalWidth().
src/bin/zigfetch.zig Switches CLI parsing import from simargs to zigcli.structargs.
src/bin/zfetch.zig Switches to zigcli.structargs and uses zigcli.term.isTty.
src/bin/tree.zig Switches imports to zigcli.structargs and zigcli.gitignore.
src/bin/tcp-proxy.zig Switches CLI parsing import to zigcli.structargs.
src/bin/repeat.zig Switches CLI parsing import to zigcli.structargs.
src/bin/progress.zig Switches CLI parsing import to zigcli.structargs.
src/bin/pretty-csv.zig Switches to zigcli.structargs and zigcli.pretty_table.
src/bin/pidof.zig Switches CLI parsing import to zigcli.structargs.
src/bin/night-shift.zig Switches CLI parsing import to zigcli.structargs.
src/bin/loc.zig Switches to zigcli.pretty_table, zigcli.structargs, and zigcli.gitignore.
src/bin/dark-mode.zig Switches CLI parsing import to zigcli.structargs.
src/bin/cowsay.zig Switches CLI parsing import to zigcli.structargs.
lib.zig Introduces the single zigcli root module export surface.
examples/structargs-demo.zig Updates example to use zigcli.structargs.
examples/pretty-table-demo.zig Updates example to use zigcli.pretty_table and zigcli.term.Style.Color.
docs/content/programs/tree.org Updates module listing from simargs.zig to structargs.zig.
docs/content/packages/structargs.org Adds new package documentation for structargs.
docs/content/packages/simargs.org Removes old simargs package documentation.
docs/content/packages/pretty-table.org Updates docs to import via zigcli and references term.Style.Color.
docs/content/packages/gitignore.org Updates docs to import via zigcli.gitignore.
docs/content/install.org Updates install instructions to add only the zigcli root module.
build.zig Exposes zigcli module, renames demo step, and adds test-zigcli root tests.
GEMINI.md Updates module naming references (structargs).
CLAUDE.md Updates build/test instructions and package naming references (structargs).
CHANGELOG.md Documents breaking import change + term module + structargs help behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

jiacai2050 and others added 3 commits March 21, 2026 21:12
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jiacai2050 jiacai2050 requested a review from Copilot March 21, 2026 13:35
@jiacai2050
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent refactoring that significantly improves the project's structure and maintainability. Consolidating packages under a single zigcli root, renaming simargs to structargs, and introducing a shared term module are all great steps forward. The implementation is clean and consistent across the codebase. I have a couple of minor suggestions to enhance the build script's consistency and optimize the new term module.

build.zig Outdated
Comment on lines +86 to +88
inline for (.{ "pretty-table", "structargs", "gitignore" }) |name| {
all_tests.dependOn(buildTestStep(b, .{ .mod = name }, target));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The new term module contains tests, but it's not included in this loop for generating individual test steps. While its tests are run as part of test-zigcli, adding it here would create a zig build test-term step. This would improve consistency with how other modules like pretty-table and structargs are handled, and make it easier to run the term module's tests in isolation.

    inline for (.{ "pretty-table", "structargs", "gitignore", "term" }) |name| {
        all_tests.dependOn(buildTestStep(b, .{ .mod = name }, target));
    }

Comment on lines +106 to +119
pub fn writePrefix(self: Style, writer: *std.Io.Writer) !void {
if (self.bold) {
try writer.writeAll("\x1b[1m");
}
if (self.italic) {
try writer.writeAll("\x1b[3m");
}
if (self.fg) |fg_color| {
try writer.writeAll(fg_color.toEscapeCode());
}
if (self.bg) |bg_color| {
try writer.writeAll(bg_color.toBgEscapeCode());
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This function sends a separate ANSI escape sequence for each style attribute (bold, italic, colors). It's more efficient and conventional to combine these into a single SGR escape sequence. For example, \x1b[1m\x1b[31m can be sent as \x1b[1;31m.

Refactoring this to build a single sequence before writing would reduce the number of I/O calls and align with standard terminal practices.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 30 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +198 to +202
) *Step {
const exe_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"),
.target = target,
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

buildRootTestStep creates the module without setting .optimize. Elsewhere (e.g., the executable compile step) you pass .optimize = optimize, so this test target may not respect -Doptimize=.... Consider plumbing optimize into buildRootTestStep and setting it on b.createModule for consistent build modes.

Suggested change
) *Step {
const exe_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"),
.target = target,
) *Step {
const optimize = b.standardOptimizeOption(.{});
const exe_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"),
.target = target,
.optimize = optimize,

Copilot uses AI. Check for mistakes.
Comment on lines 184 to +188
const exe_tests = b.addTest(.{
.root_module = module,
});
exe_tests.root_module.addImport("zigcli", b.modules.get("zigcli").?);
exe_tests.root_module.addImport("build_info", b.modules.get("build_info").?);
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

In buildTestStep, the module assigned to exe_tests.root_module is created via b.createModule a few lines above without an explicit .optimize. This can make test builds use a different optimization mode than the main executable builds (which pass .optimize = optimize). Consider plumbing optimize into buildTestStep and setting it on the module for consistent -Doptimize=... behavior.

Copilot uses AI. Check for mistakes.
Removes specific test steps for modules from build.zig. Use zig build test-zigcli to verify all reusable module tests. This unifies the testing process into the root module execution.
@jiacai2050 jiacai2050 merged commit 545559f into main Mar 21, 2026
12 checks passed
@jiacai2050 jiacai2050 deleted the refactor branch March 21, 2026 13:47
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