mirror of
https://github.com/veeso/termscp.git
synced 2026-04-12 21:21:33 -07:00
context getters
This commit is contained in:
@@ -111,7 +111,7 @@ impl FileTransferActivity {
|
||||
/// Read one event.
|
||||
/// Returns whether at least one event has been handled
|
||||
pub(super) fn read_input_event(&mut self) -> bool {
|
||||
if let Ok(Some(event)) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
||||
if let Ok(Some(event)) = self.context().input_hnd().read_event() {
|
||||
// Handle event
|
||||
let msg = self.view.on(event);
|
||||
self.update(msg);
|
||||
|
||||
@@ -210,18 +210,32 @@ impl FileTransferActivity {
|
||||
})
|
||||
}
|
||||
|
||||
/// ### context
|
||||
///
|
||||
/// Returns a reference to context
|
||||
fn context(&self) -> &Context {
|
||||
self.context.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// ### context_mut
|
||||
///
|
||||
/// Returns a mutable reference to context
|
||||
fn context_mut(&mut self) -> &mut Context {
|
||||
self.context.as_mut().unwrap()
|
||||
}
|
||||
|
||||
/// ### config
|
||||
///
|
||||
/// Returns config client reference
|
||||
fn config(&self) -> &ConfigClient {
|
||||
&self.context.as_ref().unwrap().config_client
|
||||
&self.context().config()
|
||||
}
|
||||
|
||||
/// ### theme
|
||||
///
|
||||
/// Get a reference to `Theme`
|
||||
fn theme(&self) -> &Theme {
|
||||
self.context.as_ref().unwrap().theme_provider.theme()
|
||||
self.context().theme_provider().theme()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +255,7 @@ impl Activity for FileTransferActivity {
|
||||
// Set context
|
||||
self.context = Some(context);
|
||||
// Clear terminal
|
||||
self.context.as_mut().unwrap().clear_screen();
|
||||
self.context_mut().clear_screen();
|
||||
// Put raw mode on enabled
|
||||
if let Err(err) = enable_raw_mode() {
|
||||
error!("Failed to enter raw mode: {}", err);
|
||||
@@ -276,7 +290,7 @@ impl Activity for FileTransferActivity {
|
||||
}
|
||||
// Check if connected (popup must be None, otherwise would try reconnecting in loop in case of error)
|
||||
if !self.client.is_connected() && self.view.get_props(COMPONENT_TEXT_FATAL).is_none() {
|
||||
let params = self.context.as_ref().unwrap().ft_params.as_ref().unwrap();
|
||||
let params = self.context().ft_params().unwrap();
|
||||
info!(
|
||||
"Client is not connected to remote; connecting to {}:{}",
|
||||
params.address, params.port
|
||||
|
||||
@@ -76,15 +76,15 @@ impl FileTransferActivity {
|
||||
///
|
||||
/// Connect to remote
|
||||
pub(super) fn connect(&mut self) {
|
||||
let params = self.context.as_ref().unwrap().ft_params.as_ref().unwrap();
|
||||
let params = self.context().ft_params().unwrap().clone();
|
||||
let addr: String = params.address.clone();
|
||||
let entry_dir: Option<PathBuf> = params.entry_directory.clone();
|
||||
// Connect to remote
|
||||
match self.client.connect(
|
||||
params.address.clone(),
|
||||
params.address,
|
||||
params.port,
|
||||
params.username.clone(),
|
||||
params.password.clone(),
|
||||
params.username,
|
||||
params.password,
|
||||
) {
|
||||
Ok(welcome) => {
|
||||
if let Some(banner) = welcome {
|
||||
@@ -121,7 +121,7 @@ impl FileTransferActivity {
|
||||
///
|
||||
/// disconnect from remote
|
||||
pub(super) fn disconnect(&mut self) {
|
||||
let params = self.context.as_ref().unwrap().ft_params.as_ref().unwrap();
|
||||
let params = self.context().ft_params().unwrap();
|
||||
let msg: String = format!("Disconnecting from {}...", params.address);
|
||||
// Show popup disconnecting
|
||||
self.mount_wait(msg.as_str());
|
||||
|
||||
@@ -720,10 +720,8 @@ impl FileTransferActivity {
|
||||
Some(props) => {
|
||||
// Get width
|
||||
let width: usize = self
|
||||
.context
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.store
|
||||
.context()
|
||||
.store()
|
||||
.get_unsigned(super::STORAGE_EXPLORER_WIDTH)
|
||||
.unwrap_or(256);
|
||||
let hostname: String = match hostname::get() {
|
||||
@@ -768,13 +766,11 @@ impl FileTransferActivity {
|
||||
Some(props) => {
|
||||
// Get width
|
||||
let width: usize = self
|
||||
.context
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.store
|
||||
.context()
|
||||
.store()
|
||||
.get_unsigned(super::STORAGE_EXPLORER_WIDTH)
|
||||
.unwrap_or(256);
|
||||
let params = self.context.as_ref().unwrap().ft_params.as_ref().unwrap();
|
||||
let params = self.context().ft_params().unwrap();
|
||||
let hostname: String = format!(
|
||||
"{}:{} ",
|
||||
params.address,
|
||||
|
||||
Reference in New Issue
Block a user