Compose messages via external editor

This commit is contained in:
Joscha 2022-06-17 20:50:12 +02:00
parent 9a351b5eb3
commit 36e1dbfa59
6 changed files with 236 additions and 17 deletions

View file

@ -1,3 +1,4 @@
mod action;
mod blocks;
mod cursor;
mod layout;
@ -5,13 +6,16 @@ mod render;
mod util;
use std::marker::PhantomData;
use std::sync::Arc;
use crossterm::event::{KeyCode, KeyEvent};
use parking_lot::FairMutex;
use toss::frame::{Frame, Pos, Size};
use toss::terminal::Terminal;
use crate::store::{Msg, MsgStore};
use super::Cursor;
use super::{Cursor, Handled};
pub struct TreeView<M: Msg> {
// pub focus: Option<M::Id>,
@ -29,23 +33,31 @@ impl<M: Msg> TreeView<M> {
pub async fn handle_key_event<S: MsgStore<M>>(
&mut self,
l: &Arc<FairMutex<()>>,
s: &mut S,
c: &mut Option<Cursor<M::Id>>,
f: &mut Frame,
t: &mut Terminal,
z: Size,
event: KeyEvent,
) {
) -> Handled<M::Id> {
match event.code {
KeyCode::Char('z') | KeyCode::Char('Z') => self.center_cursor(s, c, f, z).await,
KeyCode::Char('k') => self.move_up(s, c, f, z).await,
KeyCode::Char('j') => self.move_down(s, c, f, z).await,
KeyCode::Char('K') => self.move_up_sibling(s, c, f, z).await,
KeyCode::Char('J') => self.move_down_sibling(s, c, f, z).await,
KeyCode::Char('g') => self.move_to_first(s, c, f, z).await,
KeyCode::Char('G') => self.move_to_last(s, c, f, z).await,
// Cursor movement
KeyCode::Char('k') => self.move_up(s, c, t.frame(), z).await,
KeyCode::Char('j') => self.move_down(s, c, t.frame(), z).await,
KeyCode::Char('K') => self.move_up_sibling(s, c, t.frame(), z).await,
KeyCode::Char('J') => self.move_down_sibling(s, c, t.frame(), z).await,
KeyCode::Char('z') | KeyCode::Char('Z') => self.center_cursor(s, c, t.frame(), z).await,
KeyCode::Char('g') => self.move_to_first(s, c, t.frame(), z).await,
KeyCode::Char('G') => self.move_to_last(s, c, t.frame(), z).await,
KeyCode::Esc => *c = None, // TODO Make 'G' do the same thing?
// Writing messages
KeyCode::Char('r') => return Self::reply_normal(l, s, c, t).await,
KeyCode::Char('R') => return Self::reply_alternate(l, s, c, t).await,
KeyCode::Char('t') | KeyCode::Char('T') => return Self::create_new_thread(l, t).await,
_ => {}
}
Handled::Ok
}
pub async fn render<S: MsgStore<M>>(