Skip to content

Commit

Permalink
bump ratatui to 0.26.1 (#32)
Browse files Browse the repository at this point in the history
this has the benefit of simplifying the code on the side of
`nu_plugin_explore` a bit 👌
  • Loading branch information
amtoine authored Feb 22, 2024
1 parent 4e8cc0b commit 426e3c9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ console = "0.15.7"
crossterm = "0.27.0"
nu-plugin = "0.90.1"
nu-protocol = { version = "0.90.1", features = ["plugin"] }
ratatui = "0.22.0"
ratatui = "0.26.1"
url = "2.4.0"

[lib]
Expand Down
4 changes: 2 additions & 2 deletions src/edit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crossterm::event::KeyCode;
use ratatui::{
prelude::{Backend, Rect},
prelude::Rect,
style::Style,
widgets::{Block, Borders, Clear, Paragraph, Wrap},
Frame,
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Editor {
None
}

pub(super) fn render<B: Backend>(&self, frame: &mut Frame<'_, B>, config: &Config) {
pub(super) fn render(&self, frame: &mut Frame, config: &Config) {
let title = "Editor";

let block = Paragraph::new(self.buffer.as_str())
Expand Down
28 changes: 10 additions & 18 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use super::{App, Config, Mode};
use crossterm::event::KeyCode;
use nu_protocol::ast::PathMember;
use nu_protocol::{Record, Type, Value};
use ratatui::prelude::Backend;
use ratatui::{
prelude::{Alignment, Constraint, Rect},
style::{Color, Modifier, Style},
Expand All @@ -18,12 +17,7 @@ use ratatui::{
};

/// render the whole ui
pub(super) fn render_ui<B: Backend>(
frame: &mut Frame<'_, B>,
app: &App,
config: &Config,
error: Option<&str>,
) {
pub(super) fn render_ui(frame: &mut Frame, app: &App, config: &Config, error: Option<&str>) {
render_data(frame, app, config);
if config.show_cell_path {
render_cell_path(frame, app);
Expand All @@ -41,7 +35,7 @@ pub(super) fn render_ui<B: Backend>(
}
}

pub(super) fn render_error<B: Backend>(frame: &mut Frame<'_, B>, error: &str) {
pub(super) fn render_error(frame: &mut Frame, error: &str) {
let bottom_two_lines = Rect::new(0, frame.size().height - 2, frame.size().width, 2);

let lines = vec![
Expand Down Expand Up @@ -229,7 +223,7 @@ fn repr_table(table: &[Record]) -> (Vec<String>, Vec<String>, Vec<Vec<String>>)
///
/// the data will be rendered on top of the bar, and on top of the cell path in case
/// [`crate::config::Config::show_cell_path`] is set to `true`.
fn render_data<B: Backend>(frame: &mut Frame<'_, B>, app: &App, config: &Config) {
fn render_data(frame: &mut Frame, app: &App, config: &Config) {
let data_frame_height = if config.show_cell_path {
frame.size().height - 2
} else {
Expand Down Expand Up @@ -318,12 +312,11 @@ fn render_data<B: Backend>(frame: &mut Frame<'_, B>, app: &App, config: &Config)
.map(|r| Row::new(r.iter().cloned().map(Cell::from).collect::<Vec<Cell>>()))
.collect();

let table = Table::new(rows)
let table = Table::new(rows, widths)
.header(header)
.block(Block::default().borders(Borders::ALL))
.highlight_style(highlight_style)
.highlight_symbol(&config.colors.selected_symbol)
.widths(&widths);
.highlight_symbol(config.colors.selected_symbol.clone());

frame.render_stateful_widget(
table,
Expand Down Expand Up @@ -446,14 +439,13 @@ fn render_data<B: Backend>(frame: &mut Frame<'_, B>, app: &App, config: &Config)
};

let table = if config.show_table_header {
Table::new(rows).header(header.height(1))
Table::new(rows, constraints).header(header.height(1))
} else {
Table::new(rows)
Table::new(rows, constraints)
}
.block(Block::default().borders(Borders::ALL))
.highlight_style(highlight_style)
.highlight_symbol(&config.colors.selected_symbol)
.widths(&constraints);
.highlight_symbol(config.colors.selected_symbol.clone());

frame.render_stateful_widget(
table,
Expand Down Expand Up @@ -481,7 +473,7 @@ fn render_data<B: Backend>(frame: &mut Frame<'_, B>, app: &App, config: &Config)
/// ```text
/// ||cell path: $.foo.bar.2.baz ...||
/// ```
fn render_cell_path<B: Backend>(frame: &mut Frame<'_, B>, app: &App) {
fn render_cell_path(frame: &mut Frame, app: &App) {
let next_to_bottom_bar_rect = Rect::new(0, frame.size().height - 2, frame.size().width, 1);
let cell_path = format!(
"cell path: $.{}",
Expand Down Expand Up @@ -530,7 +522,7 @@ fn render_cell_path<B: Backend>(frame: &mut Frame<'_, B>, app: &App) {
/// ```text
/// ||PEEKING ... <esc> to NORMAL | a to peek all | c to peek current view | u to peek under cursor | q to quit||
/// ```
fn render_status_bar<B: Backend>(frame: &mut Frame<'_, B>, app: &App, config: &Config) {
fn render_status_bar(frame: &mut Frame, app: &App, config: &Config) {
let bottom_bar_rect = Rect::new(0, frame.size().height - 1, frame.size().width, 1);

let bg_style = match app.mode {
Expand Down

0 comments on commit 426e3c9

Please sign in to comment.