[cardano-testnet] Modify `renderStatusReportHumanReadable` to return `Doc Ann` instead.

Đang mở
#6,746 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@palas đang làm issue này rồi.

Từ ngày 26/10/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

renderStatusReportHumanReadable builds the report as a String: lines are joined with <> and unlines, and renderTable pads cells with pad and replicate. That one function decides the content, where lines break and how the output looks, so changing any of these (wrapping, colour, embedding a pretty-printed error) means rewriting string code. cardano-testnet already uses cardano-api's pretty-printing API (prettyError, docToString, docToText, pshow) and depends on prettyprinter, so the report could be a Doc Ann instead.

What prettyprinter gives here:

  • Layout is separate from content. A Doc describes the content and where lines may break. A layouter (layoutPretty, layoutSmart) turns it into a SimpleDocStream for a given page width, and a renderer turns that into Text. The report code no longer decides where lines end.
  • Line breaks depend on the available width. group, softline and flatAlt keep the summary line or the no-testnet explanation on one line when it fits, and break it when it does not. hang and align indent the continuation relative to the column where it started, so it lines up without counting the prefix length.
  • The renderer interprets annotations. Mark a node state as an error once with annotate. cardano-api's docToText uses the ANSI terminal renderer and shows it in colour, while unAnnotate gives plain text for goldens, pipes and log files. The layout code is the same for both.
  • It composes with existing Docs. cardano-api errors already render as Doc Ann (prettyError, prettyException), so a node's probe error could go into the report as it is, instead of being flattened to a String first. Pretty instances for NetworkStatus and NodeState can be reused the same way.

Today's report is short and has no colour, so these gains show once it grows, for example with the probe error from my comment on line 164.

A rough path:

  1. Return Doc Ann from renderStatusReportHumanReadable (both types come from Cardano.Api), and give NetworkStatus and NodeState Pretty instances.
  2. Build lines with pretty, <+> and vsep. Use group with softline, and hang, where a line can get long.
  3. In renderTable, keep the width calculation and replace pad width cell with fill width (pretty cell) from Prettyprinter. prettyprinter has no table combinator, so the borders stay hand-built.
  4. Render at the edges: docToText where Run.hs prints the report. If colour is added, apply unAnnotate before rendering in the golden test and when stdout is not a terminal.

Originally posted by @carbolymer in https://github.com/IntersectMBO/cardano-node/pull/6741#discussion_r4348812162

Ngôn ngữ chính
Haskell
Star
3.2k
Fork
763
Merge trung bình
3 ngày 2 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của IntersectMBO/cardano-node

Tất cả issue của IntersectMBO/cardano-node

Issue tương tự

Thêm issue về Haskell

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.