Make the backlog its own component
This commit is contained in:
@ -12,6 +12,8 @@ mod fps;
|
|||||||
pub use fps::FpsCounter;
|
pub use fps::FpsCounter;
|
||||||
mod home;
|
mod home;
|
||||||
pub use home::Home;
|
pub use home::Home;
|
||||||
|
mod backlog;
|
||||||
|
pub use backlog::Backlog;
|
||||||
|
|
||||||
/// `Component` is a trait that represents a visual and interactive element of the user interface.
|
/// `Component` is a trait that represents a visual and interactive element of the user interface.
|
||||||
/// Implementors of this trait can be registered with the main application loop and will be able to receive events,
|
/// Implementors of this trait can be registered with the main application loop and will be able to receive events,
|
||||||
|
39
src/components/backlog.rs
Normal file
39
src/components/backlog.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Valentin Lorentz
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License version 3,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use super::Component;
|
||||||
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
|
use ratatui::{prelude::*, widgets::*};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct Backlog {}
|
||||||
|
|
||||||
|
impl Component for Backlog {
|
||||||
|
fn draw(
|
||||||
|
&mut self,
|
||||||
|
frame: &mut Frame<'_>,
|
||||||
|
area: Rect,
|
||||||
|
buffers: &crate::buffers::Buffers,
|
||||||
|
) -> Result<()> {
|
||||||
|
frame.render_widget(
|
||||||
|
Paragraph::new(buffers.active_buffer().content())
|
||||||
|
.block(Block::new().borders(Borders::ALL))
|
||||||
|
.wrap(Wrap { trim: true }),
|
||||||
|
area,
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Valentin Lorentz
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License version 3,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
use std::{collections::HashMap, time::Duration};
|
use std::{collections::HashMap, time::Duration};
|
||||||
|
|
||||||
use color_eyre::eyre::{Result, WrapErr};
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
@ -8,7 +24,7 @@ use tokio::sync::mpsc::UnboundedSender;
|
|||||||
use tokio::sync::OnceCell;
|
use tokio::sync::OnceCell;
|
||||||
use tui_textarea::{Input, Key, TextArea};
|
use tui_textarea::{Input, Key, TextArea};
|
||||||
|
|
||||||
use super::{Buflist, Component};
|
use super::{Backlog, Buflist, Component};
|
||||||
use crate::{
|
use crate::{
|
||||||
action::Action,
|
action::Action,
|
||||||
config::{Config, KeyBindings},
|
config::{Config, KeyBindings},
|
||||||
@ -19,6 +35,7 @@ pub struct Home {
|
|||||||
command_tx: Option<UnboundedSender<Action>>,
|
command_tx: Option<UnboundedSender<Action>>,
|
||||||
config: OnceCell<Config>,
|
config: OnceCell<Config>,
|
||||||
buflist: Buflist,
|
buflist: Buflist,
|
||||||
|
backlog: Backlog,
|
||||||
textarea: TextArea<'static>,
|
textarea: TextArea<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,15 +138,13 @@ impl Component for Home {
|
|||||||
])
|
])
|
||||||
.split(layout[1]);
|
.split(layout[1]);
|
||||||
|
|
||||||
frame.render_widget(
|
|
||||||
Paragraph::new(buffers.active_buffer().content())
|
|
||||||
.block(Block::new().borders(Borders::ALL))
|
|
||||||
.wrap(Wrap { trim: true }),
|
|
||||||
layout[0],
|
|
||||||
);
|
|
||||||
|
|
||||||
frame.render_widget(self.textarea.widget(), layout[1]);
|
frame.render_widget(self.textarea.widget(), layout[1]);
|
||||||
|
|
||||||
|
self
|
||||||
|
.backlog
|
||||||
|
.draw(frame, layout[0], buffers)
|
||||||
|
.context("Error drawing backlog")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user