Restructure and prepare for cove room UI
This commit is contained in:
parent
619e04c42a
commit
e81900caac
4 changed files with 20 additions and 14 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
mod cove;
|
||||||
mod input;
|
mod input;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod overlays;
|
mod overlays;
|
||||||
|
|
@ -18,10 +19,9 @@ use tui::layout::{Constraint, Direction, Layout, Rect};
|
||||||
use tui::{Frame, Terminal};
|
use tui::{Frame, Terminal};
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::cove;
|
|
||||||
use crate::cove::room::CoveRoom;
|
|
||||||
use crate::ui::overlays::OverlayReaction;
|
use crate::ui::overlays::OverlayReaction;
|
||||||
|
|
||||||
|
use self::cove::CoveUi;
|
||||||
use self::input::EventHandler;
|
use self::input::EventHandler;
|
||||||
use self::overlays::{Overlay, SwitchRoom, SwitchRoomState};
|
use self::overlays::{Overlay, SwitchRoom, SwitchRoomState};
|
||||||
use self::pane::PaneInfo;
|
use self::pane::PaneInfo;
|
||||||
|
|
@ -35,8 +35,8 @@ pub enum UiEvent {
|
||||||
Redraw,
|
Redraw,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<cove::conn::Event> for UiEvent {
|
impl From<crate::cove::conn::Event> for UiEvent {
|
||||||
fn from(_: cove::conn::Event) -> Self {
|
fn from(_: crate::cove::conn::Event) -> Self {
|
||||||
Self::Redraw
|
Self::Redraw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +49,8 @@ enum EventHandleResult {
|
||||||
pub struct Ui {
|
pub struct Ui {
|
||||||
config: &'static Config,
|
config: &'static Config,
|
||||||
event_tx: UnboundedSender<UiEvent>,
|
event_tx: UnboundedSender<UiEvent>,
|
||||||
cove_rooms: HashMap<String, CoveRoom>,
|
|
||||||
|
cove_rooms: HashMap<String, CoveUi>,
|
||||||
|
|
||||||
rooms_pane: PaneInfo,
|
rooms_pane: PaneInfo,
|
||||||
users_pane: PaneInfo,
|
users_pane: PaneInfo,
|
||||||
|
|
|
||||||
7
cove-tui/src/ui/cove.rs
Normal file
7
cove-tui/src/ui/cove.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
mod users;
|
||||||
|
|
||||||
|
use crate::cove::room::CoveRoom;
|
||||||
|
|
||||||
|
pub struct CoveUi {
|
||||||
|
room: CoveRoom,
|
||||||
|
}
|
||||||
|
|
@ -18,18 +18,18 @@ struct UserInfo {
|
||||||
|
|
||||||
impl From<&Session> for UserInfo {
|
impl From<&Session> for UserInfo {
|
||||||
fn from(s: &Session) -> Self {
|
fn from(s: &Session) -> Self {
|
||||||
UserInfo {
|
Self {
|
||||||
nick: s.nick.clone(),
|
nick: s.nick.clone(),
|
||||||
identity: s.identity,
|
identity: s.identity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Users {
|
pub struct CoveUsers {
|
||||||
users: Vec<UserInfo>,
|
users: Vec<UserInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Users {
|
impl CoveUsers {
|
||||||
pub fn new(present: &Present) -> Self {
|
pub fn new(present: &Present) -> Self {
|
||||||
let mut users: Vec<UserInfo> = iter::once(&present.session)
|
let mut users: Vec<UserInfo> = iter::once(&present.session)
|
||||||
.chain(present.others.values())
|
.chain(present.others.values())
|
||||||
|
|
@ -40,7 +40,7 @@ impl Users {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for Users {
|
impl Widget for CoveUsers {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let sessions = self.users.len();
|
let sessions = self.users.len();
|
||||||
let identities = self
|
let identities = self
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use tui::buffer::Buffer;
|
use tui::buffer::Buffer;
|
||||||
use tui::layout::Rect;
|
use tui::layout::Rect;
|
||||||
use tui::text::{Span, Spans};
|
use tui::text::{Span, Spans};
|
||||||
use tui::widgets::{Paragraph, Widget};
|
use tui::widgets::{Paragraph, Widget};
|
||||||
|
|
||||||
use crate::cove::room::CoveRoom;
|
use super::cove::CoveUi;
|
||||||
|
|
||||||
use super::styles;
|
use super::styles;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
|
@ -21,10 +19,10 @@ pub struct Rooms {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rooms {
|
impl Rooms {
|
||||||
pub fn new(cove_rooms: &HashMap<String, CoveRoom>) -> Self {
|
pub fn new(cove_rooms: &HashMap<String, CoveUi>) -> Self {
|
||||||
let mut rooms = cove_rooms
|
let mut rooms = cove_rooms
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(name, _room)| RoomInfo { name: name.clone() })
|
.map(|(name, _)| RoomInfo { name: name.clone() })
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
rooms.sort();
|
rooms.sort();
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue