패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.5.0

barbecue

당신의 명령줄 애플리케이션용 텍스트 테이블을 렌더링하세요. 패딩, 스팬, 사용자 정의 테두리, ANSI 색상 등을 사용하세요!

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3.6만
좋아요
30
Pub 점수
150

패키지 설치

flutter pub add barbecue

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

바베큐는 명령줄 애플리케이션에서 형식화된 텍스트 테이블을 렌더링하기 위해 설계된 플러터/다트 패키지입니다. 사용자 정의 가능한 테두리, 패딩, 텍스트 스팬 및 ANSI 색상 코드를 지원하여 시각적 출력을 강화합니다. 구조적이고 가독성이 좋은 데이터 표시가 필요한 CLI 도구에 적합하며, 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스 등 모든 주요 플랫폼에서 작동합니다. 개발자는 최소한의 노력으로 전문적인 콘솔 출력을 만들 수 있습니다.

사용 사례

  • CLI 앱에서 표 형식 데이터 표시
  • 형식화된 구조를 가진 로그 생성
  • 인터랙티브 명령줄 대시보드 만들기
  • 구성 또는 상태 정보 표시
  • CLI 기반 보고 도구 만들기

주요 기능

  • 사용자 정의 가능한 테이블 경계
  • ANSI 색상 지원
  • 텍스트 스팬 서식 지정
  • 유연한 패딩 옵션
  • 크로스 플랫폼 호환성

적합한 대상

  • CLI 애플리케이션 개발자
  • 콘솔 기반 도구 생성자
  • 터미널 환경에서의 데이터 시각화
  • DevTools 및 진단 유틸리티
  • 교육용 또는 디버깅용 명령줄 도구

고려 사항

  • ANSI 색상 지원이 가능한 터미널이 필요합니다
  • 텍스트 기반 출력에 한정
  • GUI 애플리케이션에 적합하지 않음
  • 복잡한 레이아웃을 위해 추가 스타일링이 필요할 수 있습니다
  • 콘솔 환경 기능에 따라 달라짐

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

barbecue

pub package Build Status codecov

Render text tables for CLI-based dart applications.

Ported from Kotlin to Dart from Jake Wharton's picnic.

Features:

  • Borders (with custom styling)
  • Padding
  • Styling on table- row- or cell-level
  • Text alignment (bottom/middle/top - left/middle/right)
  • Row and column spans
  • ANSI Colors and backgrounds! (see example)
  • LIMITED support for emojis and other wide characters

Examples

Simple example:


print(Table(
      tableStyle: TableStyle(border: true),
      header: TableSection(rows: [
        Row(
          cells: [
            Cell("ID"),
            Cell("Name"),
            Cell("Role"),
          ],
          cellStyle: CellStyle(borderBottom: true),
        ),
      ]),
      body: TableSection(
        cellStyle: CellStyle(paddingRight: 2),
        rows: [
          Row(cells: [
            Cell("42", style: CellStyle(alignment: TextAlignment.TopRight)),
            Cell("John Doe"),
            Cell("Secret Agent")
          ]),
          Row(cells: [
            Cell("4711"),
            Cell("Leanna E. Distefano"),
            Cell("Customer Support")
          ]),
          Row(cells: [Cell("1337"), Cell("Patrice Miller"), Cell("Accountant")])
        ],
      )).render());

Prints:

┌─────────────────────────────────────────────┐
│ID    Name                 Role              │
├─────────────────────────────────────────────┤
│  42  John Doe             Secret Agent      │
│4711  Leanna E. Distefano  Customer Support  │
│1337  Patrice Miller       Accountant        │
└─────────────────────────────────────────────┘
Text Align + Spans + ASCII style border

Table(
    cellStyle: CellStyle(
        borderBottom: true,
        borderRight: true,
        borderLeft: true,
        borderTop: true,
        alignment: TextAlignment.TopLeft),
    body: TableSection(
      rows: [
        Row(
          cells: [
            Cell("Real Planets",
                rowSpan: 8,
                style: CellStyle(alignment: TextAlignment.MiddleCenter)),
            Cell("Mercury")
          ],
        ),
        Row(
          cells: [Cell("Venus")],
        ),
        Row(
          cells: [Cell("Earth")],
        ),
        Row(
          cells: [Cell("Mars")],
        ),
        Row(
          cells: [Cell("Jupiter")],
        ),
        Row(
          cells: [Cell("Saturn")],
        ),
        Row(
          cells: [Cell("Uranus")],
        ),
        Row(
          cells: [Cell("Neptune")],
        ),
        Row(
          cells: [Cell("Very Fake Planets", rowSpan: 1), Cell("Pluto")],
        ),
      ],
    ),
  ).render(border: TextBorder.ASCII)

returns

+-----------------+-------+
|                 |Mercury|
|                 +-------+
|                 |Venus  |
|                 +-------+
|                 |Earth  |
|                 +-------+
|                 |Mars   |
|  Real Planets   +-------+
|                 |Jupiter|
|                 +-------+
|                 |Saturn |
|                 +-------+
|                 |Uranus |
|                 +-------+
|                 |Neptune|
+-----------------+-------+
|Very Fake Planets|Pluto  |
+-----------------+-------+

ANSI colors
  final strings = ["look", "at", "all", "these", "colors"];
  var i = 0;
  print(Table(
    tableStyle: TableStyle(border: true),
    body: TableSection(
        cellStyle: CellStyle(
          borderRight: true,
        ),
        rows: [
          Row(
            cells: [
              for (final pen in [
                AnsiPen()
                  ..red(bold: true),
                AnsiPen()
                  ..green(bold: true),
                AnsiPen()..blue(),
                AnsiPen()
                  ..black()
                  ..white(bg: true),
                AnsiPen()..xterm(190)
              ])
                Cell(pen(strings[i++]))
            ],
          ),
        ]),
  ).render());


prints

image

Emojis and other wide characters

By default, the layout algorithm assumes a real monospaced font, where every character is the exact same width as other characters. Most modern "Mono" fonts don't work like that.

See for example this "monospaced" block:

😊😊😊
123

In a fully monospaced font, the first line with the emojis would be exactly as wide as the second line. Chances are, that you see this block rendered like this (this depends on the font used):

emoji rendering

Text based table layouts don't work if some characters are wider than others. Luckily, most fonts used in terminals just render most emojis twice as wide as other characters: Something like:

😊😊😊|
123456|

Will likely render like that in your terminal:

emoji rendering

With the assumption that emojis are rendered twice as wide, we can build a valid text-table again. Unfortunately, this is not going to work with all fonts, and not with all characters.

Some characters are rendered with a fractional width of a default character.

See for example bold unicode characters:

𝗛𝗲𝗮𝗱𝗲𝗿|
123456|

For emojis and other wide characters, you can use the experimental EmojiAwareLayout.

Example:

  final table = Table(
        body: TableSection(rows: [
      Row(cells: [
        Cell('🤡',
            columnSpan: 4,
            style: CellStyle(alignment: TextAlignment.MiddleCenter)),
      ]),
      Row(cells: [
        Cell(
          '1',
        ),
        Cell(
          '2',
        ),
        Cell(
          '3',
        ),
        Cell(
          '4',
        ),
      ])
    ]));
  final tableString = table.render(layoutFactory: (cell) => EmojiAwareLayout(cell));

Your milage may wary. It is recommended not to use any unicode full-width or half-width characters with barbecue, as there are many platform, font or even terminal specific differences in how their glyphs are rendered, and this breaks the monospace-assumption of this package.

There is no way of drawing text tables if the glyphs are rendered with fractional widths of 1.5x.

카테고리

의존성

의존성 목록 4 개

소스 저장소

이 패키지를 사용하는 프로젝트