Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
lib: Fix column spacing
Erik Kundt committed 4 months ago
commit 3cd7833e29385fd808b7e090e50fe87cda8d4cc5
parent a541323
8 files changed +88 -19
modified bin/commands/inbox/list.rs
@@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex};

use anyhow::Result;

+
use radicle_tui::ui::Spacing;
use termion::event::Key;

use ratatui::layout::Constraint;
@@ -363,7 +364,12 @@ impl App {
            Layout::vertical([Constraint::Length(3), Constraint::Min(1)]),
            Some(1),
            |ui| {
-
                ui.column_bar(frame, header.to_vec(), Some(Borders::Top));
+
                ui.column_bar(
+
                    frame,
+
                    header.to_vec(),
+
                    Spacing::default(),
+
                    Some(Borders::Top),
+
                );

                let table = ui.table(
                    frame,
@@ -544,7 +550,7 @@ impl App {
            }
        };

-
        ui.column_bar(frame, context, Some(Borders::None));
+
        ui.column_bar(frame, context, Spacing::from(0), Some(Borders::None));
    }

    pub fn show_browser_shortcuts(&self, frame: &mut Frame, ui: &mut im::Ui<Message>) {
@@ -580,6 +586,7 @@ impl App {
                                    Constraint::Fill(1),
                                )]
                                .to_vec(),
+
                                Spacing::from(0),
                                Some(Borders::All),
                            );
                        },
@@ -594,6 +601,7 @@ impl App {
        ui.column_bar(
            frame,
            [Column::new(Span::raw(" Help ").bold(), Constraint::Fill(1))].to_vec(),
+
            Spacing::from(0),
            Some(Borders::Top),
        );

@@ -631,6 +639,7 @@ impl App {
                ),
            ]
            .to_vec(),
+
            Spacing::from(0),
            Some(Borders::None),
        );
    }
modified bin/commands/patch/list.rs
@@ -22,8 +22,7 @@ use tui::ui::im;
use tui::ui::im::widget::{PanesState, TableState, TextEditState, TextViewState, Window};
use tui::ui::im::Borders;
use tui::ui::im::Show;
-
use tui::ui::BufferedValue;
-
use tui::ui::Column;
+
use tui::ui::{BufferedValue, Column, Spacing};
use tui::{Channel, Exit};

type Selection = tui::Selection<PatchId>;
@@ -346,7 +345,12 @@ impl App {
            Layout::vertical([Constraint::Length(3), Constraint::Min(1)]),
            Some(1),
            |ui| {
-
                ui.column_bar(frame, header.to_vec(), Some(Borders::Top));
+
                ui.column_bar(
+
                    frame,
+
                    header.to_vec(),
+
                    Spacing::default(),
+
                    Some(Borders::Top),
+
                );

                let table = ui.table(
                    frame,
@@ -569,7 +573,7 @@ impl App {
            }
        };

-
        ui.column_bar(frame, context, Some(Borders::None));
+
        ui.column_bar(frame, context, Spacing::from(0), Some(Borders::None));
    }

    pub fn show_browser_shortcuts(&self, frame: &mut Frame, ui: &mut im::Ui<Message>) {
@@ -595,6 +599,7 @@ impl App {
        ui.column_bar(
            frame,
            [Column::new(Span::raw(" Help ").bold(), Constraint::Fill(1))].to_vec(),
+
            Spacing::from(0),
            Some(Borders::Top),
        );

@@ -632,6 +637,7 @@ impl App {
                ),
            ]
            .to_vec(),
+
            Spacing::from(0),
            Some(Borders::None),
        );
    }
modified bin/commands/patch/review.rs
@@ -27,7 +27,7 @@ use tui::task::EmptyProcessors;
use tui::ui::im::widget::{PanesState, TableState, TextViewState, Window};
use tui::ui::im::{Borders, Context, Show, Ui};
use tui::ui::span;
-
use tui::ui::Column;
+
use tui::ui::{Column, Spacing};
use tui::{Channel, Exit};

use crate::git::HunkState;
@@ -342,7 +342,12 @@ impl App<'_> {
            Layout::vertical([Constraint::Length(3), Constraint::Min(1)]),
            Some(1),
            |ui| {
-
                ui.column_bar(frame, header.to_vec(), Some(Borders::Top));
+
                ui.column_bar(
+
                    frame,
+
                    header.to_vec(),
+
                    Spacing::default(),
+
                    Some(Borders::Top),
+
                );

                let table = ui.table(
                    frame,
@@ -375,7 +380,12 @@ impl App<'_> {
                .unwrap_or_default();

            ui.container(layout::container(), 1, |ui| {
-
                ui.column_bar(frame, hunk.inner().header(), Some(Borders::Top));
+
                ui.column_bar(
+
                    frame,
+
                    hunk.inner().header(),
+
                    Spacing::from(0),
+
                    Some(Borders::Top),
+
                );

                if let Some(text) = hunk.inner().hunk_text() {
                    let diff = ui.text_view(frame, text, &mut cursor, Some(Borders::BottomSides));
@@ -458,6 +468,7 @@ impl App<'_> {
                ),
            ]
            .to_vec(),
+
            Spacing::from(0),
            Some(Borders::None),
        );
    }
@@ -541,7 +552,7 @@ impl Show<Message> for App<'_> {
                            };
                            let header = [Column::new(" Help ", Constraint::Fill(1))].to_vec();

-
                            ui.column_bar(frame, header, Some(Borders::Top));
+
                            ui.column_bar(frame, header, Spacing::from(0), Some(Borders::Top));
                            let help = ui.text_view(
                                frame,
                                help_text().to_string(),
modified bin/ui/im.rs
@@ -1,3 +1,4 @@
+
use radicle_tui::ui::Spacing;
use termion::event::Key;

use ratatui::layout::{Constraint, Layout};
@@ -124,7 +125,12 @@ where
            ]),
            Some(1),
            |ui| {
-
                ui.column_bar(frame, self.header.clone().to_vec(), Some(Borders::Top));
+
                ui.column_bar(
+
                    frame,
+
                    self.header.clone().to_vec(),
+
                    Spacing::default(),
+
                    Some(Borders::Top),
+
                );

                let table = ui.table(
                    frame,
@@ -151,7 +157,12 @@ where
                    self.search.write(TextEditState { text, cursor });
                    response.changed |= text_edit.changed;
                } else {
-
                    ui.column_bar(frame, self.footer.clone().to_vec(), Some(Borders::Bottom));
+
                    ui.column_bar(
+
                        frame,
+
                        self.footer.clone().to_vec(),
+
                        Spacing::from(0),
+
                        Some(Borders::Bottom),
+
                    );
                }
            },
        );
modified examples/selection.rs
@@ -2,6 +2,7 @@ use std::time::{SystemTime, UNIX_EPOCH};

use anyhow::Result;

+
use radicle_tui::ui::Spacing;
use termion::event::Key;

use ratatui::layout::{Constraint, Layout};
@@ -96,7 +97,12 @@ impl Show<Message> for App {
                    .to_vec();
                    let mut selected = self.selector.selected();

-
                    ui.column_bar(frame, columns.clone(), Some(Borders::None));
+
                    ui.column_bar(
+
                        frame,
+
                        columns.clone(),
+
                        Spacing::default(),
+
                        Some(Borders::None),
+
                    );

                    let table = ui.table(
                        frame,
modified src/ui.rs
@@ -95,6 +95,26 @@ impl<'a> Column<'a> {
    }
}

+
pub struct Spacing(u16);
+

+
impl From<u16> for Spacing {
+
    fn from(value: u16) -> Self {
+
        Self(value)
+
    }
+
}
+

+
impl Default for Spacing {
+
    fn default() -> Self {
+
        Self(0)
+
    }
+
}
+

+
impl From<Spacing> for u16 {
+
    fn from(spacing: Spacing) -> Self {
+
        spacing.0
+
    }
+
}
+

/// Needs to be implemented for items that are supposed to be rendered in tables.
pub trait ToRow<const W: usize> {
    fn to_row(&self) -> [Cell; W];
modified src/ui/im.rs
@@ -21,7 +21,7 @@ use crate::event::Event;
use crate::store::Update;
use crate::terminal::Terminal;
use crate::ui::theme::Theme;
-
use crate::ui::{Column, ToRow};
+
use crate::ui::{Column, Spacing, ToRow};
use crate::Interrupted;

use crate::ui::im::widget::Widget;
@@ -574,9 +574,10 @@ where
        &mut self,
        frame: &mut Frame,
        columns: Vec<Column<'_>>,
+
        spacing: Spacing,
        borders: Option<Borders>,
    ) -> Response {
-
        widget::ColumnBar::new(columns, borders).ui(self, frame)
+
        widget::ColumnBar::new(columns, spacing, borders).ui(self, frame)
    }

    pub fn text_view<'a>(
modified src/ui/im/widget.rs
@@ -11,7 +11,7 @@ use termion::event::Key;

use crate::ui::ext::{FooterBlock, FooterBlockType, HeaderBlock};
use crate::ui::theme::style;
-
use crate::ui::{layout, span};
+
use crate::ui::{layout, span, Spacing};
use crate::ui::{Column, ToRow};

use super::{Borders, Context, InnerResponse, Response, Ui};
@@ -533,12 +533,17 @@ where

pub struct ColumnBar<'a> {
    columns: Vec<Column<'a>>,
+
    spacing: Spacing,
    borders: Option<Borders>,
}

impl<'a> ColumnBar<'a> {
-
    pub fn new(columns: Vec<Column<'a>>, borders: Option<Borders>) -> Self {
-
        Self { columns, borders }
+
    pub fn new(columns: Vec<Column<'a>>, spacing: Spacing, borders: Option<Borders>) -> Self {
+
        Self {
+
            columns,
+
            spacing,
+
            borders,
+
        }
    }
}

@@ -581,7 +586,7 @@ impl Widget for ColumnBar<'_> {
            .collect::<Vec<_>>();

        let table = ratatui::widgets::Table::default()
-
            .column_spacing(1)
+
            .column_spacing(self.spacing.into())
            .rows([Row::new(cells)])
            .widths(widths);
        frame.render_widget(table, area);