console-rs / console-rs/console

Term::read_line_initial_text() inconsistent with Term::read_line() regarding terminating newline

Open
#112 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.2k
Forks
144
Avg merge
8h 24m
Merged PRs (30d)
4

Description

Term::read_line() allows the delimiting newline to be printed to the terminal, even though it is omitted from the returned String. This is the same as the documented behaviour of BufRead::read_line(), which Term::read_line() ends up calling.

The implementation of Term::read_line_initial_text() is not consistent with this. In this case, the newline is not printed to the terminal.

use console::Term;

fn main() {

    let term = Term::stderr();

    println!("Enter ten lines. The final five will have initial text");
    for _ in 1..6 {
        term.read_line().unwrap();
    }

    for _ in 6..11 {
        term.read_line_initial_text("Inital text ").unwrap();
    }
}

After I run the above and enter the numbers 1 to 10, my terminal looks like this:

Enter ten lines. The final five will have initial text
1
2
3
4
5
Inital text 6Inital text 7Inital text 8Inital text 9Inital text 10$

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start by locating the implementations of Term::read_line() and Term::read_line_initial_text(), then reproduce the example from the issue with Term::stderr(). Compare how each method handles the terminating newline; done means lines entered with initial text are separated by newlines like the regular read_line() output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.