l command: the wrap width comes from the terminal size, and -l is ignored

Open
#551 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
cli

Research direction

Start by reproducing the terminal-width and -l cases, then read compile_number_command and output_width() in src/sed/compiler.rs alongside ProcessingContext::length in src/sed/mod.rs. Verify that the l command uses the configured length, defaults to 70, and handles zero consistently, regardless of terminal size.

Written by the indexing model from the issue text.

Description

The wrap width used by the l command does not come from the -l option or from its documented default. It comes from the width of the terminal the process happens to be running in, and falls back to 60 when there is no terminal. The same command on the same input therefore produces different bytes depending on where the output goes, and changes when the window is resized.

Tested with uutils sed 0.2.0 built from main at 77f442d, against GNU sed 4.9, under LC_ALL=C.

Measured under a pty of an explicit width, input 200 x, length of the first output line:

terminal columns 20 40 80 120 200
GNU sed 4.9 70 70 70 70 70
uutils sed 20 40 80 120 200

-l N is parsed and then ignored:

$ printf 'aaaaaaaaaa\n' | sed -n -l 5 l
aaaa\
aaaa\
aa$

$ printf 'aaaaaaaaaa\n' | ./target/release/sed -n -l 5 l
aaaaaaaaaa$

-l 5, -l 0 and -l 200 all produce the same output.

l 0 folds after every character:

$ echo abc | sed -n 'l 0'
abc$

$ echo abc | ./target/release/sed -n 'l 0'
\
a\
b\
c$

With no terminal, the default width is 60 rather than 70:

$ printf 'a%.0s' {1..70} | sed -n l
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
a$

$ printf 'a%.0s' {1..70} | ./target/release/sed -n l
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaa$

The GNU sed manual, on -l N: "A length of 0 (zero) means to never wrap long lines. If not specified, it is taken to be 70." On the l n argument: "a length of 0 (zero) means to never wrap long lines. If omitted, the default as specified on the command line is used."

compile_number_command in src/sed/compiler.rs stores output_width() when l has no numeric argument, and output_width() reads terminal_size(). The value from -l is already computed correctly into ProcessingContext::length in src/sed/mod.rs (defaulting to 70) and is never read.

I have a fix for this and will open a PR.

Dominant language
Rust
Stars
106
Forks
28
Avg merge
14h 12m
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uutils/sed

All issues in uutils/sed

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.