Skip to content

Commit

Permalink
Add #![warn(unreachable_pub)] and appease
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird authored and djc committed Dec 17, 2024
1 parent b892409 commit 383fcce
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct Match<'a> {

impl<'a> Match<'a> {
#[inline]
pub fn as_str(&self) -> &'a str {
pub(crate) fn as_str(&self) -> &'a str {
&self.text[self.start..self.end]
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/common_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ use std::io;

use crate::term::Term;

pub fn move_cursor_down(out: &Term, n: usize) -> io::Result<()> {
pub(crate) fn move_cursor_down(out: &Term, n: usize) -> io::Result<()> {
if n > 0 {
out.write_str(&format!("\x1b[{}B", n))
} else {
Ok(())
}
}

pub fn move_cursor_up(out: &Term, n: usize) -> io::Result<()> {
pub(crate) fn move_cursor_up(out: &Term, n: usize) -> io::Result<()> {
if n > 0 {
out.write_str(&format!("\x1b[{}A", n))
} else {
Ok(())
}
}
pub fn move_cursor_left(out: &Term, n: usize) -> io::Result<()> {
pub(crate) fn move_cursor_left(out: &Term, n: usize) -> io::Result<()> {
if n > 0 {
out.write_str(&format!("\x1b[{}D", n))
} else {
Ok(())
}
}

pub fn move_cursor_right(out: &Term, n: usize) -> io::Result<()> {
pub(crate) fn move_cursor_right(out: &Term, n: usize) -> io::Result<()> {
if n > 0 {
out.write_str(&format!("\x1b[{}C", n))
} else {
Expand All @@ -34,11 +34,11 @@ pub fn move_cursor_right(out: &Term, n: usize) -> io::Result<()> {
}

#[inline]
pub fn move_cursor_to(out: &Term, x: usize, y: usize) -> io::Result<()> {
pub(crate) fn move_cursor_to(out: &Term, x: usize, y: usize) -> io::Result<()> {
out.write_str(&format!("\x1B[{};{}H", y + 1, x + 1))
}

pub fn clear_chars(out: &Term, n: usize) -> io::Result<()> {
pub(crate) fn clear_chars(out: &Term, n: usize) -> io::Result<()> {
if n > 0 {
out.write_str(&format!("\x1b[{}D\x1b[0K", n))
} else {
Expand All @@ -47,26 +47,26 @@ pub fn clear_chars(out: &Term, n: usize) -> io::Result<()> {
}

#[inline]
pub fn clear_line(out: &Term) -> io::Result<()> {
pub(crate) fn clear_line(out: &Term) -> io::Result<()> {
out.write_str("\r\x1b[2K")
}

#[inline]
pub fn clear_screen(out: &Term) -> io::Result<()> {
pub(crate) fn clear_screen(out: &Term) -> io::Result<()> {
out.write_str("\r\x1b[2J\r\x1b[H")
}

#[inline]
pub fn clear_to_end_of_screen(out: &Term) -> io::Result<()> {
pub(crate) fn clear_to_end_of_screen(out: &Term) -> io::Result<()> {
out.write_str("\r\x1b[0J")
}

#[inline]
pub fn show_cursor(out: &Term) -> io::Result<()> {
pub(crate) fn show_cursor(out: &Term) -> io::Result<()> {
out.write_str("\x1b[?25h")
}

#[inline]
pub fn hide_cursor(out: &Term) -> io::Result<()> {
pub(crate) fn hide_cursor(out: &Term) -> io::Result<()> {
out.write_str("\x1b[?25l")
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
//! for stripping and taking ansi escape codes into account for length
//! calculations).
#![warn(unreachable_pub)]

pub use crate::kb::Key;
pub use crate::term::{
user_attended, user_attended_stderr, Term, TermFamily, TermFeatures, TermTarget,
Expand Down
8 changes: 4 additions & 4 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum TermTarget {
}

#[derive(Debug)]
pub struct TermInner {
struct TermInner {
target: TermTarget,
buffer: Option<Mutex<Vec<u8>>>,
prompt: RwLock<String>,
Expand Down Expand Up @@ -657,8 +657,8 @@ impl Read for &Term {
}

#[cfg(all(unix, not(target_arch = "wasm32")))]
pub use crate::unix_term::*;
pub(crate) use crate::unix_term::*;
#[cfg(target_arch = "wasm32")]
pub use crate::wasm_term::*;
pub(crate) use crate::wasm_term::*;
#[cfg(windows)]
pub use crate::windows_term::*;
pub(crate) use crate::windows_term::*;
24 changes: 12 additions & 12 deletions src/unix_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ use once_cell::sync::Lazy;
use crate::kb::Key;
use crate::term::Term;

pub use crate::common_term::*;
pub(crate) use crate::common_term::*;

pub const DEFAULT_WIDTH: u16 = 80;
pub(crate) const DEFAULT_WIDTH: u16 = 80;

#[inline]
pub fn is_a_terminal(out: &Term) -> bool {
pub(crate) fn is_a_terminal(out: &Term) -> bool {
unsafe { libc::isatty(out.as_raw_fd()) != 0 }
}

pub fn is_a_color_terminal(out: &Term) -> bool {
pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
if !is_a_terminal(out) {
return false;
}
Expand All @@ -37,7 +37,7 @@ pub fn is_a_color_terminal(out: &Term) -> bool {
}
}

pub fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
let res = f();
if res != 0 {
Err(io::Error::last_os_error())
Expand All @@ -46,7 +46,7 @@ pub fn c_result<F: FnOnce() -> libc::c_int>(f: F) -> io::Result<()> {
}
}

pub fn terminal_size(out: &Term) -> Option<(u16, u16)> {
pub(crate) fn terminal_size(out: &Term) -> Option<(u16, u16)> {
unsafe {
if libc::isatty(out.as_raw_fd()) != 1 {
return None;
Expand All @@ -66,7 +66,7 @@ pub fn terminal_size(out: &Term) -> Option<(u16, u16)> {
}
}

pub fn read_secure() -> io::Result<String> {
pub(crate) fn read_secure() -> io::Result<String> {
let mut f_tty;
let fd = unsafe {
if libc::isatty(libc::STDIN_FILENO) == 1 {
Expand Down Expand Up @@ -300,7 +300,7 @@ fn read_single_key_impl(fd: i32) -> Result<Key, io::Error> {
}
}

pub fn read_single_key(ctrlc_key: bool) -> io::Result<Key> {
pub(crate) fn read_single_key(ctrlc_key: bool) -> io::Result<Key> {
let tty_f;
let fd = unsafe {
if libc::isatty(libc::STDIN_FILENO) == 1 {
Expand Down Expand Up @@ -339,7 +339,7 @@ pub fn read_single_key(ctrlc_key: bool) -> io::Result<Key> {
rv
}

pub fn key_from_utf8(buf: &[u8]) -> Key {
fn key_from_utf8(buf: &[u8]) -> Key {
if let Ok(s) = str::from_utf8(buf) {
if let Some(c) = s.chars().next() {
return Key::Char(c);
Expand All @@ -355,15 +355,15 @@ static IS_LANG_UTF8: Lazy<bool> = Lazy::new(|| match std::env::var("LANG") {
});

#[cfg(target_os = "macos")]
pub fn wants_emoji() -> bool {
pub(crate) fn wants_emoji() -> bool {
true
}

#[cfg(not(target_os = "macos"))]
pub fn wants_emoji() -> bool {
pub(crate) fn wants_emoji() -> bool {
*IS_LANG_UTF8
}

pub fn set_title<T: Display>(title: T) {
pub(crate) fn set_title<T: Display>(title: T) {
print!("\x1b]0;{}\x07", title);
}

0 comments on commit 383fcce

Please sign in to comment.