This commit is contained in:
2023-11-01 14:13:04 +01:00
parent 0f97aad2e8
commit 41bf892e74
7 changed files with 44 additions and 15 deletions

View File

@ -30,7 +30,7 @@ use crate::{
action::Action,
buffers::{Buffers, RoomBuffer},
commands::RataCommands,
components::{FpsCounter, Home, Component},
components::{Component, FpsCounter, Home},
config::Config,
mode::Mode,
tui,
@ -151,7 +151,10 @@ impl App {
for client in &self.clients {
for room in client.joined_rooms() {
self.buffers.push(Box::new(RoomBuffer::new(vec![client.clone()], room.room_id().to_owned())));
self.buffers.push(Box::new(RoomBuffer::new(
vec![client.clone()],
room.room_id().to_owned(),
)));
}
}

View File

@ -29,7 +29,7 @@ impl Buffers {
Self(Vec::new())
}
pub fn iter(&self) -> impl Iterator<Item=&dyn Buffer> {
pub fn iter(&self) -> impl Iterator<Item = &dyn Buffer> {
self.0.iter().map(|buffer_box| &**buffer_box)
}

View File

@ -14,9 +14,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use matrix_sdk::ruma::OwnedRoomId;
use matrix_sdk::Client;
use matrix_sdk::Room;
use matrix_sdk::ruma::OwnedRoomId;
use super::Buffer;

View File

@ -4,11 +4,7 @@ use ratatui::layout::Rect;
use ratatui::Frame;
use tokio::sync::mpsc::UnboundedSender;
use crate::{
action::Action,
config::Config,
tui::Event,
};
use crate::{action::Action, config::Config, tui::Event};
mod buflist;
pub use buflist::Buflist;
@ -126,5 +122,10 @@ pub trait Component {
/// # Returns
///
/// * `Result<()>` - An Ok result or an error.
fn draw(&mut self, f: &mut Frame<'_>, area: Rect, buffers: &crate::buffers::Buffers) -> Result<()>;
fn draw(
&mut self,
f: &mut Frame<'_>,
area: Rect,
buffers: &crate::buffers::Buffers,
) -> Result<()>;
}

View File

@ -57,9 +57,21 @@ impl Component for Buflist {
Ok(None)
}
fn draw(&mut self, frame: &mut Frame<'_>, area: Rect, buffers: &crate::buffers::Buffers) -> Result<()> {
fn draw(
&mut self,
frame: &mut Frame<'_>,
area: Rect,
buffers: &crate::buffers::Buffers,
) -> Result<()> {
frame.render_widget(
Paragraph::new(buffers.iter().map(|buf| buf.short_name()).collect::<Vec<_>>().join("\n")).block(Block::new().borders(Borders::ALL)),
Paragraph::new(
buffers
.iter()
.map(|buf| buf.short_name())
.collect::<Vec<_>>()
.join("\n"),
)
.block(Block::new().borders(Borders::ALL)),
area,
);

View File

@ -71,7 +71,12 @@ impl Component for FpsCounter {
Ok(None)
}
fn draw(&mut self, f: &mut Frame<'_>, rect: Rect, _buffers: &crate::buffers::Buffers) -> Result<()> {
fn draw(
&mut self,
f: &mut Frame<'_>,
rect: Rect,
_buffers: &crate::buffers::Buffers,
) -> Result<()> {
let rects = Layout::default()
.direction(Direction::Vertical)
.constraints(vec![

View File

@ -51,13 +51,21 @@ impl Component for Home {
Ok(None)
}
fn draw(&mut self, frame: &mut Frame<'_>, area: Rect, buffers: &crate::buffers::Buffers) -> Result<()> {
fn draw(
&mut self,
frame: &mut Frame<'_>,
area: Rect,
buffers: &crate::buffers::Buffers,
) -> Result<()> {
let layout = Layout::default()
.direction(Direction::Horizontal)
.constraints(vec![Constraint::Percentage(20), Constraint::Percentage(80)])
.split(area);
self.buflist.draw(frame, layout[0], buffers).context("Error drawing buflist")?;
self
.buflist
.draw(frame, layout[0], buffers)
.context("Error drawing buflist")?;
frame.render_widget(
Paragraph::new("buffer goes here").block(Block::new().borders(Borders::ALL)),
layout[1],