r-lib / ansistrings

Manipulation of ANSI colored strings
Other
9 stars 5 forks source link

Truncation to fixed width #11

Open krlmlr opened 7 years ago

krlmlr commented 7 years ago

that is aware of wide characters.

brodieG commented 7 years ago

Wide in bytes or wide in display characters? @gaborcsardi and I have been having a back and forth over this one.

krlmlr commented 7 years ago

For tibble it's wide in display characters.

gaborcsardi commented 7 years ago

I guess this is easy, because it is kind of independent of the color.

  1. remove color
  2. find where you want to truncate using nchar(type = "width")
  3. see how many characters this means
  4. use col_substr to get that many, colored correctly.

But anyway, we indeed should have this in ansistrings, and/or temporarily in crayon.

krlmlr commented 7 years ago

We may want to do nchar(strsplit(x, "")[[1]][seq_len(n)], type = "width") and then employ cumsum() .

brodieG commented 7 years ago

Would work, but risks being slow. I guess in the likely application you're thinking of (truncate long char cells in tibble, where only n rows are shown), it's probably tolerable. And you're definitely thinking of truncation, not wrapping, right?

krlmlr commented 7 years ago

Yes, wrapping is yet another issue.