TUI #1
@ -199,10 +199,7 @@ impl<'a> Widget for &mut App<'a> {
|
||||
self.draw_tabs(editor_layout[0], buf);
|
||||
let id = App::id().to_string();
|
||||
self.editor.render(editor_layout[1], buf);
|
||||
self.explorer
|
||||
.render(horizontal[0], buf)
|
||||
.context("Failed to render Explorer")
|
||||
.unwrap_or_else(|e| error!(target:id.as_str(), "{}", e));
|
||||
self.explorer.render(horizontal[0], buf);
|
||||
self.logger.render(vertical[2], buf);
|
||||
|
||||
// The title bar is rendered last to overlay any popups created for drop-down menus.
|
||||
|
||||
@ -5,7 +5,7 @@ use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEvent
|
||||
use ratatui::layout::{Alignment, Position, Rect};
|
||||
use ratatui::prelude::Style;
|
||||
use ratatui::style::{Color, Modifier};
|
||||
use ratatui::widgets::{Block, Borders, StatefulWidget};
|
||||
use ratatui::widgets::{Block, Borders, StatefulWidget, Widget};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
||||
@ -82,36 +82,6 @@ impl<'a> Explorer<'a> {
|
||||
.context("Failed to build tree from path.")
|
||||
}
|
||||
|
||||
pub fn render(&mut self, area: Rect, buf: &mut Buffer) -> Result<()> {
|
||||
StatefulWidget::render(
|
||||
Tree::new(&self.tree_items.children())
|
||||
.context("Failed to build file Explorer Tree.")?
|
||||
.style(Style::default())
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(
|
||||
self.root_path
|
||||
.file_name()
|
||||
.context("Failed to get file name from path.")?
|
||||
.to_string_lossy(),
|
||||
)
|
||||
.title_style(Style::default().fg(Color::Green))
|
||||
.title_alignment(Alignment::Center),
|
||||
)
|
||||
.highlight_style(
|
||||
Style::new()
|
||||
.fg(Color::Black)
|
||||
.bg(Color::Rgb(57, 59, 64))
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
area,
|
||||
buf,
|
||||
&mut self.tree_state,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn selected(&self) -> Result<String> {
|
||||
if let Some(path) = self.tree_state.selected().last() {
|
||||
return Ok(std::path::absolute(path)?
|
||||
@ -123,6 +93,33 @@ impl<'a> Explorer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Widget for &mut Explorer<'a> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
if let Ok(tree) = Tree::new(&self.tree_items.children()) {
|
||||
let file_name = self.root_path.file_name().unwrap_or("Unknown".as_ref());
|
||||
StatefulWidget::render(
|
||||
tree.style(Style::default())
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(file_name.to_string_lossy())
|
||||
.title_style(Style::default().fg(Color::Green))
|
||||
.title_alignment(Alignment::Center),
|
||||
)
|
||||
.highlight_style(
|
||||
Style::new()
|
||||
.fg(Color::Black)
|
||||
.bg(Color::Rgb(57, 59, 64))
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
area,
|
||||
buf,
|
||||
&mut self.tree_state,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Component for Explorer<'a> {
|
||||
fn handle_event(&mut self, event: Event) -> Result<Action> {
|
||||
if let Some(key_event) = event.as_key_event() {
|
||||
|
||||
@ -144,8 +144,10 @@ impl MenuBar {
|
||||
height,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self, area: Rect, buf: &mut Buffer)
|
||||
impl Widget for &mut MenuBar {
|
||||
fn render(self, area: Rect, buf: &mut Buffer)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user