Coder Social home page Coder Social logo

petercorke / ansitable Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 1.0 102 KB

Quick, easy and pretty display of tabular data or matrices, with optional ANSI color and borders

License: MIT License

Python 98.72% Makefile 1.28%
table tabular-data-formatter tabular-data ansi-colors ansi-art borders columnar formatting matrix array

ansitable's Introduction

I'm Peter, I'm a robotics educator and researcher.

  • I'm currently working on a bunch of packages for robotics, machine vision and block diagram simulation.

Peter Corke's GitHub stats

ansitable's People

Contributors

callumjhays avatar petercorke avatar sdiebolt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sdiebolt

ansitable's Issues

Colored 1.5.0 introduces breaking changes

Colored doesn't follow semantic versioning, and version 1.5.0 introduced breaking API changes. In particular, the functions fg and attr were renamed fore and style, respectively. This means that the following lines:

try:
from colored import fg, bg, attr
_colored = True
# print('using colored output')
except ImportError:
# print('colored not found')
_colored = False

will always lead to _colored = False, even if colored is installed. Since ansitable's dependencies do not specify a version for colored, this is a problem for ansitable.

Long header should apply colbgcolor to same width as header

This issue is related to, and may be irrelevant once resolved by #8 (headbgcolor and colbgcolor should not be affected by colsep).

The natural column width is determined by the widest column value, whether that's the header or one of the rows. That same column width should be applied to both headbgcolor and colbgcolor, but it is currently not being applied to colbgcolor.

In the example below, the "Date" header is padded—as expected—by the longer "2023-07-28" values, but the wider "Column 2" header is not reflected in the padding of shorter version numbers like "1.0.0". The same is true with column 1 row values.

image

from ansitable import ANSITable, Column # ansitable 0.9.7

table = ANSITable(
  Column("Column 1", headalign="<", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="<",  colcolor="white",  colstyle="bold",  colbgcolor="blue"),
  Column("Column 2", headalign="^", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="<",  colcolor="light_magenta",            colbgcolor="blue"),
  Column("Date",     headalign="^", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="^",  colcolor="chartreuse_3b"),
  border="thick", bordercolor="cornflower_blue", colsep=4,
)
table.row("hello-world", "1.0.0", "2023-07-28")
table.row("foo-bar",     "0.1.0", "2023-07-28")
table.print()

headbgcolor and colbgcolor should not be affected by colsep

Column headbgcolor and colbgcolor settings are typically used as cell background colors, so they should occupy the entire cell width and not be affected by the ANSITable colsep setting that adds left/right padding to a header or column cell. This padding is currently being applied to the background colors instead of just the text, rendering empty strips along the inner borders.

image

from ansitable import ANSITable, Column # ansitable 0.9.7

table = ANSITable(
  Column("Column 1", headalign="<", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="<",  colcolor="white",  colstyle="bold",  colbgcolor="blue"),
  Column("Column 2", headalign="^", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="<",  colcolor="light_magenta",            colbgcolor="blue"),
  Column("Date",     headalign="^", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="^",  colcolor="chartreuse_3b"),
  border="thick", bordercolor="cornflower_blue", colsep=4,
)
table.row("hello-world", "1.0.0", "2023-07-28")
table.row("foo-bar",     "0.1.0", "2023-07-28")
table.print()

ANSITable colsep not applied on left side of first column

When a table border is shown, no matter what the header or column alignment is set to for the first, left-most, column, the colsep setting, which should be better known as "padding", does not get applied on the left side of that column. For other columns, this setting appears to be working fine.

image

from ansitable import ANSITable, Column # ansitable 0.9.7

table = ANSITable(
  Column("Column 1", headalign="<", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="<",  colcolor="white",  colstyle="bold",  colbgcolor="blue"),
  Column("Column 2", headalign="^", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="<",  colcolor="light_magenta",            colbgcolor="blue"),
  Column("Date",     headalign="^", headcolor="white", headstyle="bold", headbgcolor="blue",
                      colalign="^",  colcolor="chartreuse_3b"),
  border="thick", bordercolor="cornflower_blue", colsep=4,
)
table.row("hello-world", "1.0.0", "2023-07-28")
table.row("foo-bar",     "0.1.0", "2023-07-28")
table.print()

Feature: Support row and cell-level style overrides

Introduce Row and Cell classes to allow customizing per-row and per-cell styling (alignment, color, and style). This is useful, for example, to highlight specific rows or specific cell values in a large table using, e.g., style="reverse"

# proposed syntax only!
table.add(Row(["hello-world", "1.0.0", "2023-07-28"], style="reverse")) #  row-level override
table.add(Row([Cell("foo-bar", style="bold"), "0.1.0", "2023-07-28"]))  # cell-level override

AttributeError: function 'SetsConsoleMode' not found

I tried to run the test according to the README, but it gave me the error shown in the picture and I could not find any function or class named "SetsConsoleMode" in the source file.
image
My version of python is 3.10.12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.