Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
refactor: slowly clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Dec 29, 2023
1 parent 92d2819 commit 1fe8b51
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 141 deletions.
79 changes: 45 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added output
Empty file.
39 changes: 35 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::database::db::{SavedCommand, SavedKey, DB};
use crate::display::menuopts::OPTION_PADDING_MID;
use crate::display::{AppOptions, HeaderKind};
use crate::request::command::{CmdOpts, CMD};
use crate::request::command::{Cmd, CmdOpts, CMD};

Check warning on line 4 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `Cmd`

warning: unused import: `Cmd` --> src/app.rs:4:31 | 4 | use crate::request::command::{Cmd, CmdOpts, CMD}; | ^^^ | = note: `#[warn(unused_imports)]` on by default
use crate::request::curl::{AuthKind, Curl};
use crate::screens::screen::Screen;
use crate::Config;
use arboard::Clipboard;
use std::rc::Rc;

Check warning on line 9 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `std::rc::Rc`

warning: unused import: `std::rc::Rc` --> src/app.rs:9:5 | 9 | use std::rc::Rc; | ^^^^^^^^^^^
use std::{error, mem};
use tui::widgets::{ListItem, ListState};
use tui_input::Input;
Expand Down Expand Up @@ -94,6 +95,36 @@ impl<'a> App<'a> {
}
}

pub fn copy_to_clipboard_from_response(&self) -> Result<(), String> {
if let Some(resp) = self.response.as_ref() {
if let Ok(mut clipboard) = Clipboard::new() {
if let Err(e) = clipboard.set_text(resp) {
return Err(e.to_string());
}
Ok(())
} else {
Err("Failed to copy to clipboard".to_string())
}
} else {
Err("No response to copy".to_string())
}
}

pub fn copy_to_clipboard_from_command(&mut self) -> Result<(), String> {
if let Some(cmd) = self.command.as_ref() {
if let Ok(mut clipboard) = Clipboard::new() {
if let Err(e) = clipboard.set_text(cmd.get_command_string()) {
return Err(e.to_string());
}
Ok(())
} else {
Err("Failed to copy to clipboard".to_string())
}
} else {
Err("No command to copy".to_string())
}
}

pub fn goto_screen(&mut self, screen: Screen) {
// Push New/Next Screen Onto The Screen Stack
self.screen_stack.push(screen.clone());
Expand Down Expand Up @@ -323,8 +354,8 @@ impl<'a> App<'a> {
AppOptions::Referrer(_) => self.command.as_mut().unwrap().set_referrer(""),
AppOptions::RecDownload(_) => self.command.as_mut().unwrap().set_rec_download_level(0),
AppOptions::RequestBody(_) => self.command.as_mut().unwrap().set_request_body(""),
AppOptions::Cookie(_) => self.command.as_mut().unwrap().remove_headers(opt.get_value()),
AppOptions::Headers(_) => self.command.as_mut().unwrap().remove_headers(opt.get_value()),
AppOptions::Cookie(_) => self.command.as_mut().unwrap().remove_headers(&opt.get_value()),
AppOptions::Headers(_) => self.command.as_mut().unwrap().remove_headers(&opt.get_value()),
AppOptions::Auth(_) => self.command.as_mut().unwrap().set_auth(crate::request::curl::AuthKind::None),
AppOptions::EnableHeaders => self.command.as_mut().unwrap().enable_response_headers(false),
AppOptions::ContentHeaders(_)=> self.command.as_mut().unwrap().set_content_header(HeaderKind::None),
Expand Down Expand Up @@ -437,7 +468,7 @@ impl<'a> App<'a> {
}
AppOptions::UnixSocket(socket) => self.command.as_mut().unwrap().set_unix_socket(&socket),

AppOptions::Headers(value) => self.command.as_mut().unwrap().add_headers(value),
AppOptions::Headers(value) => self.command.as_mut().unwrap().add_headers(&value),

AppOptions::URL(url) => self.command.as_mut().unwrap().set_url(&url),

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![warn(clippy::all)]
#![allow(non_snake_case)]
use clap::builder::Command;
use clap::Arg;
Expand Down
Loading

0 comments on commit 1fe8b51

Please sign in to comment.