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

Commit

Permalink
feat: echo response to stdout upon app exit + refactor garbage
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Nov 22, 2023
1 parent fe20ce3 commit 997d027
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 51 deletions.
3 changes: 0 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ All commit messages must follow the conventional commit format. For more informa
- **Description**: A short description of the change and your reasoning for it.

- **Related issue**: If there is no issue related, please create one :)



4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
![image](imgs/cute.png)
# Rust TUI HTTP Client with API Key Management

#### This project is still in active development and although it is useable, there may still be bugs and significant changes are still needed to both refactor the codebase and add new features.
#### I am distracted with work and a new project at the moment, so I am not able to put in as much time as I would like here and I am afraid that if I don't open source it now, it will end up in the side-project graveyard. Collaboration is welcome and encouraged, there is LOTS of low-hanging fruit here, while still being a useful tool.
#### This project is still in active development and although it is definitely useable, there may still be bugs and significant changes are still needed to both refactor the codebase and add new features.
#### Collaboration is welcome and encouraged! There is lots of low hanging fruit 👍and cool ideas for additional features.
![image](imgs/demo.gif)

Terminal user interface (TUI) HTTP client in Rust designed to simplify the process of making various types of HTTP requests while supporting various different kinds of Authentication (powered by libcURL), recursive downloading of directories (powered by GNU Wget), and storage + management of your previous requests + API keys.
Expand Down
13 changes: 10 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ impl<'a> App<'a> {
}

pub fn quit(&mut self) {
if let Some(resp) = self.response.as_ref() {
let _ = std::process::Command::new("echo")
.arg(resp)
.spawn()
.map_err(|e| e.to_string())
.unwrap();
}
self.running = false;
}

Expand Down Expand Up @@ -251,9 +258,9 @@ impl<'a> App<'a> {
}

pub fn get_response(&self) -> &str {
match self.response {
Some(ref response) => response,
None => "Error: No response",
match self.response.as_ref() {
Some(response) => response,
None => "",
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub static CONFIG_PATH: Lazy<String> = Lazy::new(|| {
fn parse_cmdline() -> Option<Config> {
let args = Command::new("CuTE")
.author("PThorpe92 <[email protected]>")
.version("0.1.0")
.version("0.0.1")
.about("Simple TUI for libcurl powered http requests, wget powered recursive downloads, and API key/command storage")
.after_help("Arguments are '--dump-config {path}' to write the default config file to the specified path,
\nand '--db-path' to define a custom path to the database\nDB path can also be defined in the config file at $CONFIG/CuTE/config.toml\n
Expand Down
78 changes: 37 additions & 41 deletions src/screens/render.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
use super::request::handle_request_menu_screen;
use super::saved_keys::handle_key_menu;
use super::*;
use crate::display::inputopt::InputOpt;
use crate::display::menuopts::{
API_KEY_PARAGRAPH, API_KEY_TITLE, AUTH_MENU_TITLE, DEFAULT_MENU_PARAGRAPH, DEFAULT_MENU_TITLE,
DOWNLOAD_MENU_TITLE, ERROR_MENU_TITLE, INPUT_MENU_TITLE, SAVED_COMMANDS_TITLE,
SUCCESS_MENU_TITLE, VIEW_BODY_TITLE,
};
use crate::display::AppOptions;
use crate::screens::input::input::handle_default_input_screen;

use super::auth::handle_authentication_screen;
use super::downloads::handle_downloads_screen;
use super::headers::handle_headers_screen;
use super::home::handle_home_screen;
use super::input::request_body_input::handle_req_body_input_screen;
use super::method::handle_method_select_screen;
use super::more_flags::handle_more_flags_screen;
use super::request::handle_request_menu_screen;
use super::response::handle_response_screen;
use super::saved_commands::{handle_alert_menu, handle_saved_commands_screen};
use super::saved_keys::{handle_key_menu, handle_saved_keys_screen};
use crate::screens::error::handle_error_screen;
use crate::{app::App, display::menuopts::SAVED_COMMANDS_PARAGRAPH};
use tui::style::Stylize;
use tui::text::Line;
Expand Down Expand Up @@ -145,8 +134,8 @@ pub fn handle_screen_defaults<B: Backend>(app: &mut App, frame: &mut Frame<'_, B

pub fn handle_screen<B: Backend>(app: &mut App, frame: &mut Frame<'_, B>, screen: Screen) {
match screen {
Screen::Home => handle_home_screen(app, frame),
Screen::Method => handle_method_select_screen(app, frame),
Screen::Home => home::handle_home_screen(app, frame),
Screen::Method => method::handle_method_select_screen(app, frame),
Screen::ViewBody => {
let area = default_rect(frame.size());
let response = app.response.clone().unwrap_or_default();
Expand All @@ -156,55 +145,65 @@ pub fn handle_screen<B: Backend>(app: &mut App, frame: &mut Frame<'_, B>, screen
frame.render_widget(paragraph, area);
}
Screen::Downloads(e) => {
if is_prompt(&e) {
handle_downloads_screen(app, frame, &e);
} else {
handle_downloads_screen(app, frame, "");
}
downloads::handle_downloads_screen(
app,
frame,
match is_prompt(&e) {
true => &e,
false => "",
},
);
}
//
// REQUEST MENU *********************************************************
Screen::RequestMenu(e) => {
if is_prompt(&e) {
handle_request_menu_screen(app, frame, e);
} else {
handle_request_menu_screen(app, frame, "".to_string());
}
handle_request_menu_screen(
app,
frame,
match is_prompt(&e) {
true => e,
false => String::new(),
},
);
}
// AUTHENTICATION SCREEN ************************************************
Screen::Authentication => {
handle_authentication_screen(app, frame);
auth::handle_authentication_screen(app, frame);
}
// SUCESSS SCREEN *******************************************************
Screen::Success => handle_screen_defaults(app, frame),
// INPUT MENU SCREEN ****************************************************
Screen::InputMenu(opt) => {
handle_default_input_screen(app, frame, opt.clone());
input::input::handle_default_input_screen(app, frame, opt.clone());
}
// RESPONSE SCREEN ******************************************************
Screen::Response(resp) => {
app.set_response(&resp);
handle_response_screen(app, frame, resp.to_string());
response::handle_response_screen(app, frame, resp.to_string());
}
Screen::SavedCommands => {
handle_saved_commands_screen(app, frame);
saved_commands::handle_saved_commands_screen(app, frame);
}
Screen::Headers => {
handle_headers_screen(app, frame);
headers::handle_headers_screen(app, frame);
}
Screen::Error(e) => {
handle_error_screen(app, frame, e);
error::handle_error_screen(app, frame, e);
}
Screen::MoreFlags => {
handle_more_flags_screen(app, frame);
more_flags::handle_more_flags_screen(app, frame);
}
Screen::SavedKeys => {
handle_saved_keys_screen(app, frame);
saved_keys::handle_saved_keys_screen(app, frame);
}
Screen::CmdMenu(cmd) => {
handle_alert_menu(app, frame, cmd);
saved_commands::handle_alert_menu(app, frame, cmd);
}
Screen::RequestBodyInput => handle_req_body_input_screen(app, frame, InputOpt::RequestBody),
Screen::RequestBodyInput => input::request_body_input::handle_req_body_input_screen(
app,
frame,
InputOpt::RequestBody,
),
Screen::KeysMenu(cmd) => handle_key_menu(app, frame, cmd),
_ => {}
}
Expand All @@ -220,11 +219,8 @@ fn handle_display_options(opts: &[AppOptions]) -> Vec<Line> {
.collect::<Vec<Line>>()
}

pub fn render_header_paragraph(
para: &'static str,
title: &'static str,
style: Style,
) -> Paragraph<'static> {
#[rustfmt::skip]
pub fn render_header_paragraph(para: &'static str, title: &'static str, style: Style) -> Paragraph<'static> {
Paragraph::new(para)
.block(
Block::default()
Expand Down
1 change: 0 additions & 1 deletion src/screens/saved_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ pub fn handle_alert_menu<B: Backend>(app: &mut App, frame: &mut Frame<'_, B>, cm
frame.render_widget(paragraph, cmd_str);
frame.render_widget(alert_text_chunk, alert_box);
frame.render_stateful_widget(list, options_box, &mut list_state);

match app.selected {
// execute saved command
Some(0) => {
Expand Down

0 comments on commit 997d027

Please sign in to comment.