Comments (11)
What trouble are you having? Rich should detect the width of the terminal automatically. Post a screenshot if you like.
from rich.
The table doesn't seem to expand beyond 80chars, instead it squeezes to fit into 80 chars (even though there's plenty of screen width). See here ...
See all the space on the right? I can't seem to get the table to expand any farther right. I've tried the width and expand options, to no effect. I saw where the code is using shutil to get the screen dimensions. Here's the output of that on my screen:
$ python
Python 3.7.5 (default, Nov 24 2019, 09:32:14)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.get_terminal_size()
os.terminal_size(columns=158, lines=48)
Your thoughts appreciated.
from rich.
Strange. The Console
class calls shutil.get_terminal_size()
under the hood.
How are you constructing Console
? If you set width
or height
it will override the auto-detected terminal size.
What should happen is that if you set expand=True
on the Table
constructor it will fit the table to the terminal size. If you could post the code you used to construct the Console and Table, I may be able to figure it out.
from rich.
Here's my code ....
self.console = Console()
def outputColumnStats(self):
table = Table(show_header=True, box=box.ROUNDED, header_style="bold magenta", expand=True)
table.add_column(header="Column", style="dim", width=9, no_wrap=True)
table.add_column(header="str",justify="right", width=4, no_wrap=True)
table.add_column(header="shrt",justify="right", width=5, no_wrap=True)
table.add_column(header="int",justify="right", width=4, no_wrap=True)
table.add_column(header="long",justify="right", width=4, no_wrap=True)
table.add_column(header="flt",justify="right", width=3, no_wrap=True)
table.add_column(header="date",justify="right", width=4 )
table.add_column(header="dttm",justify="right", width=4, no_wrap=True)
table.add_column(header="null",justify="right", width=4, no_wrap=True)
for k,rows in self.col_stats.items():
vals = [ "0" for r in range(8) ]
for r in rows:
if r[0] == "string":
vals[0] = f"{r[1]:,}"
elif r[0] == "short":
vals[1] = f"{r[1]:,}"
elif r[0] == "integer":
vals[2] = f"{r[1]:,}"
elif r[0] == "long":
vals[3] = f"{r[1]:,}"
elif r[0] == "float":
vals[4] = f"{r[1]:,}"
elif r[0] == "date":
vals[5] = f"{r[1]:,}"
elif r[0] == "datetime":
vals[6] = f"{r[1]:,}"
elif r[0] == "null":
vals[7] = f"{r[1]:,}"
table.add_row(k[:-7], *vals)
self.console.print(table)
return
Thanks.
from rich.
Ah. I think that's because you have explicitly set the widths for each column. You'll need at least one column without an explicit width for Rich to expand the table.
The Table class will calculate a minimum width for each column, so you might want to omit the width entirely. You could also set a value for ratio
on a column to configure how it expands.
from rich.
Tried it, no luck. Seems like no matter what I do, I can't get the table to be wider than 80 chars.
from rich.
Running out of suggestions. Obviously works here, but then I'm on OSX. Will try a Linux box soon.
- Could you print the result of
self.console.size
and check that matches your terminal size. - Run
python -m rich.table
which should render a table the full width of the terminal.
Just noticed you used os.get_terminal_size
and not shutil.get_terminal_size
. The later respects COLUMNS
and LINES
env vars. If your COLUMNS
is set to 80, that would explain it.
from rich.
Here ya go ...
$ python
Python 3.7.5 (default, Nov 24 2019, 09:32:14)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rich.console import Console
>>> console = Console()
>>> console.size
ConsoleDimensions(width=142, height=38)
>>>
And output of python -m rich.table
...
$ python -m rich.table
Traceback (most recent call last):
File "/home/bill.walrond/.pyenv/versions/3.7.5/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/bill.walrond/.pyenv/versions/3.7.5/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/bill.walrond/.pyenv/versions/3.7.5/lib/python3.7/site-packages/rich/table.py", line 496, in <module>
from .markdown import Markdown
File "/home/bill.walrond/.pyenv/versions/3.7.5/lib/python3.7/site-packages/rich/markdown.py", line 4, in <module>
from commonmark.blocks import Parser
ModuleNotFoundError: No module named 'commonmark'
Look like a module error. I'll try to debug this more when I get some time.
from rich.
Any chance you can try with the latest version (v0.6.0)? Still haven't managed to reproduce this.
from rich.
I am seeing the same issue on OSX when I run pytest. It creates a new line char after 78 chars. The total would match then 80 as well.
In my terminal I see a different output longer than 80 chars per line.
EDIT:
Solved it by adding -s
flag to pytest.
from rich.
I had similar problem where the console intance created didn't have the size of my actual console.
it turned out because i was using cmder, and when running my script from a split console that was smaller, my script opens up in a new full screen console but with old one's dimensions. all in all it was not a fault on rich's end, just putting this out there
from rich.
Related Issues (20)
- [BUG] significantly changes the text to be printed. [v13.7.0] HOT 4
- [BUG] Live rendering issue with a specific Unicode character HOT 1
- [BUG] Panel borders broken if using a styled console as renderable HOT 5
- [BUG] multibyte characters in Progressbar TextColumn mess up render HOT 11
- [BUG] Documentation and code disagree about the type of `log_time_format` HOT 1
- [REQUEST] Backspace and Carriage Return support HOT 1
- [BUG] rich/13.7.0: tests failure on debian unstable HOT 1
- [BUG] Text inside Live with vertical_overflow="visible" duplicating when above console.height instead of scrolling HOT 2
- [BUG] Addressing Dashboard Freeze and Cursor Flicker Issues in Real-Time Data Applications Using Rich HOT 11
- Using Traceback Handler has no effect HOT 1
- [BUG] Inconsistent traceback logging HOT 4
- [REQUEST] Shortening error messages of certain modules similarly to frame suppression in tracebacks HOT 2
- [BUG] Restarting progressbar tasks does not restart their running clocks HOT 2
- [BUG] Captured console output still results in newline being printed in Jupyter HOT 1
- [BUG] Some colors aren't printed in bold HOT 4
- [BUG] Rich tracebacks raise another exception when suppressing sys HOT 1
- [BUG] Markdown blockquotes cause crash on Windows HOT 1
- Is there a way to print the line number while console.log'ging a single line? HOT 3
- [BUG] table.add_section does not draw a line / appear to do anything HOT 1
- Support for stdlib logging StreamHandler with `Live(redirect_stderr=True)` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rich.