Connect to new rooms
This commit is contained in:
parent
05ac42ab78
commit
3e9ceba302
4 changed files with 52 additions and 13 deletions
|
|
@ -1,6 +1,8 @@
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use parking_lot::FairMutex;
|
||||
use tokio::sync::mpsc;
|
||||
use toss::frame::{Frame, Pos, Size};
|
||||
use toss::terminal::Terminal;
|
||||
|
|
@ -9,7 +11,7 @@ use crate::chat::Chat;
|
|||
use crate::euph;
|
||||
use crate::vault::{EuphMsg, EuphVault, Vault};
|
||||
|
||||
use super::UiEvent;
|
||||
use super::{util, UiEvent};
|
||||
|
||||
mod style {
|
||||
use crossterm::style::{ContentStyle, Stylize};
|
||||
|
|
@ -159,6 +161,7 @@ impl Rooms {
|
|||
terminal: &mut Terminal,
|
||||
size: Size,
|
||||
ui_event_tx: &mpsc::UnboundedSender<UiEvent>,
|
||||
crossterm_lock: &Arc<FairMutex<()>>,
|
||||
event: KeyEvent,
|
||||
) {
|
||||
if let Some(focus) = &self.focus {
|
||||
|
|
@ -203,6 +206,18 @@ impl Rooms {
|
|||
}
|
||||
}
|
||||
}
|
||||
KeyCode::Char('C') => {
|
||||
if let Some(room) = util::prompt(terminal, crossterm_lock) {
|
||||
let room = room.trim().to_string();
|
||||
self.euph_rooms.entry(room.clone()).or_insert_with(|| {
|
||||
euph::Room::new(
|
||||
room.clone(),
|
||||
self.vault.euph(room),
|
||||
ui_event_tx.clone(),
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
KeyCode::Char('d') => {
|
||||
if let Some(cursor) = &self.cursor {
|
||||
if let Some(room) = rooms.get(cursor.index) {
|
||||
|
|
|
|||
20
src/ui/util.rs
Normal file
20
src/ui/util.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use parking_lot::FairMutex;
|
||||
use toss::terminal::Terminal;
|
||||
|
||||
pub fn prompt(terminal: &mut Terminal, crossterm_lock: &Arc<FairMutex<()>>) -> Option<String> {
|
||||
let content = {
|
||||
let _guard = crossterm_lock.lock();
|
||||
terminal.suspend().expect("could not suspend");
|
||||
let content = edit::edit("").expect("could not edit");
|
||||
terminal.unsuspend().expect("could not unsuspend");
|
||||
content
|
||||
};
|
||||
|
||||
if content.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(content)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue