meli/ui/src/types.rs

136 lines
3.2 KiB
Rust
Raw Normal View History

2018-08-07 15:01:15 +03:00
/*
* meli - ui crate.
*
* Copyright 2017-2018 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
extern crate serde;
2018-08-08 11:50:51 +03:00
#[macro_use]
2018-08-06 16:53:23 +03:00
mod helpers;
pub use self::helpers::*;
use super::execute::Action;
2019-03-12 20:35:23 +02:00
use super::terminal::*;
2018-08-06 16:53:23 +03:00
use melib::RefreshEvent;
use std;
use std::fmt;
2018-08-07 15:01:15 +03:00
use std::thread;
use uuid::Uuid;
2018-08-06 16:53:23 +03:00
2018-08-26 19:29:12 +03:00
#[derive(Debug)]
pub enum StatusEvent {
DisplayMessage(String),
BufClear,
BufSet(String),
}
2018-08-06 16:53:23 +03:00
/// `ThreadEvent` encapsulates all of the possible values we need to transfer between our threads
/// to the main process.
#[derive(Debug)]
pub enum ThreadEvent {
ThreadJoin(thread::ThreadId),
/// User input.
Input(Key),
/// A watched folder has been refreshed.
RefreshMailbox(Box<RefreshEvent>),
2018-08-06 16:53:23 +03:00
UIEvent(UIEventType),
//Decode { _ }, // For gpg2 signature check
}
impl From<RefreshEvent> for ThreadEvent {
fn from(event: RefreshEvent) -> Self {
ThreadEvent::RefreshMailbox(Box::new(event))
2018-08-06 16:53:23 +03:00
}
}
#[derive(Debug)]
pub enum ForkType {
Finished, // Already finished fork, we only want to restore input/output
2018-08-06 16:53:23 +03:00
Generic(std::process::Child),
NewDraft(File, std::process::Child),
}
#[derive(Debug)]
pub enum UIEventType {
Input(Key),
ExInput(Key),
InsertInput(Key),
2018-08-06 16:53:23 +03:00
RefreshMailbox((usize, usize)),
//Quit?
Resize,
/// Force redraw.
Fork(ForkType),
ChangeMailbox(usize),
ChangeMode(UIMode),
Command(String),
2018-09-05 16:08:11 +03:00
Notification(Option<String>, String),
2018-08-06 16:53:23 +03:00
Action(Action),
2018-08-26 19:29:12 +03:00
StatusEvent(StatusEvent),
MailboxUpdate((usize, usize)), // (account_idx, mailbox_idx)
EntityKill(Uuid),
2018-08-06 16:53:23 +03:00
StartupCheck,
RefreshEvent(Box<RefreshEvent>),
}
impl From<RefreshEvent> for UIEvent {
fn from(event: RefreshEvent) -> Self {
UIEvent {
id: 0,
event_type: UIEventType::RefreshEvent(Box::new(event)),
}
}
2018-08-06 16:53:23 +03:00
}
/// An event passed from `State` to its Entities.
#[derive(Debug)]
pub struct UIEvent {
pub id: u64,
pub event_type: UIEventType,
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum UIMode {
Normal,
Insert,
2018-08-06 16:53:23 +03:00
Execute,
Fork,
}
impl fmt::Display for UIMode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match *self {
UIMode::Normal => "NORMAL",
UIMode::Insert => "INSERT",
2018-08-06 16:53:23 +03:00
UIMode::Execute => "EX",
UIMode::Fork => "FORK",
}
)
}
}
/// An event notification that is passed to Entities for handling.
pub struct Notification {
_title: String,
_content: String,
_timestamp: std::time::Instant,
}