Make the backlog its own component

This commit is contained in:
2023-11-02 16:09:57 +01:00
parent c837f471e5
commit fd649a1ed9
3 changed files with 64 additions and 8 deletions

View File

@ -12,6 +12,8 @@ mod fps;
pub use fps::FpsCounter;
mod 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.
/// 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
View 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(())
}
}

View File

@ -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 color_eyre::eyre::{Result, WrapErr};
@ -8,7 +24,7 @@ use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::OnceCell;
use tui_textarea::{Input, Key, TextArea};
use super::{Buflist, Component};
use super::{Backlog, Buflist, Component};
use crate::{
action::Action,
config::{Config, KeyBindings},
@ -19,6 +35,7 @@ pub struct Home {
command_tx: Option<UnboundedSender<Action>>,
config: OnceCell<Config>,
buflist: Buflist,
backlog: Backlog,
textarea: TextArea<'static>,
}
@ -121,15 +138,13 @@ impl Component for Home {
])
.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]);
self
.backlog
.draw(frame, layout[0], buffers)
.context("Error drawing backlog")?;
Ok(())
}
}