mirror of
https://github.com/veeso/termscp.git
synced 2026-04-05 09:41:53 -07:00
context getters
This commit is contained in:
@@ -92,7 +92,7 @@ impl SetupActivity {
|
||||
None => Ok(()),
|
||||
Some(ctx) => {
|
||||
// Set editor if config client exists
|
||||
env::set_var("EDITOR", ctx.config_client.get_text_editor());
|
||||
env::set_var("EDITOR", ctx.config().get_text_editor());
|
||||
// Prepare terminal
|
||||
if let Err(err) = disable_raw_mode() {
|
||||
error!("Failed to disable raw mode: {}", err);
|
||||
@@ -101,10 +101,10 @@ impl SetupActivity {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
ctx.leave_alternate_screen();
|
||||
// Get result
|
||||
let result: Result<(), String> = match ctx.config_client.iter_ssh_keys().nth(idx) {
|
||||
let result: Result<(), String> = match ctx.config().iter_ssh_keys().nth(idx) {
|
||||
Some(key) => {
|
||||
// Get key path
|
||||
match ctx.config_client.get_ssh_key(key) {
|
||||
match ctx.config().get_ssh_key(key) {
|
||||
Ok(ssh_key) => match ssh_key {
|
||||
None => Ok(()),
|
||||
Some((_, _, key_path)) => {
|
||||
|
||||
@@ -134,24 +134,38 @@ impl Default for SetupActivity {
|
||||
}
|
||||
|
||||
impl SetupActivity {
|
||||
/// ### 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()
|
||||
}
|
||||
|
||||
fn config(&self) -> &ConfigClient {
|
||||
&self.context.as_ref().unwrap().config_client
|
||||
&self.context().config()
|
||||
}
|
||||
|
||||
fn config_mut(&mut self) -> &mut ConfigClient {
|
||||
&mut self.context.as_mut().unwrap().config_client
|
||||
self.context_mut().config_mut()
|
||||
}
|
||||
|
||||
fn theme(&self) -> &Theme {
|
||||
self.context.as_ref().unwrap().theme_provider.theme()
|
||||
self.context().theme_provider().theme()
|
||||
}
|
||||
|
||||
fn theme_mut(&mut self) -> &mut Theme {
|
||||
self.context.as_mut().unwrap().theme_provider.theme_mut()
|
||||
self.context_mut().theme_provider_mut().theme_mut()
|
||||
}
|
||||
|
||||
fn theme_provider(&mut self) -> &mut ThemeProvider {
|
||||
&mut self.context.as_mut().unwrap().theme_provider
|
||||
self.context_mut().theme_provider_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +202,7 @@ impl Activity for SetupActivity {
|
||||
return;
|
||||
}
|
||||
// Read one event
|
||||
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() {
|
||||
// Set redraw to true
|
||||
self.redraw = true;
|
||||
// Handle event
|
||||
|
||||
@@ -197,7 +197,7 @@ impl SetupActivity {
|
||||
|
||||
pub(super) fn view_setup(&mut self) {
|
||||
let mut ctx: Context = self.context.take().unwrap();
|
||||
let _ = ctx.terminal.draw(|f| {
|
||||
let _ = ctx.terminal().draw(|f| {
|
||||
// Prepare main chunks
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
||||
@@ -111,7 +111,7 @@ impl SetupActivity {
|
||||
|
||||
pub(crate) fn view_ssh_keys(&mut self) {
|
||||
let mut ctx: Context = self.context.take().unwrap();
|
||||
let _ = ctx.terminal.draw(|f| {
|
||||
let _ = ctx.terminal().draw(|f| {
|
||||
// Prepare main chunks
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
||||
@@ -175,7 +175,7 @@ impl SetupActivity {
|
||||
|
||||
pub(super) fn view_theme(&mut self) {
|
||||
let mut ctx: Context = self.context.take().unwrap();
|
||||
let _ = ctx.terminal.draw(|f| {
|
||||
let _ = ctx.terminal().draw(|f| {
|
||||
// Prepare main chunks
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
||||
Reference in New Issue
Block a user