~soywod/pimalaya#153: 
When piping, width is reduced to 80

The following commands print a table wide enough to fit all content (but no wider than the screen):

himalaya list --folder mail/Drafts --color always
himalaya list --folder mail/Drafts --color always -w auto

However, when piping, the width is statically set to 80:

> himalaya list --folder mail/Drafts --color always -w auto | tac
> himalaya list --folder mail/Drafts --color always -w auto -w auto | tac
Status
RESOLVED WONT_FIX
Submitter
~whynothugo
Assigned to
No-one
Submitted
8 months ago
Updated
5 months ago
Labels
No labels applied.

~soywod 8 months ago

The following commands print a table wide enough to fit all content

Duplicate of https://todo.sr.ht/~soywod/pimalaya/75?

~whynothugo 8 months ago

On Sun, 12 Nov 2023, at 16:39, ~soywod wrote:

The following commands print a table wide enough to fit all content

Duplicate of https://todo.sr.ht/~soywod/pimalaya/75?

I don't think so. The linked issue is about making the table as wide as the entire terminal.

I want to the table to be wide-enough to fit everything with piping (this is the default when not piping).

They're related though, and might make sense to implement together.

~soywod REPORTED WONT_FIX 7 months ago

I finally took time to check in detail this issue. Here the relevant code:

let max_width = match opts.format {                                        
    EmailTextPlainFormat::Fixed(width) => opts.max_width.unwrap_or(*width),
    EmailTextPlainFormat::Flowed => 0,                                     
    EmailTextPlainFormat::Auto => opts                                     
        .max_width                                                         
        .or_else(|| terminal_size().map(|(w, _)| w.0 as usize))            
        .unwrap_or(DEFAULT_TERM_WIDTH),                                    
};

In Auto, it takes the max width for the configuration, or it takes the size of your terminal (using the terminal_size crate). Notice that it returns an Option, from their doc:

/// Returns the size of the terminal defaulting to STDOUT, if available.
///
/// If STDOUT is not a tty, returns `None`

When you pipe the result of the himalaya list command, you are not in an interactive shell anymore so the size of the terminal cannot be determined, hence the fixed width at 80 (this could be customized though).

So I am afraid there is no workaround, any suggestion?

~whynothugo 5 months ago

Indeed, if stdout is not a terminal, there doesn't seem to be a clean way to determine the terminal's width.

I don't think that anything actionable can be done here.

Register here or Log in to comment, or comment via email.