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

Commit

Permalink
Merge pull request #41 from PThorpe92/dev
Browse files Browse the repository at this point in the history
feat: huge refactor (again) hacking away
  • Loading branch information
PThorpe92 authored Oct 4, 2023
2 parents ffc2ddc + 5c89c70 commit dace561
Show file tree
Hide file tree
Showing 19 changed files with 492 additions and 857 deletions.
148 changes: 1 addition & 147 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "CuTE"
name = "CuTE-tui" # crates.io/crates/CuTE is taken :(
version = "0.1.0"
authors = ["PThorpe92 <[email protected]>"]
license = "GPL-3.0"
Expand All @@ -14,7 +14,6 @@ lazy_static = "1.4.0"
rusqlite = { version = "0.29.0", features = ["bundled"] }
serde_json = {version = "1.0.107", features = ["std"] }
serde = { version = "1.0.188", features = ["derive"] }
chrono = "0.4.31"
curl = "0.4.44"
mockito = "1.2.0"
regex = "1.9.5"
Expand Down
14 changes: 12 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{error, mem};

use crate::database::db::DB;
use crate::display::displayopts::DisplayOpts;
use crate::display::shareablecmd::ShareableCommand;
use crate::request::command::Command;
use crate::request::curl::Curl;
use crate::screens::screen::Screen;
use crate::{database::db::DB, request::wget::Wget};
use tui::widgets::{ListItem, ListState};
use tui_input::Input;
/// Application result type.
Expand Down Expand Up @@ -59,11 +60,20 @@ impl<'a> Default for App<'a> {
}
}

impl<'a> App<'_> {
impl<'a> App<'a> {
/// Constructs a new instance of [`App`].
pub fn new() -> Self {
Self::default()
}
pub fn set_command(&mut self, command: Command<'a>) {
self.command = Some(command);
}

pub fn set_url(&mut self, url: String) {
if let Some(cmd) = &mut self.command {
cmd.set_url(url);
}
}

pub fn tick(&self) {}

Expand Down
5 changes: 3 additions & 2 deletions src/display/inputopt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::request::cmdtype::CmdType;
use crate::request::curl::AuthKind;

#[derive(Debug, Clone, PartialEq)]
pub enum InputOpt {
URL,
URL(CmdType),
Headers,
Output,
Verbose,
Expand All @@ -15,7 +16,7 @@ pub enum InputOpt {
impl InputOpt {
pub fn to_string(&self) -> String {
match self {
InputOpt::URL => "URL",
InputOpt::URL(_) => "URL",
InputOpt::Headers => "Header",
InputOpt::Output => "Output",
InputOpt::RequestBody => "Request Body",
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::io;
use dirs::data_local_dir;
use tui::backend::CrosstermBackend;
use tui::Terminal;
use CuTE::app::{App, AppResult};
use CuTE::events::event::{Event, EventHandler};
use CuTE::events::handler::handle_key_events;
use CuTE::ui::tui::Tui;
use CuTE_tui::app::{App, AppResult};
use CuTE_tui::events::event::{Event, EventHandler};
use CuTE_tui::events::handler::handle_key_events;
use CuTE_tui::ui::tui::Tui;

fn main() -> AppResult<()> {
let mut app = App::new();
Expand Down
11 changes: 11 additions & 0 deletions src/request/cmdtype.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
use std::fmt::{Display, Error, Formatter};

#[derive(Debug, Clone, PartialEq)]
pub enum CmdType {
Curl,
Wget,
}

impl Display for CmdType {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
match self {
CmdType::Curl => write!(f, "HTTP Request"),
CmdType::Wget => write!(f, "Download"),
}
}
}
1 change: 1 addition & 0 deletions src/request/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl<'a> Command<'a> {
}
}
}

pub fn save_command(&mut self, save: bool) {
if let Command::Curl(curl) = self {
curl.save_command(save);
Expand Down
2 changes: 1 addition & 1 deletion src/request/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ mod tests {
curl.set_response(response);
curl.set_output("output.txt".to_string());
curl.write_output().unwrap();
std::fs::remove_file("output.txt").unwrap();
let _ = std::fs::remove_file("output.txt");
}

#[test]
Expand Down
7 changes: 0 additions & 7 deletions src/request/methods.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/request/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod cmdtype;
pub mod command;
pub mod methods;
// Curl command builder
pub mod curl;
// Wget command builder
Expand Down
Loading

0 comments on commit dace561

Please sign in to comment.