comfy-table icon indicating copy to clipboard operation
comfy-table copied to clipboard

[BUG] Table rendering without content on Windows

Open aclemmensen opened this issue 2 years ago • 3 comments

Describe the bug

The table renders with the width calculated correctly, as far as I can tell, but all the cells are empty. I only see this on Windows (8, rustc 1.62.0 (a8314ef7d 2022-06-27)) in the good old cmd terminal.

It renders like this:

C:\code\rust\tables>cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.41s
     Running `target\debug\tables.exe`
+-------+-------+
|||
+===============+
|||
+-------+-------+

Expected behavior

I expect contents to render. The same code renders fine on my Mac. And it works on Windows Terminal and cmd.exe on Windows 10.

Code

Please add a code example of how the bug is triggered.

fn main() {
    let mut table = comfy_table::Table::new();
    table.set_header(vec!["Hello", "World"]);
    table.add_row(vec!["Hej", "Dig"]);
    println!("{table}");
}

Steps to reproduce the bug

  1. Create a table with two columns
  2. Add one row
  3. Render it to the console
  4. Wonder why it's empty :thinking:

Additional context

  • Operating System: Windows 8, using the GNU toolchain not the default Microsoft one, stable-x86_64-pc-windows-gnu
  • comfy-table version: 6.0.0

aclemmensen avatar Jul 15 '22 13:07 aclemmensen

This is an extremely weird bug :D

Could you do me a favor and try to run this example without default features: comfy-table = { version = "6", default-features = false }

This disables the terminal specific logic and should probably resolve the issue.

In case it does fix this, I assume that this is due to incorrect styling instructions in windows environments. This would then be a bug in crossterm, which is the library used by comfy-table to handle stuff like this.

Could you try the following:

use crossterm::style::style;

fn main() {
   let test = "This is a test";
   let styled = style(test);
   println!("{}", styled.to_string());
}

with this dependency:

crossterm = { version = "0.24" }

Nukesor avatar Jul 15 '22 14:07 Nukesor

If that's the case, a fix for this is already on main.

It simply prevents the style function of crossterm being called, if there's no active styling, which is probably the best behavior anyway (even though it shouldn't change the behavior, as crossterm doesn't apply anything if there's nothing to apply. At least on Linux).

Nukesor avatar Jul 16 '22 04:07 Nukesor

Ping @aclemmensen

Did you have some time to follow up on this :)? I'm really curious.

Nukesor avatar Jul 28 '22 11:07 Nukesor

Closing due to inactivity

Nukesor avatar Aug 17 '22 16:08 Nukesor