feat: support console.table#14338
Merged
zerosnacks merged 11 commits intofoundry-rs:masterfrom Apr 22, 2026
Merged
Conversation
mablr
previously approved these changes
Apr 17, 2026
Amp-Thread-ID: https://ampcode.com/threads/T-019db45a-2ee1-771d-8127-2052dc6df2a3 Co-authored-by: Amp <amp@ampcode.com>
Replace fragile name-based detection (`starts_with("table")`) with a
structural check: table call structs have all fields of type `Vec<T>`
(Solidity arrays), while regular `log` calls never use array parameters.
…elds
Combine the name-based check (`starts_with("table")`) with the
structural Vec<T> field check so both must hold. This prevents
accidental table rendering for unrelated structs that happen to
have all-Vec fields.
mablr
reviewed
Apr 22, 2026
Collaborator
mablr
left a comment
There was a problem hiding this comment.
Made table detection more robust.
s/o @zerosnacks for guidance 🫡
Contributor
Author
|
Thank you both for the nice improvements ! |
mablr
approved these changes
Apr 22, 2026
zerosnacks
added a commit
to foundry-rs/forge-std
that referenced
this pull request
Apr 22, 2026
Resolves #91 - Depends on foundry-rs/foundry#14338 Two of the most common use-cases for tables are easily logging arrays and comparing multiple labelled values, which often leads the user to manually line up the values like so: ```solidity console.log("alice ", 0x328809Bc894f92807417D2dAD6b7C998c1aFdac6); console.log("bob ", 0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e); console.log("charlie", 0xea475d60c118d7058beF4bDd9c32bA51139a74e0); ``` Both of those use-cases can be solved with a table with a single column of values. For this reason and because it would double the variants, I've opted to not support tables with multiple value columns, though it can be added in the future. This adds 12 variants for `console.table`: - 6 single-array (auto-indexed, array of values) - 6 keyed (`string[]` indexes, array of values) Value types supported: `uint256`, `int256`, `address`, `bytes32`, `string`, `bool`. Some notes: - I've added this to `console` and not `console2` since it's just adding new functionality and not introducing any breaking changes. For `console2` to inherit from `console` and have its own new methods, I would need to import each method from `console` and define new ones in `console2` since libraries don't support inheritance, which would be a lot of maintenance, and also would involve the question of whether to use the same `CONSOLE_ADDRESS` - I've chosen the box characters `┌`, `─`, `┼`, `│`, etc. to more closely match Node.js's `console.table` output and because it's more aesthetically pleasing, but if preferred, a simpler option is to use the ASCII version with just `-`, `+`, `|` Usage example: ```solidity string[] memory idxs = new string[](3); idxs[0] = "alice"; idxs[1] = "bob"; idxs[2] = "charlie"; address[] memory addrs = new address[](3); bytes32[] memory hashes = new bytes32[](3); for (uint256 i = 0; i < idxs.length; i++) { addrs[i] = makeAddr(idxs[i]); hashes[i] = keccak256(abi.encodePacked(idxs[i])); } console.table(addrs); console.table(idxs, addrs); console.table(idxs, hashes); ``` Output: ```txt Logs: ┌─────────┬────────────────────────────────────────────┐ │ (index) │ Values │ ├─────────┼────────────────────────────────────────────┤ │ 0 │ 0x328809Bc894f92807417D2dAD6b7C998c1aFdac6 │ │ 1 │ 0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e │ │ 2 │ 0xea475d60c118d7058beF4bDd9c32bA51139a74e0 │ └─────────┴────────────────────────────────────────────┘ ┌─────────┬────────────────────────────────────────────┐ │ (index) │ Values │ ├─────────┼────────────────────────────────────────────┤ │ alice │ 0x328809Bc894f92807417D2dAD6b7C998c1aFdac6 │ │ bob │ 0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e │ │ charlie │ 0xea475d60c118d7058beF4bDd9c32bA51139a74e0 │ └─────────┴────────────────────────────────────────────┘ ┌─────────┬────────────────────────────────────────────────────────────────────┐ │ (index) │ Values │ ├─────────┼────────────────────────────────────────────────────────────────────┤ │ alice │ 0x9c0257114eb9399a2985f8e75dad7600c5d89fe3824ffa99ec1c3eb8bf3b0501 │ │ bob │ 0x38e47a7b719dce63662aeaf43440326f551b8a7ee198cee35cb5d517f2d296a2 │ │ charlie │ 0x87a213ce1ee769e28decedefb98f6fe48890a74ba84957ebf877fb591e37e0de │ └─────────┴────────────────────────────────────────────────────────────────────┘ ``` Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
console.tableformatting.Changes:
Console.jsonto include the 12 newtablevariantsconsole_table_formatConsoleFmtderive macro to handletablecall structsPR Checklist