Lines
88.1 %
Functions
50 %
Branches
100 %
//! The SSH keys tab: fetching the list and settling the add and remove replies.
use crate::tabs::ssh_keys::SshKeysTab;
use cli_core::render::{WireValue, parse_wire};
use scripting::nomiscript::Value;
use crate::app::App;
use crate::modal::{ConfirmAction, Modal};
use crate::route::RouteCtx;
use crate::view::ViewId;
use crate::window::WindowId;
impl App {
pub fn fetch_ssh_keys(&mut self, window: WindowId) {
let Some(seq) = self
.win_mut::<SshKeysTab>(window)
.map(|tab| tab.seq.advance())
else {
return;
};
let ctx = RouteCtx::SshKeys { seq };
if let Some(id) = self.dispatch_eval(window, ctx, "(list-ssh-keys)".to_string())
&& let Some(keys) = self.win_mut::<SshKeysTab>(window)
{
keys.set_loading(id);
}
/// Asks before removing the key `fingerprint`.
pub fn confirm_remove_ssh_key(&mut self, fingerprint: String) {
if self.dialog_free("remove of the SSH key") {
self.open_dialog_for(
ViewId::SshKeys,
Modal::confirm(
format!("Remove SSH key {fingerprint}?"),
ConfirmAction::RemoveSshKey(fingerprint),
),
);
pub(super) fn deliver_ssh_keys(&mut self, window: WindowId, seq: u64, wire: &str) {
if let Some(keys) = self.win_mut::<SshKeysTab>(window)
&& keys.seq.awaits(seq)
keys.on_reply(wire);
pub(super) fn deliver_ssh_key_added(&mut self, window: WindowId, wire: &str) {
match parse_wire(wire) {
Ok(WireValue::Value(Value::String(id))) => {
self.status = "key added".to_string();
if let Some(keys) = self.win_mut::<SshKeysTab>(window) {
keys.follow = Some(id);
Ok(_) => self.status = "key added".to_string(),
Err(e) => self.status = format!("add failed: {e}"),
pub(super) fn deliver_ssh_key_removed(&mut self, fingerprint: &str, wire: &str) {
self.status = match parse_wire(wire) {
Ok(_) => format!("removed {fingerprint}"),
Err(e) => format!("remove failed: {e}"),