From 2c9d525d367c9c626f4e6e7915cc2f7b920b9ffe Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Tue, 16 May 2023 16:20:58 +0200 Subject: [PATCH] docs(ui): add docstrings --- crates/pacdef_core/src/ui.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/pacdef_core/src/ui.rs b/crates/pacdef_core/src/ui.rs index 4280336..aa49762 100644 --- a/crates/pacdef_core/src/ui.rs +++ b/crates/pacdef_core/src/ui.rs @@ -15,6 +15,14 @@ pub fn get_user_confirmation() -> Result { Ok(reply.trim().is_empty() || reply.to_lowercase().contains('y')) } +/// Read a single byte from the stdin and interpret it as `char`. Use the +/// `termios` library to switch the terminal to raw mode before reading, +/// and restore the original terminal mode afterwards. +/// +/// # Errors +/// +/// This function will return an error if the data cannot be read or the +/// terminal settings cannot be changed. pub fn read_single_char_from_terminal() -> Result { // 0 is the file descriptor for stdin let fd = 0; @@ -32,6 +40,7 @@ pub fn read_single_char_from_terminal() -> Result { let result: char = input[0] .try_into() .context("reading a single byte from stdin")?; + // stdin is not echoed automatically in this terminal mode println!("{result}");