Skip to content

pretty-table: add Cell struct with per-cell styling and horizontal span#63

Merged
jiacai2050 merged 10 commits intomainfrom
copilot/improve-pretty-table
Mar 16, 2026
Merged

pretty-table: add Cell struct with per-cell styling and horizontal span#63
jiacai2050 merged 10 commits intomainfrom
copilot/improve-pretty-table

Conversation

Copy link
Contributor

Copilot AI commented Mar 14, 2026

Adds a Cell type to pretty-table enabling per-cell ANSI styling (bold, italic, fg/bg color) and horizontal column spanning (hspan). Previously rows were [n][]const u8; now they are [n]Cell, with Cell.init(text) as the zero-cost default path.

API changes (src/mod/pretty-table.zig)

  • New Cell struct with builder methods: init, span, withBold, withItalic, withFg, withBg, withHspan
  • Row(n) is now [n]Cell; plain-text usage wraps strings with Cell.init(...)
  • Table gains column_align, padding, and row_separator fields
  • Removed cell_colors, header_color, footer_color fields (superseded by per-cell styling)
  • Column-width calculation handles multi-column spans in two passes: non-spanning cells first, then expand the last spanned column to fit

Span usage example

const t = Table(3){
    .header = [_]Cell{ Cell.init("Name"), Cell.init("Q1"), Cell.init("Q2") },
    .rows = &[_][3]Cell{
        .{ Cell.init("Alice"), Cell.init("90"), Cell.init("85") },
        // "Total" spans both Q columns; the placeholder Cell.span() fills position 2
        .{ Cell.init("Bob"), Cell.init("On leave").withHspan(2), Cell.span() },
    },
};

Consumers updated

  • src/bin/loc.zig: rows and header updated from []const u8 to Cell.init(...) wrappers — no behavioral change
  • examples/pretty-table-demo.zig and docs/content/packages/pretty-table.org updated to reflect new API

Scope

src/mod/simargs.zig and all other src/bin/*.zig files are unchanged from the merge base — this PR is strictly scoped to pretty-table.

Original prompt

This section details on the original issue you should resolve

<issue_title>Improve pretty-table</issue_title>
<issue_description>Reference:

<agent_instructions>请参考 https://github.com/phsym/prettytable-rs 这个 rust 库的功能,改进我们的 pretty-table 实现,让其功能更加丰富</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…separators

Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve pretty-table functionality pretty-table: add cell alignment, symmetric padding, and row separators Mar 14, 2026
Copilot AI requested a review from jiacai2050 March 14, 2026 12:35
@jiacai2050
Copy link
Owner

能再给表格里的数据加上颜色吗?我看它是支持的

Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title pretty-table: add cell alignment, symmetric padding, and row separators pretty-table: add ANSI foreground color support Mar 14, 2026
Copilot stopped work on behalf of jiacai2050 due to an error March 15, 2026 14:17
Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title pretty-table: add ANSI foreground color support pretty-table: replace table-level color fields with per-cell Cell struct Mar 15, 2026
Copilot AI and others added 3 commits March 15, 2026 14:55
Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title pretty-table: replace table-level color fields with per-cell Cell struct pretty-table: per-cell styling via Cell struct + TigerStyle compliance Mar 15, 2026
Copilot AI added a commit that referenced this pull request Mar 15, 2026
… for PR #63)

Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title pretty-table: per-cell styling via Cell struct + TigerStyle compliance pretty-table: per-cell styling, column alignment, hspan, and TigerStyle compliance Mar 16, 2026
Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title pretty-table: per-cell styling, column alignment, hspan, and TigerStyle compliance Fix Zig 0.15.2 compilation error in pretty-table tests Mar 16, 2026
…al column widths

Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title Fix Zig 0.15.2 compilation error in pretty-table tests Fix pretty-table CI: fmt violation, compile error, and test panic in hspan tests Mar 16, 2026
@jiacai2050 jiacai2050 marked this pull request as ready for review March 16, 2026 02:29
Copilot AI review requested due to automatic review settings March 16, 2026 02:29
Copy link
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

This PR performs a major refactoring of both simargs and pretty-table modules. The simargs API is modernized with a ParseOptions struct, renamed fields (argsoptions, positional_argspositional_arguments, programprogram_name), and improved naming throughout. The pretty-table module gains a Cell struct with per-cell ANSI styling (bold, italic, fg/bg colors), column alignment, row separators, and horizontal column spanning (hspan).

Changes:

  • Refactored simargs public API: introduced ParseOptions struct, renamed StructArguments to ParseResult, and updated all callers across binaries and examples.
  • Enhanced pretty-table with Cell, Color, Align types, column spanning support, and row separators, replacing raw String rows.
  • Added TigerStyle coding guidelines skill file and updated documentation.

Reviewed changes

Copilot reviewed 6 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/mod/simargs.zig Major API refactor: ParseOptions, renamed types/fields, improved naming conventions
src/mod/pretty-table.zig New Cell/Color/Align types, hspan support, alignment, row separators, extensive tests
src/bin/*.zig Updated all callers to new simargs API (options, positional_arguments, ParseOptions)
examples/simargs-demo.zig Updated to new simargs API
examples/pretty-table-demo.zig Rewritten to showcase new pretty-table features
docs/content/packages/pretty-table.org Updated docs for Cell API and new features
.agents/skills/zig-tiger-style/SKILL.md Added TigerStyle coding guidelines
src/bin/loc.zig Updated to use Cell for table data

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

You can also share your feedback on Copilot code review. Take the survey.

return switch (@typeInfo(option_type)) {
.int => |int_info| int_info.signedness,
.optional => |optional_info| getSignedness(optional_info.child),
else => .unsigned,
Comment on lines +416 to +418
comptime Options: type,
) OptionType {
return Self.convert(T, false);
return Self.convert(Options, false);
Comment on lines +27 to +30
pub const ParseOptions = struct {
argument_prompt: ?[]const u8 = null,
version_string: ?[]const u8 = null,
};
…ll file

Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
Copilot AI changed the title Fix pretty-table CI: fmt violation, compile error, and test panic in hspan tests pretty-table: add Cell struct with per-cell styling and horizontal span Mar 16, 2026
@jiacai2050 jiacai2050 merged commit 100d69a into main Mar 16, 2026
8 checks passed
@jiacai2050 jiacai2050 deleted the copilot/improve-pretty-table branch March 16, 2026 03:03
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.

Improve pretty-table

3 participants