Package: richer
RicherTable renderer for dataclass usingRichFeaturesList TableDisplay table from dataclasses1_list_table.pyfromrich.consoleimportConsolefromricher.tableimportListTable@dataclassclassProject:name:strstar_count:intstart_date:datetimeitems=[Project('Vue',156110,datetime.fromisoformat('2013-07-29T00:00:00')),Project('React',142857,datetime.fromisoformat('2013-05-25T00:00:00')),Project('Angular',57004,datetime.fromisoformat('2014-09-19T00:00:00'))]console=Console()console.print(ListTable(items))┌─────────┬────────────┬─────────────────────┐
│ NAME    │ STAR COUNT │ START DATE          │
├─────────┼────────────┼─────────────────────┤
│ Vue     │    156,110 │ 2013-07-29 00:00:00 │
│ React   │    142,857 │ 2013-05-25 00:00:00 │
│ Angular │     57,004 │ 2014-09-19 00:00:00 │
└─────────┴────────────┴─────────────────────┘Column ManipulationsDisplay a table with custom columnsJustifySortHide/Show1-1_column_manipulation.pyfromrich.consoleimportConsolefromricher.tableimportColumn,ListTabletable=ListTable(items,columns=[Column(name='star_count',order='asc',justify='right'),Column(name='start_date',visible=False)])console=Console()console.print(table)┌─────────┬──────────────┐
│ NAME    │ STAR COUNT ▲ │
├─────────┼──────────────┤
│ Angular │       57,004 │
│ React   │      142,857 │
│ Vue     │      156,110 │
└─────────┴──────────────┘Property TableDisplay table from a dataclass2_property_table.pyfromricher.tableimportPropertyTableconsole.print(PropertyTable(item[0]))┌────────────┬─────────────────────┐
│ NAME       │ Vue                 │
├────────────┼─────────────────────┤
│ STAR COUNT │ 156,110             │
├────────────┼─────────────────────┤
│ START DATE │ 2013-07-29 00:00:00 │
└────────────┴─────────────────────┘Inner TableDisplay inner table from a nested dataclass3_inner_table.py@dataclassclassTag:name:strcommit:str@dataclassclassProject:name:strstar_count:intstart_date:datetimetags:List[Tag]tags=[Tag('v17.0.0','89b6109'),Tag('v16.0.0','5c6ef40')]item=Project('React',142857,datetime.fromisoformat('2013-05-25T00:00:00'),tags)console.print(PropertyTable(item))┌────────────┬─────────────────────┐
│ NAME       │ React               │
├────────────┼─────────────────────┤
│ STAR COUNT │ 142,857             │
├────────────┼─────────────────────┤
│ START DATE │ 2013-05-25 00:00:00 │
├────────────┼─────────────────────┤
│ TAGS       │  NAME    │ COMMIT   │
│            │ ─────────┼───────── │
│            │  v17.0.0 │ 89b6109  │
│            │  v16.0.0 │ 5c6ef40  │
└────────────┴─────────────────────┘Pagination a tablePaginate a table using cursesPress 'q' key to exit from interactive console.Press 'right' key or 'page down' key to go to next page.Press 'left' key or 'page up' key to go to previous page.4_pagination.pyfromricher.consoleimportInteractiveConsole@dataclassclassRow:id:intitems=[Row(r)forrinrange(0,100)]console=InteractiveConsole(items)console.print()┌────┐
│ ID │
├────┤
│  0 │
│  1 │
│  2 │
│  3 │
│  4 │
│  5 │
│  6 │
│  7 │
│  8 │
│  9 │
│ 10 │
└────┘ANSI Escape TextDisplay ANSI Escape TextIt is useful to use rich by redirecting stdout and stderr5_ansi_escape_text.pyfromricher.textimportAnsiEscapeTextconsole=Console()text='\x1b[1;32mSuccess\x1b[0m\n\x1b[1;31mFailure\x1b[0m'console.print(AnsiEscapeText(text))SuccessFailure