Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update dependencies #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ edition = "2021"

[dependencies]
#tui = "0.18.0"
ratatui = "0.20.0"
ratatui = "0.28.1"
bounded-vec-deque = { version = "0.1.1", optional = true }
lazy_static = { version = "1.4.0", optional = true }
time = { version = "0.3.11", features = ["local-offset", "macros"] , optional = true }
lazy_static = { version = "1.5.0", optional = true }
time = { version = "0.3.36", features = ["local-offset", "macros"] , optional = true }
serde = { version ="1.0", optional = true }
serde_derive = { version = "1.0", optional = true }

[dev-dependencies]
crossterm = "0.23.2"
crossterm = "0.28.1"

[features]
default = ["styled_list", "calendar", "text_macros"]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Additional widgets for [ratatui](https://crates.io/crates/ratatui).

These widgets are designed to operate similar to the built-in widgets in tui-rs, and should fit
These widgets are designed to operate similar to the built-in widgets in ratatui, and should fit
into your app cleanly.

TODO: Add example gifs
Expand All @@ -19,15 +19,15 @@ Since the internals are documented as well.
By default all the widgets are built and available:
```toml
[dependencies]
extra-widgets = "0.0.1"
ratatui = "0.20.0"
extra-widgets = "0.1.0"
ratatui = "0.28.1"
```
Alternately, each widget can be enabled individually. The feature names are the same as the
module name for the widget. To just use the calendar widget:
```toml
[dependencies]
extra-widgets = {"0.0.1" default-features = false, features = ["calendar"] }
ratatui = "0.20.0"
extra-widgets = {"0.1.0" default-features = false, features = ["calendar"] }
ratatui = "0.28.1"
```
Dependencies for each widget are only pulled if the feature is enabled.

Expand Down
6 changes: 3 additions & 3 deletions examples/calendar/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crossterm::{
};

use ratatui::{
backend::{Backend, CrosstermBackend},
backend::CrosstermBackend,
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
Frame, Terminal,
Expand Down Expand Up @@ -44,8 +44,8 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}

fn draw<B: Backend>(f: &mut Frame<B>) {
let app_area = f.size();
fn draw(f: &mut Frame) {
let app_area = f.area();

let calarea = Rect {
x: app_area.x + 1,
Expand Down
3 changes: 1 addition & 2 deletions examples/list_demo/demos/basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ratatui::{
backend::Backend,
layout::Rect,
style::{Color, Style},
Frame,
Expand All @@ -9,7 +8,7 @@ use extra_widgets::styled_list::{ItemDisplay, StyledList};

use super::super::{words, AppState};

pub fn basic<B: Backend>(area: Rect, state: &mut AppState, f: &mut Frame<B>) {
pub fn basic(area: Rect, state: &mut AppState, f: &mut Frame) {
let demo_items = words();
let demo_list = StyledList::new(demo_items)
.default_style(Style::reset().bg(Color::Black).fg(Color::White))
Expand Down
3 changes: 1 addition & 2 deletions examples/list_demo/demos/fixed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ratatui::{
backend::Backend,
layout::Rect,
style::{Color, Style},
Frame,
Expand All @@ -9,7 +8,7 @@ use extra_widgets::styled_list::{ItemDisplay, StyledList, WindowType};

use super::super::{words, AppState};

pub fn fixed<B: Backend>(area: Rect, state: &mut AppState, f: &mut Frame<B>) {
pub fn fixed(area: Rect, state: &mut AppState, f: &mut Frame) {
let demo_items = words();
let demo_list = StyledList::new(demo_items)
.default_style(Style::reset().bg(Color::Black).fg(Color::White))
Expand Down
3 changes: 1 addition & 2 deletions examples/list_demo/demos/separated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ratatui::{
backend::Backend,
layout::Rect,
style::{Color, Style},
Frame,
Expand All @@ -9,7 +8,7 @@ use extra_widgets::styled_list::{ItemDisplay, StyledList};

use super::super::{words, AppState};

pub fn separated<B: Backend>(area: Rect, state: &mut AppState, f: &mut Frame<B>) {
pub fn separated(area: Rect, state: &mut AppState, f: &mut Frame) {
let demo_items = words();
let demo_list = StyledList::new(demo_items)
.default_style(Style::reset().bg(Color::Black).fg(Color::White))
Expand Down
3 changes: 1 addition & 2 deletions examples/list_demo/demos/styled_items.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ratatui::{
backend::Backend,
layout::Rect,
style::{Color, Modifier, Style},
Frame,
Expand All @@ -9,7 +8,7 @@ use extra_widgets::styled_list::{Indicator, ItemDisplay, LineIndicators, StyledL

use super::super::{words, AppState};

pub fn styled_items<B: Backend>(area: Rect, state: &mut AppState, f: &mut Frame<B>) {
pub fn styled_items(area: Rect, state: &mut AppState, f: &mut Frame) {
let demo_items = words();
let orange = Style::default().bg(Color::Rgb(242, 147, 5));
let demo_items =
Expand Down
47 changes: 25 additions & 22 deletions examples/list_demo/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{error::Error, io};

use crossterm::{
event::{self, Event, KeyCode},
event::{self, Event, KeyCode, KeyEventKind},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};

use ratatui::{
backend::{Backend, CrosstermBackend},
backend::CrosstermBackend,
layout::{Alignment, Constraint, Direction, Layout, Margin},
style::{Color, Modifier, Style},
text::{Span, Spans},
text::{Span, Line},
widgets::{Block, BorderType, Borders, Paragraph},
Frame, Terminal,
};
Expand Down Expand Up @@ -90,21 +90,24 @@ fn main() -> Result<(), Box<dyn Error>> {
let _ = terminal.draw(|f| draw(mstate, f));

if let Event::Key(key) = event::read()? {
match key.code {
KeyCode::Char(c) if c == 'j' => {
state.move_down();
}
KeyCode::Char(c) if c == 'k' => {
state.move_up();
}
KeyCode::Char(c) if c == 'h' || c == 'l' => {
state.switch_focus();
}
KeyCode::Char(_) => {
break;
}
_ => {}
};
// On windows, we need to ignore non-press events or we get each key twice: Once for press, once for release
if key.kind == KeyEventKind::Press {
match key.code {
KeyCode::Char(c) if c == 'j' => {
state.move_down();
}
KeyCode::Char(c) if c == 'k' => {
state.move_up();
}
KeyCode::Char(c) if c == 'h' || c == 'l' => {
state.switch_focus();
}
KeyCode::Char(_) => {
break;
}
_ => {}
};
}
}
}

Expand All @@ -114,8 +117,8 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}

fn draw<B: Backend>(state: &mut AppState, f: &mut Frame<B>) {
let app_area = f.size();
fn draw(state: &mut AppState, f: &mut Frame) {
let app_area = f.area();
let layout = Layout::default()
.direction(Direction::Vertical)
.margin(1)
Expand All @@ -136,7 +139,7 @@ fn draw<B: Backend>(state: &mut AppState, f: &mut Frame<B>) {
let main_area = chunks[2];

// draw top bar
let top_text = Spans::from(vec![
let top_text = Line::from(vec![
Span::styled("Controls:", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" 'h' - "),
Span::styled("left,", Style::default().add_modifier(Modifier::ITALIC)),
Expand Down Expand Up @@ -186,7 +189,7 @@ fn draw<B: Backend>(state: &mut AppState, f: &mut Frame<B>) {
];
state.picker.resize(4);

let demo_list_area = demo_list_area.inner(&Margin {
let demo_list_area = demo_list_area.inner(Margin {
vertical: 2,
horizontal: 2,
});
Expand Down
10 changes: 5 additions & 5 deletions examples/macros/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crossterm::{
};

use ratatui::{
backend::{Backend, CrosstermBackend},
backend::CrosstermBackend,
layout::{Constraint, Direction, Layout, Margin, Rect},
style::Color,
text::Text,
Expand Down Expand Up @@ -44,7 +44,7 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}

fn draw<B: Backend>(f: &mut Frame<B>) {
fn draw(f: &mut Frame) {
let result = text! {
underlined!("Some fancy text for you!");
"";
Expand Down Expand Up @@ -90,15 +90,15 @@ text! {
.direction(Direction::Vertical)
.margin(0)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.split(f.size());
.split(f.area());
(chunks[0], chunks[1])
};

make_block("code", code, code_pane, f);
make_block("result", result, result_pane, f);
}

fn make_block<'a, B: Backend>(title: &str, text: impl Into<Text<'a>>, pos: Rect, f: &mut Frame<B>) {
fn make_block<'a>(title: &str, text: impl Into<Text<'a>>, pos: Rect, f: &mut Frame) {
let b = Block::default().title(title).borders(Borders::all());
let inner = b.inner(pos);
f.render_widget(b, pos);
Expand All @@ -109,7 +109,7 @@ fn make_block<'a, B: Backend>(title: &str, text: impl Into<Text<'a>>, pos: Rect,
}

fn get_middle(area: Rect) -> Rect {
area.inner(&Margin {
area.inner(Margin {
vertical: 2,
horizontal: 5,
})
Expand Down
17 changes: 10 additions & 7 deletions src/calendar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ratatui::{
buffer::Buffer,
layout::Rect,
style::Style,
text::{Span, Spans},
text::{Span, Line},
widgets::{Block, Widget},
};

Expand Down Expand Up @@ -122,7 +122,7 @@ impl<'a, S: DateStyler> Widget for Calendar<'a, S> {
);
// cal is 21 cells wide, so hard code the 11
let x_off = 11_u16.saturating_sub(line.width() as u16 / 2);
buf.set_spans(area.x + x_off, area.y, &line.into(), area.width);
buf.set_line(area.x + x_off, area.y, &line.into(), area.width);
area.y += 1
}

Expand All @@ -140,19 +140,22 @@ impl<'a, S: DateStyler> Widget for Calendar<'a, S> {

// go through all the weeks containing a day in the target month.
while curr_day.month() as u8 != self.display_date.month().next() as u8 {
let mut line = Spans(Vec::with_capacity(14));
let mut line = Line {
spans: Vec::with_capacity(14),
..Default::default()
};
for i in 0..7 {
// Draw the gutter. Do it here so we can avoid worrying about
// styling the ' ' in the format_date method
if i == 0 {
line.0.push(Span::styled(" ", Style::default()));
line.push_span(Span::styled(" ", Style::default()));
} else {
line.0.push(Span::styled(" ", self.default_bg()));
line.push_span(Span::styled(" ", self.default_bg()));
}
line.0.push(self.format_date(curr_day));
line.push_span(self.format_date(curr_day));
curr_day += Duration::DAY;
}
buf.set_spans(area.x, area.y, &line, area.width);
buf.set_line(area.x, area.y, &line, area.width);
area.y += 1;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Additional widgets for [tui-rs](https://crates.io/crates/tui).
//! Additional widgets for [ratatui](https://crates.io/crates/ratatui).
//!
//! These widgets are designed to operate similar to the built-in widgets in tui-rs, and should fit
//! These widgets are designed to operate similar to the built-in widgets in ratatui, and should fit
//! into your app cleanly.
//!
//! TODO: Add example gifs
Expand All @@ -9,15 +9,15 @@
//! By default all the widgets are built and available:
//! ```toml
//! [dependencies]
//! extra-widgets = "0.0.1"
//! tui = "0.18"
//! extra-widgets = "0.1.0"
//! ratatui = "0.28.1"
//! ```
//! Alternately, each widget can be enabled individually. The feature names are the same as the
//! module name for the widget. To just use the calendar widget:
//! ```toml
//! [dependencies]
//! extra-widgets = {"0.0.1" default-features = false, features = ["calendar"] }
//! tui = "0.18"
//! extra-widgets = {"0.1.0"" default-features = false, features = ["calendar"] }
//! ratatui = "0.28.1"
//! ```
//! Dependencies for each widget are only pulled if the feature is enabled.
//!
Expand Down
Loading