mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Added terminal to Context
This commit is contained in:
@@ -24,10 +24,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
|
extern crate crossterm;
|
||||||
|
extern crate tui;
|
||||||
|
|
||||||
|
// Locals
|
||||||
use super::input::InputHandler;
|
use super::input::InputHandler;
|
||||||
use crate::filetransfer::FileTransfer;
|
use crate::filetransfer::FileTransfer;
|
||||||
use crate::host::Localhost;
|
use crate::host::Localhost;
|
||||||
|
|
||||||
|
// Includes
|
||||||
|
use crossterm::execute;
|
||||||
|
use crossterm::event::EnableMouseCapture;
|
||||||
|
use crossterm::terminal::{EnterAlternateScreen};
|
||||||
|
use std::io::{stdout, Stdout, Write};
|
||||||
|
use tui::backend::CrosstermBackend;
|
||||||
|
use tui::Terminal;
|
||||||
|
|
||||||
/// ## Context
|
/// ## Context
|
||||||
///
|
///
|
||||||
/// Context holds data structures used by the ui
|
/// Context holds data structures used by the ui
|
||||||
@@ -35,6 +47,7 @@ pub struct Context {
|
|||||||
pub scp_client: Box<dyn FileTransfer>,
|
pub scp_client: Box<dyn FileTransfer>,
|
||||||
pub local: Localhost,
|
pub local: Localhost,
|
||||||
pub(crate) input_hnd: InputHandler,
|
pub(crate) input_hnd: InputHandler,
|
||||||
|
pub(crate) terminal: Terminal<CrosstermBackend<Stdout>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
@@ -42,10 +55,14 @@ impl Context {
|
|||||||
///
|
///
|
||||||
/// Instantiates a new Context
|
/// Instantiates a new Context
|
||||||
pub fn new(scp_client: Box<dyn FileTransfer>, local: Localhost) -> Context {
|
pub fn new(scp_client: Box<dyn FileTransfer>, local: Localhost) -> Context {
|
||||||
|
// Create terminal
|
||||||
|
let mut stdout = stdout();
|
||||||
|
assert!(execute!(stdout, EnterAlternateScreen, EnableMouseCapture).is_ok());
|
||||||
Context {
|
Context {
|
||||||
scp_client: scp_client,
|
scp_client: scp_client,
|
||||||
local: local,
|
local: local,
|
||||||
input_hnd: InputHandler::new(),
|
input_hnd: InputHandler::new(),
|
||||||
|
terminal: Terminal::new(CrosstermBackend::new(stdout)).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user