Skip to content

Commit

Permalink
Merge b21ab6c into 6f12e2f
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Mar 5, 2024
2 parents 6f12e2f + b21ab6c commit e88148c
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 14 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ratatui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: ratatui

on: [push, pull_request]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-fail-fast
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-fail-fast --no-default-features --features ratatui,crossterm
- name: Examples
run: cargo build --all-targets --examples
- name: Format
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --lib -- -Dwarnings
2 changes: 1 addition & 1 deletion .github/workflows/build.yml → .github/workflows/tui.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: tui

on: [push, pull_request]

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@
<p align="center">
<a href="https://github.com/veeso/tui-realm-stdlib/actions"
><img
src="https://github.com/veeso/tui-realm-stdlib/workflows/Build/badge.svg"
alt="CI"
src="https://github.com/veeso/tui-realm-stdlib/workflows/tui/badge.svg"
alt="tui ci"
/></a>
<a href="https://github.com/veeso/tui-realm-stdlib/actions"
><img
src="https://github.com/veeso/tui-realm-stdlib/workflows/ratatui/badge.svg"
alt="ratatui ci"
/></a>
<a href="https://docs.rs/tui-realm-stdlib"
><img
Expand Down
8 changes: 5 additions & 3 deletions src/components/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use tuirealm::{Frame, MockComponent, State};

// -- Props
use super::props::{
CANVAS_MARKER, CANVAS_MARKER_BAR, CANVAS_MARKER_BLOCK, CANVAS_MARKER_BRAILLE,
CANVAS_MARKER_DOT, CANVAS_X_BOUNDS, CANVAS_Y_BOUNDS,
CANVAS_MARKER, CANVAS_MARKER_BLOCK, CANVAS_MARKER_BRAILLE, CANVAS_MARKER_DOT, CANVAS_X_BOUNDS,
CANVAS_Y_BOUNDS,
};

// -- Component
Expand Down Expand Up @@ -114,7 +114,9 @@ impl Canvas {
fn marker_to_prop(marker: Marker) -> AttrValue {
AttrValue::Number(match marker {
#[cfg(feature = "ratatui")]
Marker::Bar => CANVAS_MARKER_BAR,
Marker::HalfBlock => crate::props::CANVAS_MARKER_HALF_BLOCK,
#[cfg(feature = "ratatui")]
Marker::Bar => crate::props::CANVAS_MARKER_BAR,
Marker::Block => CANVAS_MARKER_BLOCK,
Marker::Braille => CANVAS_MARKER_BRAILLE,
Marker::Dot => CANVAS_MARKER_DOT,
Expand Down
10 changes: 8 additions & 2 deletions src/components/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tuirealm::tui::text::Line as Spans;
#[cfg(feature = "tui")]
use tuirealm::tui::text::Spans;
use tuirealm::tui::{
layout::{Corner, Rect},
layout::Rect,
text::Span,
widgets::{List as TuiList, ListItem, ListState},
};
Expand Down Expand Up @@ -289,10 +289,16 @@ impl MockComponent for List {
false => modifiers,
};
// Make list
#[cfg(feature = "tui")]
let mut list = TuiList::new(list_items)
.block(div)
.style(Style::default().fg(foreground).bg(background))
.start_corner(Corner::TopLeft);
.start_corner(tuirealm::tui::layout::Corner::TopLeft);
#[cfg(feature = "ratatui")]
let mut list = TuiList::new(list_items)
.block(div)
.style(Style::default().fg(foreground).bg(background))
.direction(tuirealm::tui::widgets::ListDirection::TopToBottom);
if let Some(highlighted_color) = highlighted_color {
list = list.highlight_style(
Style::default()
Expand Down
2 changes: 2 additions & 0 deletions src/components/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub const CANVAS_MARKER_DOT: isize = 1;
pub const CANVAS_MARKER_BLOCK: isize = 2;
#[cfg(feature = "ratatui")]
pub const CANVAS_MARKER_BAR: isize = 3;
#[cfg(feature = "ratatui")]
pub const CANVAS_MARKER_HALF_BLOCK: isize = 4;

// -- chart

Expand Down
24 changes: 22 additions & 2 deletions src/components/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tuirealm::tui::text::Line as Spans;
#[cfg(feature = "tui")]
use tuirealm::tui::text::Spans;
use tuirealm::tui::{
layout::{Constraint, Corner, Direction as LayoutDirection, Layout, Rect},
layout::{Constraint, Direction as LayoutDirection, Layout, Rect},
widgets::{Block, List, ListItem, ListState, Paragraph},
};
use tuirealm::{Frame, MockComponent, State, StateValue};
Expand Down Expand Up @@ -255,6 +255,7 @@ impl Select {
render.render_widget(p, chunks[0]);
// Render the list of elements in chunks [1]
// Make list
#[cfg(feature = "tui")]
let mut list = List::new(choices)
.block(
Block::default()
Expand All @@ -266,7 +267,26 @@ impl Select {
.border_type(borders.modifiers)
.style(Style::default().bg(background)),
)
.start_corner(Corner::TopLeft)
.start_corner(tuirealm::tui::layout::Corner::TopLeft)
.style(Style::default().fg(foreground).bg(background))
.highlight_style(
Style::default()
.fg(hg)
.add_modifier(TextModifiers::REVERSED),
);
#[cfg(feature = "ratatui")]
let mut list = List::new(choices)
.block(
Block::default()
.borders(BorderSides::LEFT | BorderSides::BOTTOM | BorderSides::RIGHT)
.border_style(match focus {
true => borders.style(),
false => Style::default(),
})
.border_type(borders.modifiers)
.style(Style::default().bg(background)),
)
.direction(tuirealm::tui::widgets::ListDirection::TopToBottom)
.style(Style::default().fg(foreground).bg(background))
.highlight_style(
Style::default()
Expand Down
12 changes: 10 additions & 2 deletions src/components/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ impl MockComponent for Table {
.get(Attribute::HighlightedColor)
.map(|x| x.unwrap_color());
let widths: Vec<Constraint> = self.layout();
#[cfg(feature = "tui")]
let mut table = TuiTable::new(rows)
.block(crate::utils::get_block(
borders,
Expand All @@ -356,6 +357,13 @@ impl MockComponent for Table {
inactive_style,
))
.widths(&widths);
#[cfg(feature = "ratatui")]
let mut table = TuiTable::new(rows, &widths).block(crate::utils::get_block(
borders,
Some(title),
focus,
inactive_style,
));
if let Some(highlighted_color) = highlighted_color {
table = table.highlight_style(Style::default().fg(highlighted_color).add_modifier(
match focus {
Expand All @@ -370,7 +378,7 @@ impl MockComponent for Table {
.get(Attribute::HighlightedStr)
.map(|x| x.unwrap_string());
if let Some(hg_str) = &self.hg_str {
table = table.highlight_symbol(hg_str);
table = table.highlight_symbol(hg_str.as_str());
}
// Col spacing
if let Some(spacing) = self
Expand Down Expand Up @@ -686,7 +694,7 @@ mod tests {
#[test]
fn test_component_table_with_empty_rows_and_no_width_set() {
// Make component
let mut component = Table::default().table(TableBuilder::default().build());
let component = Table::default().table(TableBuilder::default().build());

assert_eq!(component.states.list_len, 1);
assert_eq!(component.states.list_index, 0);
Expand Down
20 changes: 18 additions & 2 deletions src/components/textarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tuirealm::props::{
TextModifiers, TextSpan,
};
use tuirealm::tui::{
layout::{Corner, Rect},
layout::Rect,
widgets::{List, ListItem, ListState},
};
use tuirealm::{Frame, MockComponent, State};
Expand Down Expand Up @@ -245,14 +245,30 @@ impl MockComponent for Textarea {
let mut state: ListState = ListState::default();
state.select(Some(self.states.list_index));
// Make component
#[cfg(feature = "tui")]
let mut list = List::new(lines)
.block(crate::utils::get_block(
borders,
Some(title),
focus,
inactive_style,
))
.start_corner(Corner::TopLeft)
.start_corner(tuirealm::tui::layout::Corner::TopLeft)
.style(
Style::default()
.fg(foreground)
.bg(background)
.add_modifier(modifiers),
);
#[cfg(feature = "ratatui")]
let mut list = List::new(lines)
.block(crate::utils::get_block(
borders,
Some(title),
focus,
inactive_style,
))
.direction(tuirealm::tui::widgets::ListDirection::TopToBottom)
.style(
Style::default()
.fg(foreground)
Expand Down

0 comments on commit e88148c

Please sign in to comment.