Idiomatic type for reader_readline nchars argument

This commit is contained in:
Johannes Altmanninger
2025-05-17 07:30:33 +02:00
parent 4b5650ee4f
commit 2071df126c
2 changed files with 4 additions and 4 deletions

View File

@@ -28,6 +28,7 @@
use crate::wutil::encoding::zero_mbstate;
use crate::wutil::perror;
use libc::SEEK_CUR;
use std::num::NonZeroUsize;
use std::os::fd::RawFd;
use std::sync::atomic::Ordering;
@@ -244,7 +245,7 @@ fn read_interactive(
let mline = {
let _interactive = parser.push_scope(|s| s.is_interactive = true);
reader_readline(parser, nchars)
reader_readline(parser, NonZeroUsize::try_from(nchars).ok())
};
terminal_protocols_disable_ifn();
if let Some(line) = mline {

View File

@@ -1060,12 +1060,11 @@ pub fn reader_reading_interrupted(data: &mut ReaderData) -> i32 {
}
/// Read one line of input. Before calling this function, reader_push() must have been called in
/// order to set up a valid reader environment. If nchars > 0, return after reading that many
/// order to set up a valid reader environment. If nchars is given, return after reading that many
/// characters even if a full line has not yet been read. Note: the returned value may be longer
/// than nchars if a single keypress resulted in multiple characters being inserted into the
/// commandline.
pub fn reader_readline(parser: &Parser, nchars: usize) -> Option<WString> {
let nchars = NonZeroUsize::try_from(nchars).ok();
pub fn reader_readline(parser: &Parser, nchars: Option<NonZeroUsize>) -> Option<WString> {
let data = current_data().unwrap();
let mut reader = Reader { parser, data };
reader.readline(nchars)