From 87313aebb993e09f639627fe34fc4a582b75e83e Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 14 Mar 2025 15:44:45 +0000 Subject: [PATCH 1/2] Started 1.0 prerelease redesign. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for termprogress's current commit: Future blessing − 末吉 --- Cargo.toml | 2 +- src/inter.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 62605c8..ca10182 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "termprogress" description = "A terminal progress bar renderer with status and spinners" license = "GPL-3.0-or-later" # TODO: After full interface update & correction, bump version to `0.11.0` instead or a revision. -version = "0.10.0-r1" +version = "1.0.0-r0-pre" authors = ["Avril "] edition = "2018" diff --git a/src/inter.rs b/src/inter.rs index b904823..56ef521 100644 --- a/src/inter.rs +++ b/src/inter.rs @@ -138,6 +138,57 @@ where T: Spinner + ?Sized } } + +impl Display for std::convert::Infallible +{ + #[inline] fn refresh(&self) + { + + } + #[inline] fn blank(&self) + { + + } + #[inline] fn println(&self, _: &str) + { + + } + #[inline] fn eprintln(&self, _: &str) + { + + } + #[inline] fn get_title(&self) -> &str + { + match *self {} + } + #[inline] fn set_title(&mut self, _: &str) + { + } + + #[inline] fn update_dimensions(&mut self, _: usize) + { + + } +} + +impl ProgressBar for std::convert::Infallible +{ + + #[inline] fn set_progress(&mut self, _: f64) + { + + } + #[inline] fn get_progress(&self) -> f64 + { + match *self {} + } +} + +impl Spinner for std::convert::Infallible +{ + #[inline] fn bump(&mut self){} +} + #[cfg(nightly)] mod never { use super::*; From 1ef1aeda08c7315a3497b4c2ab0ba845e3f06305 Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 14 Mar 2025 15:55:28 +0000 Subject: [PATCH 2/2] Moved from using `AsRawFd` to `AsFd`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for termprogress's current commit: Curse − 凶 --- Cargo.toml | 13 ++++++------- src/lib.rs | 11 ++++++----- src/progress.rs | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca10182..f145730 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,18 +2,17 @@ name = "termprogress" description = "A terminal progress bar renderer with status and spinners" license = "GPL-3.0-or-later" -# TODO: After full interface update & correction, bump version to `0.11.0` instead or a revision. -version = "1.0.0-r0-pre" +version = "0.11.0-r0" authors = ["Avril "] -edition = "2018" +edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["size", "reactive"] +default = ["size"] # Use terminal size when drawing bars. -size = ["terminal_size"] +size = ["dep:terminal_size"] # TODO: React to `SIGWINCH` when output stream is a terminal (linux only.) reactive = [] @@ -21,8 +20,8 @@ reactive = [] [dependencies] atomic_refcell = "0.1.10" stackalloc = "1.2.0" -terminal_size = {version = "0.1", optional = true} +terminal_size = {version = "0.4", optional = true} [build-dependencies] -rustc_version = "0.2" +rustc_version = "0.4" diff --git a/src/lib.rs b/src/lib.rs index 7367cac..0edc423 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,15 +46,16 @@ pub(crate) fn create_default_output_device() -> DefaultOutputDevice #[cfg(feature="size")] #[inline(always)] -fn terminal_size_of(f: &(impl AsRawFd + ?Sized)) -> Option<(terminal_size::Width, terminal_size::Height)> +fn terminal_size_of(f: &(impl AsFd + ?Sized)) -> Option<(terminal_size::Width, terminal_size::Height)> { - terminal_size::terminal_size_using_fd(f.as_raw_fd()) + terminal_size::terminal_size_of(f) } use atomic_refcell::AtomicRefCell; //#[cfg(feature="size")] TODO: How to add `AsRawFd` bound to `Bar` *only* when `size` feature is enabled? -use std::os::unix::io::*; +//use std::os::unix::io::*; // Not currently needed right now, platform-agnostic `AsFd` is used instead. +use std::os::fd::AsFd; mod util; mod inter; @@ -78,9 +79,9 @@ pub fn has_terminal_output_default() -> bool /// /// Requires `size` feature. #[cfg(feature="size")] -pub fn has_terminal_output(f: &(impl AsRawFd + ?Sized)) -> bool +pub fn has_terminal_output(f: &(impl AsFd + ?Sized)) -> bool { - terminal_size::terminal_size_using_fd(f.as_raw_fd()).is_some() + terminal_size::terminal_size_of(f).is_some() } /// The prelude exposes the traits for spinners and progress bars, and the `spinner::Spin` and `progress::Bar` types for easy access and use. diff --git a/src/progress.rs b/src/progress.rs index 2abbf16..17cbcc7 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -136,10 +136,10 @@ impl Bar { } } -impl Bar +impl Bar { /// Create a new bar `width` long with a title. - pub fn with_title(output: impl Into + AsRawFd, width: usize, title: impl AsRef) -> Self + pub fn with_title(output: impl Into + AsFd, width: usize, title: impl AsRef) -> Self { let mut this = Self::new(output, width); this.add_title(title.as_ref()); @@ -156,7 +156,7 @@ impl Bar /// /// If `output` is not a terminal, then `None` is returned. #[cfg(feature="size")] - pub fn try_new_with_title(output: impl Into + AsRawFd, width: usize, title: impl AsRef) -> Option + pub fn try_new_with_title(output: impl Into + AsFd, width: usize, title: impl AsRef) -> Option { let (terminal_size::Width(tw), _) = terminal_size_of(&output)?; let tw = usize::from(tw); @@ -181,7 +181,7 @@ impl Bar /// /// To try to create one that always adheres to `size`, use the `try_new()` family of functions. #[cfg_attr(not(feature="size"), inline)] - pub fn new(output: impl Into + AsRawFd, width: usize) -> Self + pub fn new(output: impl Into + AsFd, width: usize) -> Self { #[cfg(feature="size")] return { @@ -206,7 +206,7 @@ impl Bar /// /// If `output` is not a terminal, then `None` is returned. #[cfg(feature="size")] - pub fn try_new(output: impl Into + AsRawFd, width: usize) -> Option + pub fn try_new(output: impl Into + AsFd, width: usize) -> Option { let (terminal_size::Width(tw), _) = terminal_size_of(&output)?; let tw = usize::from(tw); @@ -220,7 +220,7 @@ impl Bar /// If `output` is not a terminal, then `None` is returned. #[cfg(feature="size")] #[inline] - pub fn try_new_default_size(to: impl Into + AsRawFd) -> Option + pub fn try_new_default_size(to: impl Into + AsFd) -> Option { Self::try_new(to, DEFAULT_SIZE) } @@ -247,13 +247,13 @@ impl Bar } -impl Bar { +impl Bar { #[inline(always)] #[cfg(feature="size")] fn try_get_size(&self) -> Option<(terminal_size::Width, terminal_size::Height)> { let b = self.output.try_borrow().ok()?; - terminal_size::terminal_size_using_fd(b.as_raw_fd()) + terminal_size::terminal_size_of::<&T>(&b) } /// Fit to terminal's width if possible. /// @@ -266,7 +266,7 @@ impl Bar { pub fn fit(&mut self) -> bool { #[cfg(feature="size")] { - if let Some((terminal_size::Width(tw), _)) = terminal_size::terminal_size_using_fd(self.output.get_mut().as_raw_fd()) { + if let Some((terminal_size::Width(tw), _)) = terminal_size::terminal_size_of(self.output.get_mut()) { let tw = usize::from(tw); self.width = if self.width < tw {self.width} else {tw}; self.update_dimensions(tw); @@ -359,7 +359,7 @@ fn ensure_lower(input: String, to: usize) -> String } } -impl Display for Bar +impl Display for Bar { fn refresh(&self) { @@ -431,7 +431,7 @@ impl Display for Bar } } -impl ProgressBar for Bar +impl ProgressBar for Bar { fn get_progress(&self) -> f64 { @@ -457,7 +457,7 @@ impl ProgressBar for Bar } } -impl WithTitle for Bar +impl WithTitle for Bar { fn add_title(&mut self, string: impl AsRef) { @@ -483,7 +483,7 @@ const _:() = { fn take_display(_: &(impl Display + ?Sized)) {} fn test() { - #[macro_export] macro_rules! assert_is_bar { + macro_rules! assert_is_bar { ($ty:path) => { take_title(&declval::<$ty>()); take_progress(&declval::<$ty>());