Git Product home page Git Product logo

Comments (4)

BurntSushi avatar BurntSushi commented on September 2, 2024 1

Nice find. This is fixed in bstr 1.9.1.

from bstr.

BurntSushi avatar BurntSushi commented on September 2, 2024

Please provide a full program and an example invocation on the CLI that reproduces the problem. Please include actual output and expected output.

from bstr.

zhitkoff avatar zhitkoff commented on September 2, 2024

Full program for bstr use case:

use bstr::io::BufReadExt;
use std::io::{self, stdin, BufReader, IsTerminal};

fn main() -> io::Result<()> {
    if stdin().is_terminal() {
        let mut buf_in = BufReader::new(stdin());
        let separator = b'\n';

        println!("Start terminal input for bstr for_byte_record_with_terminator\nTry ^D - it will not exit right away on the first ^D");
        let _result_bstr = buf_in.for_byte_record_with_terminator(separator, |_line| {
            // do something with line
            Ok(true)
        })?;
        println!("Done");
    }
    Ok(())
}

Run with cargo run and it will wait for user input in the terminal. Try ^D (Control-D) and notice that it does not exit, still accepting input in the terminal. Try ^D twice - it should exit to command prompt

from bstr.

zhitkoff avatar zhitkoff commented on September 2, 2024

Full program to illustrate that using std::io functions in the same scenario does exit on the first ^D:

use std::io::{self, stdin, BufRead, BufReader, IsTerminal};

fn main() -> io::Result<()> {
    if stdin().is_terminal() {
        let buf_in = BufReader::new(stdin());
        let separator = b'\n';

        println!("Start terminal input for std io, like split, read_until, etc\nTry ^D");
        let _result_std = buf_in.split(separator).for_each(|_line| {
            // do something with line
        });
        println!("Done");
    }
    Ok(())
}

Run with cargo run and it will wait for user input in the terminal. Try ^D (Control-D) once and notice that it does exit into command prompt right away.

from bstr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.