Skip to content

Commit

Permalink
fix(terminal)!: make terminal module private (#1260)
Browse files Browse the repository at this point in the history
This is a simplification of the public API that is helpful for new users
that are not familiar with how rust re-exports work, and helps avoid
clashes with other modules in the backends that are named terminal.

BREAKING CHANGE: The `terminal` module is now private and can not be
used directly. The types under this module are exported from the root of
the crate.

```diff
- use ratatui::terminal::{CompletedFrame, Frame, Terminal, TerminalOptions, ViewPort};
+ use ratatui::{CompletedFrame, Frame, Terminal, TerminalOptions, ViewPort};
```

Fixes: #1210
  • Loading branch information
joshka authored Aug 2, 2024
1 parent 5b89bd0 commit 84cb164
Show file tree
Hide file tree
Showing 38 changed files with 64 additions and 41 deletions.
27 changes: 26 additions & 1 deletion BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ GitHub with a [breaking change] label.

This is a quick summary of the sections below:

- [v0.28.0](#v0280)
- [v0.28.0](#v0280) (unreleased)
- `Layout::init_cache` no longer returns bool and takes a `NonZeroUsize` instead of `usize`
- `ratatui::terminal` module is now private
- [v0.27.0](#v0270)
- List no clamps the selected index to list
- Prelude items added / removed
Expand Down Expand Up @@ -58,6 +59,30 @@ This is a quick summary of the sections below:
- MSRV is now 1.63.0
- `List` no longer ignores empty strings

## v0.28.0 (unreleased)

### `Layout::init_cache` no longer returns bool and takes a `NonZeroUsize` instead of `usize` ([#1145])

[#1145]: https://github.com/ratatui-org/ratatui/pull/1145

```diff
- let is_initialized = Layout::init_cache(100);
+ Layout::init_cache(NonZeroUsize::new(100).unwrap());
```

### `ratatui::terminal` module is now private ([#1160])

[#1160]: https://github.com/ratatui-org/ratatui/pull/1160

The `terminal` module is now private and can not be used directly. The types under this module are
exported from the root of the crate. This reduces clashes with other modules in the backends that
are also named terminal, and confusion about module exports for newer Rust users.

```diff
- use ratatui::terminal::{CompletedFrame, Frame, Terminal, TerminalOptions, ViewPort};
+ use ratatui::{CompletedFrame, Frame, Terminal, TerminalOptions, ViewPort};
```

## [v0.27.0](https://github.com/ratatui-org/ratatui/releases/tag/v0.27.0)

### List no clamps the selected index to list ([#1159])
Expand Down
2 changes: 1 addition & 1 deletion examples/barchart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use ratatui::{
},
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
terminal::{Frame, Terminal},
text::{Line, Span},
widgets::{Bar, BarChart, BarGroup, Block, Paragraph},
Frame, Terminal,
};

struct Company<'a> {
Expand Down
2 changes: 1 addition & 1 deletion examples/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ use ratatui::{
},
layout::{Alignment, Constraint, Layout, Rect},
style::{Style, Stylize},
terminal::Frame,
text::Line,
widgets::{
block::{Position, Title},
Block, BorderType, Borders, Padding, Paragraph, Wrap,
},
Frame,
};

// These type aliases are used to make the code more readable by reducing repetition of the generic
Expand Down
2 changes: 1 addition & 1 deletion examples/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Color, Stylize},
symbols::Marker,
terminal::{Frame, Terminal},
widgets::{
canvas::{Canvas, Circle, Map, MapResolution, Rectangle},
Block, Widget,
},
Frame, Terminal,
};

fn main() -> io::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion examples/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ use ratatui::{
layout::{Alignment, Constraint, Layout, Rect},
style::{Color, Modifier, Style, Stylize},
symbols::{self, Marker},
terminal::{Frame, Terminal},
text::Span,
widgets::{block::Title, Axis, Block, Chart, Dataset, GraphType, LegendPosition},
Frame, Terminal,
};

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion examples/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ use ratatui::{
},
layout::{Alignment, Constraint, Layout, Rect},
style::{Color, Style, Stylize},
terminal::{Frame, Terminal},
text::Line,
widgets::{Block, Borders, Paragraph},
Frame, Terminal,
};

type Result<T> = result::Result<T, Box<dyn Error>>;
Expand Down
2 changes: 1 addition & 1 deletion examples/colors_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ use ratatui::{
},
layout::{Constraint, Layout, Rect},
style::Color,
terminal::Terminal,
text::Text,
widgets::Widget,
Terminal,
};

#[derive(Debug, Default)]
Expand Down
2 changes: 1 addition & 1 deletion examples/constraint-explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use ratatui::{
Color, Style, Stylize,
},
symbols::{self, line},
terminal::Terminal,
text::{Line, Span, Text},
widgets::{Block, Paragraph, Widget, Wrap},
Terminal,
};
use strum::{Display, EnumIter, FromRepr};

Expand Down
2 changes: 1 addition & 1 deletion examples/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ use ratatui::{
},
style::{palette::tailwind, Color, Modifier, Style, Stylize},
symbols,
terminal::Terminal,
text::Line,
widgets::{
Block, Padding, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget,
Tabs, Widget,
},
Terminal,
};
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use ratatui::{
},
layout::{Constraint, Layout, Rect},
style::{Color, Style},
terminal::{Frame, Terminal},
text::Line,
widgets::{Paragraph, Widget},
Frame, Terminal,
};

/// A custom widget that renders a button with a label, theme and state.
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ratatui::{
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
},
terminal::Terminal,
Terminal,
};

use crate::{app::App, ui};
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/termion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::{error::Error, io, sync::mpsc, thread, time::Duration};

use ratatui::{
backend::{Backend, TermionBackend},
terminal::Terminal,
termion::{
event::Key,
input::{MouseTerminal, TermRead},
raw::IntoRawMode,
screen::IntoAlternateScreen,
},
Terminal,
};

use crate::{app::App, ui};
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/termwiz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::{

use ratatui::{
backend::TermwizBackend,
terminal::Terminal,
termwiz::{
input::{InputEvent, KeyCode},
terminal::Terminal as TermwizTerminal,
},
Terminal,
};

use crate::{app::App, ui};
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
symbols,
terminal::Frame,
text::{self, Span},
widgets::{
canvas::{self, Canvas, Circle, Map, MapResolution, Rectangle},
Axis, BarChart, Block, Cell, Chart, Dataset, Gauge, LineGauge, List, ListItem, Paragraph,
Row, Sparkline, Table, Tabs, Wrap,
},
Frame,
};

use crate::app::App;
Expand Down
2 changes: 1 addition & 1 deletion examples/demo2/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use ratatui::{
crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind},
layout::{Constraint, Layout, Rect},
style::Color,
terminal::Terminal,
text::{Line, Span},
widgets::{Block, Tabs, Widget},
Terminal,
};
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};

Expand Down
2 changes: 1 addition & 1 deletion examples/demo2/big_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
//! layout::{self, Alignment, Constraint, Direction, Layout, Margin, Rect},
//! style::{self, Color, Modifier, Style, Styled, Stylize},
//! symbols::{self, Marker},
//! terminal::{CompletedFrame, Frame, Terminal, TerminalOptions, Viewport},
//! text::{self, Line, Masked, Span, Text},
//! widgets::{block::BlockExt, StatefulWidget, Widget},
//! CompletedFrame, Frame, Terminal, TerminalOptions, Viewport,
//! };
//! use tui_big_text::{BigTextBuilder, PixelSize};
//!
Expand Down
2 changes: 1 addition & 1 deletion examples/demo2/destroy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use ratatui::{
buffer::Buffer,
layout::{Flex, Layout, Rect},
style::{Color, Style},
terminal::Frame,
widgets::Widget,
Frame,
};
use unicode_width::UnicodeWidthStr;

Expand Down
2 changes: 1 addition & 1 deletion examples/demo2/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ratatui::{
ExecutableCommand,
},
layout::Rect,
terminal::{Terminal, TerminalOptions, Viewport},
Terminal, TerminalOptions, Viewport,
};

pub fn init() -> Result<Terminal<impl Backend>> {
Expand Down
2 changes: 1 addition & 1 deletion examples/docsrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use ratatui::{
},
layout::{Constraint, Layout},
style::{Color, Modifier, Style, Stylize},
terminal::{Frame, Terminal},
text::{Line, Span, Text},
widgets::{Block, Borders, Paragraph},
Frame, Terminal,
};

/// Example code for lib.rs
Expand Down
2 changes: 1 addition & 1 deletion examples/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ use ratatui::{
},
style::{palette::tailwind, Color, Modifier, Style, Stylize},
symbols::{self, line},
terminal::Terminal,
text::{Line, Text},
widgets::{
block::Title, Block, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState,
StatefulWidget, Tabs, Widget,
},
Terminal,
};
use strum::{Display, EnumIter, FromRepr, IntoEnumIterator};

Expand Down
2 changes: 1 addition & 1 deletion examples/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ use ratatui::{
},
layout::{Alignment, Constraint, Layout, Rect},
style::{palette::tailwind, Color, Style, Stylize},
terminal::Terminal,
text::Span,
widgets::{block::Title, Block, Borders, Gauge, Padding, Paragraph, Widget},
Terminal,
};

const GAUGE1_COLOR: Color = tailwind::RED.c800;
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use ratatui::{
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
},
terminal::{Frame, Terminal},
widgets::Paragraph,
Frame, Terminal,
};

/// This is a bare minimum example. There are many approaches to running an application loop, so
Expand Down
3 changes: 1 addition & 2 deletions examples/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ use ratatui::{
layout::{Alignment, Constraint, Layout, Rect},
style::{Color, Modifier, Style},
symbols,
terminal::{Frame, Terminal, Viewport},
text::{Line, Span},
widgets::{block, Block, Gauge, LineGauge, List, ListItem, Paragraph, Widget},
TerminalOptions,
Frame, Terminal, TerminalOptions, Viewport,
};

const NUM_DOWNLOADS: usize = 10;
Expand Down
2 changes: 1 addition & 1 deletion examples/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ use ratatui::{
Layout, Rect,
},
style::{Color, Style, Stylize},
terminal::{Frame, Terminal},
text::Line,
widgets::{Block, Paragraph},
Frame, Terminal,
};

fn main() -> Result<(), Box<dyn Error>> {
Expand Down
2 changes: 1 addition & 1 deletion examples/line_gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use ratatui::{
},
layout::{Alignment, Constraint, Layout, Rect},
style::{palette::tailwind, Color, Style, Stylize},
terminal::Terminal,
widgets::{block::Title, Block, Borders, LineGauge, Padding, Paragraph, Widget},
Terminal,
};

const CUSTOM_LABEL_COLOR: Color = tailwind::SLATE.c200;
Expand Down
4 changes: 2 additions & 2 deletions examples/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ use ratatui::{
Color, Modifier, Style, Stylize,
},
symbols,
terminal::Terminal,
text::Line,
widgets::{
Block, Borders, HighlightSpacing, List, ListItem, ListState, Padding, Paragraph,
StatefulWidget, Widget, Wrap,
},
Terminal,
};

const TODO_HEADER_STYLE: Style = Style::new().fg(SLATE.c100).bg(BLUE.c800);
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tui {
},
ExecutableCommand,
},
terminal::Terminal,
Terminal,
};

pub fn init_error_hooks() -> color_eyre::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion examples/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ use ratatui::{
},
layout::{Constraint, Layout},
style::{Color, Modifier, Style, Stylize},
terminal::{Frame, Terminal},
text::Line,
widgets::Paragraph,
Frame, Terminal,
};

type Result<T> = result::Result<T, Box<dyn Error>>;
Expand Down
2 changes: 1 addition & 1 deletion examples/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ use ratatui::{
event::{self, Event, KeyCode},
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
},
terminal::{Frame, Terminal},
text::Line,
widgets::{Block, Paragraph},
Frame, Terminal,
};

type Result<T> = std::result::Result<T, Box<dyn Error>>;
Expand Down
2 changes: 1 addition & 1 deletion examples/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod common {
crossterm::terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
},
terminal::Terminal,
Terminal,
};

// A simple alias for the terminal type used in this example.
Expand Down
2 changes: 1 addition & 1 deletion examples/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use ratatui::{
},
layout::{Constraint, Layout, Rect},
style::Stylize,
terminal::{Frame, Terminal},
widgets::{Block, Clear, Paragraph, Wrap},
Frame, Terminal,
};

struct App {
Expand Down
3 changes: 1 addition & 2 deletions examples/ratatui-logo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ use itertools::izip;
use ratatui::{
backend::{Backend, CrosstermBackend},
crossterm::terminal::{disable_raw_mode, enable_raw_mode},
terminal::{Terminal, Viewport},
widgets::Paragraph,
TerminalOptions,
Terminal, TerminalOptions, Viewport,
};

/// A fun example of using half block characters to draw a logo
Expand Down
Loading

0 comments on commit 84cb164

Please sign in to comment.