Skip to content

Commit 8ca3331

Browse files
authored
Merge pull request #10 from jbicha/nu-ansi-term
feat: replace `ansiterm` with `nu-ansi-term`
2 parents 7df0aa5 + aae463b commit 8ca3331

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

crosstermion/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include = ["src/**/*", "LICENSE.md", "README.md", "CHANGELOG.md"]
1212
[features]
1313
default = []
1414

15-
color = ["ansiterm"]
15+
color = ["nu-ansi-term"]
1616

1717
input-async = ["futures-channel", "async-channel", "futures-lite", "futures-core" ]
1818
input-async-crossterm = ["crossterm/event-stream", "input-async"]
@@ -28,9 +28,9 @@ crossterm = { version = "0.27.0", optional = true, default-features = false, fea
2828
futures-channel = { version = "0.3.5", optional = true, default-features = false, features = ["std", "sink"] }
2929
futures-core = { version = "0.3.5", optional = true, default-features = false }
3030
futures-lite = { version = "2.1.0", optional = true }
31+
nu-ansi-term = { version = "0.50", optional = true, default-features = false }
3132
tui = { package = "ratatui", version = "0.26.0", optional = true, default-features = false }
3233
tui-react = { version = "^0.23.2", optional = true, default-features = false, path = "../tui-react" }
33-
ansiterm = { version = "0.12.2", optional = true, default-features = false }
3434
async-channel = { version = "2.1.1", optional = true }
3535

3636
[target."cfg(windows)".dependencies]

crosstermion/src/color.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::borrow::Cow;
22
use std::ffi::OsStr;
33

4-
#[cfg(feature = "ansiterm")]
4+
#[cfg(feature = "nu-ansi-term")]
55
mod _impl {
6-
use ansiterm::{ANSIGenericString, Style};
6+
use nu_ansi_term::{AnsiGenericString, Style};
77

88
pub struct Brush {
99
may_paint: bool,
@@ -27,20 +27,20 @@ mod _impl {
2727
pub fn paint<'a, I, S: 'a + ToOwned + ?Sized>(
2828
&mut self,
2929
input: I,
30-
) -> ANSIGenericString<'a, S>
30+
) -> AnsiGenericString<'a, S>
3131
where
3232
I: Into<std::borrow::Cow<'a, S>>,
3333
<S as ToOwned>::Owned: std::fmt::Debug,
3434
{
3535
match (self.may_paint, self.style.as_ref().take()) {
3636
(true, Some(style)) => style.paint(input),
37-
(_, Some(_)) | (_, None) => ANSIGenericString::from(input),
37+
(_, Some(_)) | (_, None) => AnsiGenericString::from(input),
3838
}
3939
}
4040
}
4141
}
4242

43-
#[cfg(feature = "ansiterm")]
43+
#[cfg(feature = "nu-ansi-term")]
4444
pub use _impl::*;
4545

4646
/// Return true if we should colorize the output, based on [clicolors spec](https://bixense.com/clicolors/) and [no-color spec](https://no-color.org)

crosstermion/src/input.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ pub fn input_channel() -> std::sync::mpsc::Receiver<Event> {
4747
Action::Continue => continue,
4848
Action::Result(res) => res?,
4949
};
50-
if let Ok(event) = event.try_into() {
51-
if key_send.send(event).is_err() {
52-
break;
53-
}
50+
let Ok(event) = event.try_into();
51+
if key_send.send(event).is_err() {
52+
break;
5453
}
5554
}
5655
Ok(())

crosstermion/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ pub mod cursor;
1111
pub mod color;
1212

1313
// Reexports
14-
#[cfg(feature = "ansiterm")]
15-
pub use ansiterm as ansi_term;
1614
#[cfg(feature = "crossterm")]
1715
pub use crossterm;
16+
#[cfg(feature = "nu-ansi-term")]
17+
pub use nu_ansi_term;
1818
#[cfg(feature = "tui")]
1919
pub use tui;
2020
#[cfg(feature = "tui-react")]

tui-react/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mod terminal;
66
pub use list::*;
77
pub use terminal::*;
88

9-
use std::iter::repeat;
109
use tui::{self, buffer::Buffer, layout::Rect, style::Color, style::Style};
1110
use unicode_segmentation::UnicodeSegmentation;
1211
use unicode_width::UnicodeWidthStr;
@@ -15,7 +14,7 @@ pub fn fill_background_to_right(mut s: String, entire_width: u16) -> String {
1514
match (s.len(), entire_width as usize) {
1615
(x, y) if x >= y => s,
1716
(x, y) => {
18-
s.extend(repeat(' ').take(y - x));
17+
s.extend(std::iter::repeat_n(' ', y - x));
1918
s
2019
}
2120
}
@@ -52,7 +51,7 @@ pub fn draw_text_with_ellipsis_nowrap(
5251
if x + 1 == bound.right() {
5352
ellipsis_candidate_x = Some(x);
5453
}
55-
cell.set_symbol(g.into());
54+
cell.set_symbol(g);
5655
if let Some(s) = s {
5756
cell.set_style(s);
5857
}
@@ -68,7 +67,7 @@ pub fn draw_text_with_ellipsis_nowrap(
6867
}
6968
}
7069
if let (Some(_), Some(x)) = (graphemes.next(), ellipsis_candidate_x) {
71-
buf.get_mut(x, bound.y).set_symbol("…".into());
70+
buf.get_mut(x, bound.y).set_symbol("…");
7271
}
7372
}
7473
total_width as u16
@@ -85,7 +84,7 @@ pub fn draw_text_nowrap_fn(
8584
}
8685
for (g, x) in t.as_ref().graphemes(true).zip(bound.left()..bound.right()) {
8786
let cell = buf.get_mut(x, bound.y);
88-
cell.set_symbol(g.into());
87+
cell.set_symbol(g);
8988
cell.set_style(s(cell.symbol(), x, bound.y));
9089
}
9190
}

tui-react/src/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct List {
1414
impl List {
1515
fn list_offset_for(&self, entry_in_view: Option<usize>, height: usize) -> usize {
1616
match entry_in_view {
17-
Some(pos) => match height as usize {
17+
Some(pos) => match height {
1818
h if (self.offset + h).saturating_sub(1) < pos => pos - h + 1,
1919
_ if self.offset > pos => pos,
2020
_ => self.offset,

tui-react/src/terminal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ mod tests {
138138
use super::*;
139139
use tui::backend::TestBackend;
140140

141+
#[expect(dead_code)]
141142
#[derive(Default, Clone)]
142143
struct ComplexProps {
143144
x: usize,
@@ -175,7 +176,7 @@ mod tests {
175176
term.render(&mut c, 3usize).ok();
176177
assert_eq!(c.x, 3);
177178

178-
let mut c = StatelessComponent::default();
179+
let mut c = StatelessComponent;
179180
term.render(&mut c, ComplexProps::default()).ok();
180181
}
181182
}

0 commit comments

Comments
 (0)