Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions kdam/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Bump up pyo3 >=0.27

## [0.6.3] - 2025-06-10

### Changed
Expand Down
6 changes: 3 additions & 3 deletions kdam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ repository = "https://github.com/clitic/kdam/tree/main/kdam"
version = "0.6.3"

[dependencies]
colorgrad = { version = "0.7", optional = true }
colorgrad = { version = "0.8", optional = true }
formatx = { version = "0.2.4", optional = true }
kdam_derive = { version = "0.1.1", path = "../kdam_derive", optional = true }
pyo3 = { version = ">=0.23,<0.26", optional = true }
pyo3 = { version = ">=0.27", optional = true }
rayon = { version = "1.10", optional = true }
terminal_size = "0.4"
unicode-segmentation = { version = "1", optional = true }
unicode-width = { version = "0.2", optional = true }

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_System_Console"] }
windows-sys = { version = "0.61.0", features = ["Win32_Foundation", "Win32_System_Console"] }

[features]
derive = ["dep:kdam_derive"]
Expand Down
4 changes: 2 additions & 2 deletions kdam/examples/coloured/gradient.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use kdam::{term::Colorizer, tqdm, Colour};
use std::io::{stderr, IsTerminal};
use kdam::{Colour, term::Colorizer, tqdm};
use std::io::{IsTerminal, stderr};

fn main() {
kdam::term::init(stderr().is_terminal());
Expand Down
4 changes: 2 additions & 2 deletions kdam/examples/coloured/solid.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use kdam::{tqdm, BarExt};
use std::io::{stderr, IsTerminal, Result};
use kdam::{BarExt, tqdm};
use std::io::{IsTerminal, Result, stderr};

fn main() -> Result<()> {
kdam::term::init(stderr().is_terminal());
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/messages/between.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{term, term::Writer, tqdm, BarExt};
use kdam::{BarExt, term, term::Writer, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/messages/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/messages/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/messages/write.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/miscellaneous/custom.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, Bar, BarExt};
use kdam::{Bar, BarExt, tqdm};
use std::{io::Result, num::NonZeroU16};

#[derive(BarExt)]
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/miscellaneous/file_copy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::{
fs::File,
io::{BufReader, Read, Result, Write},
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/miscellaneous/file_download/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
reqwest = { version = "0.12", features = ["stream"] }
reqwest = { version = "0.13", features = ["stream"] }
futures-util = "0.3"
tokio = { version = "1", features = ["full"] }
kdam = { path = "../../.." }
2 changes: 1 addition & 1 deletion kdam/examples/miscellaneous/inverse_unit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/miscellaneous/max_fps.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/miscellaneous/monitor_mode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/miscellaneous/rayon.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{rayon::prelude::*, TqdmIterator, TqdmParallelIterator};
use kdam::{TqdmIterator, TqdmParallelIterator, rayon::prelude::*};
use std::{
thread::sleep,
time::{Duration, Instant},
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/miscellaneous/redirect_output.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::{
fs::File,
io::{Result, Write},
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/multiple/row_manager_clean.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{term, tqdm, BarExt, RowManager};
use kdam::{BarExt, RowManager, term, tqdm};
use std::{
io::Result,
sync::{Arc, Mutex},
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/multiple/row_manager_keep.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt, RowManager, term};
use kdam::{BarExt, RowManager, term, tqdm};
use std::{
io::Result,
sync::{Arc, Mutex},
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/multiple/thread.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{term, tqdm, BarExt};
use kdam::{BarExt, term, tqdm};
use std::{io::Result, thread, time::Duration};

fn main() -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions kdam/examples/notebook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
kdam = { path = "../..", features = ["notebook", "template"] }
pyo3 = { version = ">=0.23,<0.26", features = ["extension-module"] }
pyo3 = { version = ">=0.27", features = ["extension-module"] }

[build-dependencies]
pyo3-build-config = ">=0.23,<0.26"
pyo3-build-config = ">=0.27"
4 changes: 2 additions & 2 deletions kdam/examples/rich.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use kdam::{term, term::Colorizer, tqdm, BarExt, Column, RichProgress, Spinner};
use std::io::{stderr, IsTerminal, Result};
use kdam::{BarExt, Column, RichProgress, Spinner, term, term::Colorizer, tqdm};
use std::io::{IsTerminal, Result, stderr};

fn main() -> Result<()> {
term::init(stderr().is_terminal());
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/showcase/animations.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{term, tqdm, Animation, BarExt};
use kdam::{Animation, BarExt, term, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/showcase/fira_code.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/showcase/spinner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{term, term::Writer, Spinner};
use kdam::{Spinner, term, term::Writer};
use std::{
num::NonZeroI16,
time::{Duration, Instant},
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
18 changes: 16 additions & 2 deletions kdam/examples/template.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt, Spinner};
use kdam::{BarExt, Spinner, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand All @@ -8,7 +8,21 @@ fn main() -> Result<()> {
force_refresh = true,
bar_format = "{desc suffix=' '}|{animation}| {spinner} {count}/{total} [{percentage:.0}%] in {elapsed human=true} ({rate:.1}/s, eta: {remaining human=true})",
spinner = Spinner::new(
&["▁▂▃", "▂▃▄", "▃▄▅", "▄▅▆", "▅▆▇", "▆▇█", "▇█▇", "█▇▆", "▇▆▅", "▆▅▄", "▅▄▃", "▄▃▂", "▃▂▁"],
&[
"▁▂▃",
"▂▃▄",
"▃▄▅",
"▄▅▆",
"▅▆▇",
"▆▇█",
"▇█▇",
"█▇▆",
"▇▆▅",
"▆▅▄",
"▅▄▃",
"▄▃▂",
"▃▂▁"
],
30.0,
1.0,
)
Expand Down
2 changes: 1 addition & 1 deletion kdam/examples/unknown.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kdam::{tqdm, BarExt};
use kdam::{BarExt, tqdm};
use std::io::Result;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion kdam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod format;
pub mod term;

pub use crate::std::{
monitor, Animation, Bar, BarBuilder, BarExt, BarIter, Colour, RowManager, TqdmIterator,
Animation, Bar, BarBuilder, BarExt, BarIter, Colour, RowManager, TqdmIterator, monitor,
};

#[cfg(feature = "derive")]
Expand Down
2 changes: 1 addition & 1 deletion kdam/src/rich/bar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::styles;
use crate::{std::Bar, term::Colorizer, BarExt};
use crate::{BarExt, std::Bar, term::Colorizer};
use std::num::{NonZeroI16, NonZeroU16};

#[cfg(feature = "spinner")]
Expand Down
6 changes: 4 additions & 2 deletions kdam/src/rich/styles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::num::{NonZeroU16, NonZeroI16};
use crate::term::Colorizer;
use std::num::{NonZeroI16, NonZeroU16};

// Characters
const BAR_CHR: &str = "━";
Expand All @@ -21,7 +21,9 @@ pub(super) fn bar(ncols: NonZeroU16, progress: f32) -> String {
let ncols = ncols.get();

if progress >= 1.0 {
BAR_CHR.repeat(ncols as usize).colorize(BAR_COMPLETED_COLOUR)
BAR_CHR
.repeat(ncols as usize)
.colorize(BAR_COMPLETED_COLOUR)
} else {
let block = (ncols as f32 * progress) as u16;
(BAR_CHR.repeat(block as usize) + BAR_END_CHR).colorize(BAR_COLOUR)
Expand Down
5 changes: 1 addition & 4 deletions kdam/src/spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ impl Spinner {
/// ```
pub fn new(frames: &[&str], interval: f32, speed: f32) -> Self {
Self {
frames: frames
.iter()
.map(|x| String::from(*x))
.collect(),
frames: frames.iter().map(|x| String::from(*x)).collect(),
interval,
speed,
}
Expand Down
21 changes: 10 additions & 11 deletions kdam/src/std/bar.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::{
styles::{Animation, Colour},
BarExt,
styles::{Animation, Colour},
};
use crate::{
format,
term::{self, Colorizer, InitializedOutput, Writer},
};
use std::{
io::{stdin, Result, Write},
io::{Result, Write, stdin},
num::NonZeroU16,
time::Instant,
};
Expand All @@ -27,7 +27,6 @@ use crate::spinner::Spinner;
#[cfg(feature = "template")]
use formatx::Template;


/// Core implemention of console progress bar.
///
/// # Example
Expand Down Expand Up @@ -367,7 +366,7 @@ impl Bar {
let miniters_constraint = if self.miniters <= 1 {
true
} else {
self.counter % self.miniters == 0
self.counter.is_multiple_of(self.miniters)
};

if (mininterval_constraint && miniters_constraint && delay_constraint)
Expand Down Expand Up @@ -449,11 +448,11 @@ impl BarExt for Bar {
fn render(&mut self) -> String {
#[cfg(feature = "notebook")]
if let Some(container) = &self.container {
Python::with_gil(|py| -> PyResult<()> {
Python::attach(|py| -> PyResult<()> {
let pb = container
.bind(py)
.getattr("children")?
.downcast::<PyTuple>()?
.cast::<PyTuple>()?
.get_item(1)?;

pb.setattr("value", self.counter)?;
Expand Down Expand Up @@ -563,9 +562,9 @@ impl BarExt for Bar {
if let Some(container) = &self.container {
let text = bar_format.unchecked_text();

Python::with_gil(|py| -> PyResult<()> {
Python::attach(|py| -> PyResult<()> {
let container = container.bind(py).getattr("children")?;
let container = container.downcast::<PyTuple>()?;
let container = container.cast::<PyTuple>()?;
let (lbar, rbar) = (container.get_item(0)?, container.get_item(2)?);

if let Some(index) = text.find("{animation}") {
Expand Down Expand Up @@ -616,9 +615,9 @@ impl BarExt for Bar {

#[cfg(feature = "notebook")]
if let Some(container) = &self.container {
Python::with_gil(|py| -> PyResult<()> {
Python::attach(|py| -> PyResult<()> {
let container = container.bind(py).getattr("children")?;
let container = container.downcast::<PyTuple>()?;
let container = container.cast::<PyTuple>()?;
let (lbar, rbar) = (container.get_item(0)?, container.get_item(2)?);

if self.indefinite() {
Expand Down Expand Up @@ -1001,7 +1000,7 @@ impl BarBuilder {

#[cfg(feature = "notebook")]
if notebook::running() {
Python::with_gil(|py| -> PyResult<()> {
Python::attach(|py| -> PyResult<()> {
let ipywidgets = PyModule::import(py, "ipywidgets")?;
let ipython_display = PyModule::import(py, "IPython.display")?;

Expand Down
Loading