Version bump: Moved from using `AsRawFd` to platform-agnostic `AsFd` in interface. Removed currently-unused features.

Fortune for termprogress's current commit: Great blessing − 大吉
master
Avril 3 weeks ago
commit c8ecf2ccd1
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -2,27 +2,26 @@
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.1"
version = "0.11.0"
authors = ["Avril <flanchan@cumallover.me>"]
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 = []
# 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"

@ -47,15 +47,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;
@ -79,9 +80,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.

@ -136,10 +136,10 @@ impl Bar {
}
}
impl<T: io::Write + AsRawFd> Bar<T>
impl<T: io::Write + AsFd> Bar<T>
{
/// Create a new bar `width` long with a title.
pub fn with_title(output: impl Into<T> + AsRawFd, width: usize, title: impl AsRef<str>) -> Self
pub fn with_title(output: impl Into<T> + AsFd, width: usize, title: impl AsRef<str>) -> Self
{
let mut this = Self::new(output, width);
this.add_title(title.as_ref());
@ -156,7 +156,7 @@ impl<T: io::Write + AsRawFd> Bar<T>
///
/// If `output` is not a terminal, then `None` is returned.
#[cfg(feature="size")]
pub fn try_new_with_title(output: impl Into<T> + AsRawFd, width: usize, title: impl AsRef<str>) -> Option<Self>
pub fn try_new_with_title(output: impl Into<T> + AsFd, width: usize, title: impl AsRef<str>) -> Option<Self>
{
let (terminal_size::Width(tw), _) = terminal_size_of(&output)?;
let tw = usize::from(tw);
@ -181,7 +181,7 @@ impl<T: io::Write + AsRawFd> Bar<T>
///
/// 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<T> + AsRawFd, width: usize) -> Self
pub fn new(output: impl Into<T> + AsFd, width: usize) -> Self
{
#[cfg(feature="size")]
return {
@ -206,7 +206,7 @@ impl<T: io::Write + AsRawFd> Bar<T>
///
/// If `output` is not a terminal, then `None` is returned.
#[cfg(feature="size")]
pub fn try_new(output: impl Into<T> + AsRawFd, width: usize) -> Option<Self>
pub fn try_new(output: impl Into<T> + AsFd, width: usize) -> Option<Self>
{
let (terminal_size::Width(tw), _) = terminal_size_of(&output)?;
let tw = usize::from(tw);
@ -220,7 +220,7 @@ impl<T: io::Write + AsRawFd> Bar<T>
/// If `output` is not a terminal, then `None` is returned.
#[cfg(feature="size")]
#[inline]
pub fn try_new_default_size(to: impl Into<T> + AsRawFd) -> Option<Self>
pub fn try_new_default_size(to: impl Into<T> + AsFd) -> Option<Self>
{
Self::try_new(to, DEFAULT_SIZE)
}
@ -247,13 +247,13 @@ impl<T: io::Write + AsRawFd> Bar<T>
}
impl<T: ?Sized + io::Write + AsRawFd> Bar<T> {
impl<T: ?Sized + io::Write + AsFd> Bar<T> {
#[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<T: ?Sized + io::Write + AsRawFd> Bar<T> {
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<T: ?Sized + io::Write + AsRawFd> Display for Bar<T>
impl<T: ?Sized + io::Write + AsFd> Display for Bar<T>
{
fn refresh(&self)
{
@ -431,7 +431,7 @@ impl<T: ?Sized + io::Write + AsRawFd> Display for Bar<T>
}
}
impl<T: ?Sized + io::Write + AsRawFd> ProgressBar for Bar<T>
impl<T: ?Sized + io::Write + AsFd> ProgressBar for Bar<T>
{
fn get_progress(&self) -> f64
{
@ -457,7 +457,7 @@ impl<T: ?Sized + io::Write + AsRawFd> ProgressBar for Bar<T>
}
}
impl<T: io::Write + AsRawFd> WithTitle for Bar<T>
impl<T: io::Write + AsFd> WithTitle for Bar<T>
{
fn add_title(&mut self, string: impl AsRef<str>)
{
@ -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>());

Loading…
Cancel
Save