aboutsummaryrefslogtreecommitdiffstats
path: root/src/input.rs
diff options
context:
space:
mode:
authorKunal Mohan <44079328+kunalmohan@users.noreply.github.com>2020-12-09 22:31:26 +0530
committerGitHub <noreply@github.com>2020-12-09 18:01:26 +0100
commit92d1bcff4c0d1d886cefee6984d5533c5ea8dd6f (patch)
tree2ef85153a55e61f1d97e03dfa608ac853fe22887 /src/input.rs
parentfix(style): else-if ladder -> match (#86) (diff)
downloadsl0ppij-92d1bcff4c0d1d886cefee6984d5533c5ea8dd6f.tar.gz
sl0ppij-92d1bcff4c0d1d886cefee6984d5533c5ea8dd6f.tar.xz
sl0ppij-92d1bcff4c0d1d886cefee6984d5533c5ea8dd6f.zip
feat(infrastructure): introduce ErrorContext for tracking errors across threads (#83)
* Implement ErrorContext for tracking errors across threads * reorder Instruction and ErrorContext * Add ContextType, AppContext, ScreenContext, PtyContext * Use ArrayVec in ErrorContext * increase MAX_THREAD_CALL_STACK to 6 * Custom implement Debug for ErrorContext ad ContextType and color output * Use os_input instead of println!() * Use array instead of ArrayVec and some cleanup * Introduce SenderWithContext * Keep arrayvec at v0.5.1
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/input.rs b/src/input.rs
index ea2c4d41..6d82f4f9 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -1,28 +1,27 @@
/// Module for handling input
-use std::sync::mpsc::{Sender, SyncSender};
-
+use crate::errors::ContextType;
use crate::os_input_output::OsApi;
use crate::pty_bus::PtyInstruction;
use crate::screen::ScreenInstruction;
-use crate::AppInstruction;
use crate::CommandIsExecuting;
+use crate::{AppInstruction, SenderWithContext, OPENCALLS};
struct InputHandler {
mode: InputMode,
os_input: Box<dyn OsApi>,
command_is_executing: CommandIsExecuting,
- send_screen_instructions: Sender<ScreenInstruction>,
- send_pty_instructions: Sender<PtyInstruction>,
- send_app_instructions: SyncSender<AppInstruction>,
+ send_screen_instructions: SenderWithContext<ScreenInstruction>,
+ send_pty_instructions: SenderWithContext<PtyInstruction>,
+ send_app_instructions: SenderWithContext<AppInstruction>,
}
impl InputHandler {
fn new(
os_input: Box<dyn OsApi>,
command_is_executing: CommandIsExecuting,
- send_screen_instructions: Sender<ScreenInstruction>,
- send_pty_instructions: Sender<PtyInstruction>,
- send_app_instructions: SyncSender<AppInstruction>,
+ send_screen_instructions: SenderWithContext<ScreenInstruction>,
+ send_pty_instructions: SenderWithContext<PtyInstruction>,
+ send_app_instructions: SenderWithContext<AppInstruction>,
) -> Self {
InputHandler {
mode: InputMode::Normal,
@@ -36,6 +35,11 @@ impl InputHandler {
/// Main event loop
fn get_input(&mut self) {
+ let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());
+ err_ctx.add_call(ContextType::StdinHandler);
+ self.send_pty_instructions.update(err_ctx);
+ self.send_app_instructions.update(err_ctx);
+ self.send_screen_instructions.update(err_ctx);
loop {
match self.mode {
InputMode::Normal => self.read_normal_mode(),
@@ -263,9 +267,9 @@ pub enum InputMode {
pub fn input_loop(
os_input: Box<dyn OsApi>,
command_is_executing: CommandIsExecuting,
- send_screen_instructions: Sender<ScreenInstruction>,
- send_pty_instructions: Sender<PtyInstruction>,
- send_app_instructions: SyncSender<AppInstruction>,
+ send_screen_instructions: SenderWithContext<ScreenInstruction>,
+ send_pty_instructions: SenderWithContext<PtyInstruction>,
+ send_app_instructions: SenderWithContext<AppInstruction>,
) {
let _handler = InputHandler::new(
os_input,