diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md old mode 100644 new mode 100755 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md old mode 100644 new mode 100755 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md old mode 100644 new mode 100755 diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml old mode 100644 new mode 100755 diff --git a/.github/workflows/general.yml b/.github/workflows/general.yml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md old mode 100644 new mode 100755 diff --git a/Cargo.lock b/Cargo.lock old mode 100644 new mode 100755 diff --git a/Cargo.toml b/Cargo.toml old mode 100644 new mode 100755 diff --git a/Justfile b/Justfile old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/TODO.md b/TODO.md old mode 100644 new mode 100755 diff --git a/cliff.toml b/cliff.toml old mode 100644 new mode 100755 diff --git a/extra/error-request.gif b/extra/error-request.gif new file mode 100755 index 0000000..3431294 Binary files /dev/null and b/extra/error-request.gif differ diff --git a/extra/new-request.gif b/extra/new-request.gif new file mode 100755 index 0000000..f7f1966 Binary files /dev/null and b/extra/new-request.gif differ diff --git a/extra/preview.gif b/extra/preview.gif old mode 100644 new mode 100755 index 5872ad0..54c047d Binary files a/extra/preview.gif and b/extra/preview.gif differ diff --git a/extra/tapes/create_request.tape b/extra/tapes/create_request.tape new file mode 100755 index 0000000..5f78205 --- /dev/null +++ b/extra/tapes/create_request.tape @@ -0,0 +1,47 @@ +Output extra/new-request.gif +Hide + Set Shell zsh + + Set Theme { "name": "Kanagawa", "cursor": "#DCD7BA", "selection": "#2A2A37", "background": "#181616", "foreground": "#DCD7BA", "black": "#1F1F28", "blue": "#658594", "cyan": "#9CABCA", "green": "#76946A", "magenta": "#957FB8", "red": "#E82424", "white": "#DCD7BA", "yellow": "#FF9E3B", "brightBlack": "#2A2A37", "brightBlue": "#7FB4CA", "brightCyan": "#A3D4D5", "brightGreen": "#98BB6C", "brightMagenta": "#D27E99", "brightRed": "#FF5D62", "brightWhite": "#DCD7BA", "brightYellow": "#E6C384" } + + Set FontSize 12 + Set Width 1200 + Set Height 600 + + Set Padding 0 + Set FontFamily "JetBrains Mono" + + Set WindowBar Colorful + Set WindowBarSize 50 + + # Set Theme "Rose Pine" + Type "cargo run -q -- --dry-run" + Enter + # enter the editor + Sleep 3s + Enter + Sleep 3s +Show +Sleep 2s +# select sidebar +Enter +Sleep 200ms +# enter form +Type "n" +Sleep 1s +Type@100ms "My awesome request" +Sleep 1s +Tab +Sleep 100ms +Tab +Sleep 100ms +Tab +Sleep 100ms +Enter +Sleep 1s +Tab +Sleep 100ms +Tab +Sleep 100ms +Enter +Sleep 3s diff --git a/extra/tapes/error_request.tape b/extra/tapes/error_request.tape new file mode 100755 index 0000000..79035e8 --- /dev/null +++ b/extra/tapes/error_request.tape @@ -0,0 +1,97 @@ +Output extra/error-request.gif +Hide + Set Shell zsh + + Set Theme { "name": "Kanagawa", "cursor": "#DCD7BA", "selection": "#2A2A37", "background": "#181616", "foreground": "#DCD7BA", "black": "#1F1F28", "blue": "#658594", "cyan": "#9CABCA", "green": "#76946A", "magenta": "#957FB8", "red": "#E82424", "white": "#DCD7BA", "yellow": "#FF9E3B", "brightBlack": "#2A2A37", "brightBlue": "#7FB4CA", "brightCyan": "#A3D4D5", "brightGreen": "#98BB6C", "brightMagenta": "#D27E99", "brightRed": "#FF5D62", "brightWhite": "#DCD7BA", "brightYellow": "#E6C384" } + + Set FontSize 12 + Set Width 1200 + Set Height 600 + + Set Padding 0 + Set FontFamily "JetBrains Mono" + + Set WindowBar Colorful + Set WindowBarSize 50 + + Type "cargo run -q -- --dry-run" + Enter + # enter the editor + Sleep 3s + Enter + Sleep 3s +Show +Sleep 2s +# go to editor tab +Tab +Sleep 200ms +Tab +Sleep 1s +# Enter the editor +Enter +# Edit the message to true +Type@100ms "jj$i" +Sleep 300ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Type@100ms "true" +Escape +Sleep 100ms +Escape +# go to the headers +Sleep 1s +Tab +Sleep 200ms +# go to request uri +Tab +Sleep 200ms +Tab +Sleep 1s +# focus and send a request +Enter +Sleep 0.5s +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 1s +Enter +Sleep 0.5s +Escape +# go to the response +Tab +Sleep 200ms +Tab +Sleep 200ms +Enter +Sleep 1s +Tab +Sleep 1s +Tab +Sleep 3s diff --git a/extra/tapes/preview.tape b/extra/tapes/preview.tape old mode 100644 new mode 100755 index 6967f01..479c340 --- a/extra/tapes/preview.tape +++ b/extra/tapes/preview.tape @@ -14,57 +14,63 @@ Hide Set WindowBar Colorful Set WindowBarSize 50 - Type "cargo run -q" + Type "cargo run -q -- --dry-run" Enter + # enter the editor Sleep 3s Enter - Sleep 1s - Tab - Tab - Tab Sleep 3s Show -Sleep 1s -Enter -Sleep 500ms -Type@200ms "jj" -Enter -Sleep 3s +Sleep 2s +# go to editor tab Tab -Sleep 1s -Enter -Tab -Sleep 0.5s +Sleep 200ms Tab -Sleep 0.5s -Enter Sleep 1s -Type@100ms "jjjjjjjjjj" +# Enter the editor +Enter +# Edit the message to true +Type@100ms "jj$i" +Sleep 300ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Backspace +Sleep 100ms +Type@100ms "true" +Escape +Sleep 100ms +Escape +# go to the headers Sleep 1s Tab -Sleep 1s +Sleep 200ms +# go to request uri +Tab +Sleep 200ms Tab Sleep 1s -Type@100ms "jjjjjjjjjj" -Sleep 1s -Escape +# focus and send a request +Enter +Sleep 0.5s +Type@100ms "-headers" Sleep 1s -Tab +Enter Sleep 0.5s +Escape +# go to the response Tab -Sleep 0.5s +Sleep 200ms Tab -Sleep 0.5s +Sleep 200ms Enter -Type@100ms "jjjj" -Sleep 1s -Type@100ms "wwwww" -Sleep 1s -Type "D" Sleep 1s -Type "i" +Tab Sleep 1s -Type@100ms 'hac@is_awesome.com",' -Sleep 0.2s -Escape +Tab Sleep 3s diff --git a/flake.lock b/flake.lock old mode 100644 new mode 100755 diff --git a/flake.nix b/flake.nix old mode 100644 new mode 100755 diff --git a/hac-cli/Cargo.toml b/hac-cli/Cargo.toml old mode 100644 new mode 100755 diff --git a/hac-cli/src/lib.rs b/hac-cli/src/lib.rs old mode 100644 new mode 100755 diff --git a/hac-client/Cargo.toml b/hac-client/Cargo.toml old mode 100644 new mode 100755 diff --git a/hac-client/benches/collection_viewer_bench.rs b/hac-client/benches/collection_viewer_bench.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/app.rs b/hac-client/src/app.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/ascii.rs b/hac-client/src/ascii.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/event_pool.rs b/hac-client/src/event_pool.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/lib.rs b/hac-client/src/lib.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/main.rs b/hac-client/src/main.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages.rs b/hac-client/src/pages.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_dashboard/collection_dashboard.rs b/hac-client/src/pages/collection_dashboard/collection_dashboard.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_dashboard/collection_list.rs b/hac-client/src/pages/collection_dashboard/collection_list.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_dashboard/mod.rs b/hac-client/src/pages/collection_dashboard/mod.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_dashboard/new_collection_form.rs b/hac-client/src/pages/collection_dashboard/new_collection_form.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_viewer/collection_store.rs b/hac-client/src/pages/collection_viewer/collection_store.rs old mode 100644 new mode 100755 index 310eba0..19f05cd --- a/hac-client/src/pages/collection_viewer/collection_store.rs +++ b/hac-client/src/pages/collection_viewer/collection_store.rs @@ -41,7 +41,7 @@ impl CollectionStore { let selected_request = collection.requests.as_ref().and_then(|requests| { requests.read().unwrap().first().and_then(|req| { if let RequestKind::Single(req) = req { - Some(Arc::clone(req)) + Some(req.clone()) } else { None } @@ -323,6 +323,7 @@ mod tests { id: "root".to_string(), method: RequestMethod::Get, name: "Root1".to_string(), + headers: None, uri: "/root1".to_string(), body_type: None, body: None, @@ -335,6 +336,7 @@ mod tests { method: RequestMethod::Post, name: "Child1".to_string(), uri: "/nested1/child1".to_string(), + headers: None, body_type: None, body: None, }))) @@ -345,6 +347,7 @@ mod tests { id: "child_two".to_string(), method: RequestMethod::Put, name: "Child2".to_string(), + headers: None, uri: "/nested1/child2".to_string(), body_type: None, body: None, @@ -356,6 +359,7 @@ mod tests { id: "not_used".to_string(), method: RequestMethod::Put, name: "NotUsed".to_string(), + headers: None, uri: "/not/used".to_string(), body_type: None, body: None, @@ -378,6 +382,7 @@ mod tests { RequestKind::Single(Arc::new(RwLock::new(Request { id: "root_two".to_string(), method: RequestMethod::Delete, + headers: None, name: "Root2".to_string(), uri: "/root2".to_string(), body_type: None, diff --git a/hac-client/src/pages/collection_viewer/collection_viewer.rs b/hac-client/src/pages/collection_viewer/collection_viewer.rs old mode 100644 new mode 100755 index df48fbb..72136cc --- a/hac-client/src/pages/collection_viewer/collection_viewer.rs +++ b/hac-client/src/pages/collection_viewer/collection_viewer.rs @@ -551,19 +551,17 @@ impl<'cv> CollectionViewer<'cv> { let mut store_mut = self.collection_store.borrow_mut(); if let RequestKind::Single(ref req) = new_request { - self.collection_store - .borrow_mut() - .dispatch(CollectionStoreAction::SetSelectedRequest(Some(req.clone()))); + store_mut.dispatch(CollectionStoreAction::SetSelectedRequest(Some(req.clone()))); store_mut.dispatch(CollectionStoreAction::SetHoveredRequest(Some( new_request.get_id(), ))); - self.sidebar.rebuild_tree_view(); } store_mut.dispatch(CollectionStoreAction::InsertRequest(new_request)); // dropping the borrow so we can sync the changes drop(store_mut); + self.sidebar.rebuild_tree_view(); self.create_req_form_state = CreateReqFormState::default(); self.curr_overlay = Overlays::None; diff --git a/hac-client/src/pages/collection_viewer/mod.rs b/hac-client/src/pages/collection_viewer/mod.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_viewer/request_editor.rs b/hac-client/src/pages/collection_viewer/request_editor.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_viewer/request_editor/auth_editor.rs b/hac-client/src/pages/collection_viewer/request_editor/auth_editor.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_viewer/request_editor/body_editor.rs b/hac-client/src/pages/collection_viewer/request_editor/body_editor.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_viewer/request_editor/headers_editor.rs b/hac-client/src/pages/collection_viewer/request_editor/headers_editor.rs old mode 100644 new mode 100755 index 1a9e968..f1a32c8 --- a/hac-client/src/pages/collection_viewer/request_editor/headers_editor.rs +++ b/hac-client/src/pages/collection_viewer/request_editor/headers_editor.rs @@ -1,12 +1,14 @@ use crate::pages::{collection_viewer::collection_store::CollectionStore, Eventful, Renderable}; -use std::{cell::RefCell, rc::Rc}; +use std::{cell::RefCell, ops::Div, rc::Rc}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; +use hac_core::collection::types::HeaderMap; use ratatui::{ - layout::Rect, + layout::{Constraint, Direction, Layout, Rect}, style::Stylize, - widgets::{Cell, Paragraph, Row, Table}, + text::Line, + widgets::{Block, Borders, Cell, Paragraph, Row, Table}, Frame, }; @@ -19,6 +21,7 @@ pub enum HeadersEditorEvent { pub struct HeadersEditor<'he> { colors: &'he hac_colors::colors::Colors, collection_store: Rc>, + scroll: usize, } impl<'he> HeadersEditor<'he> { @@ -29,8 +32,29 @@ impl<'he> HeadersEditor<'he> { HeadersEditor { colors, collection_store, + scroll: 0, } } + + fn draw_row(&self, (row, header): (Rc<[Rect]>, &HeaderMap), frame: &mut Frame) { + let enabled = self.colors.normal.yellow; + let disabled = self.colors.bright.black; + let make_paragraph = |text: &str| { + Paragraph::new(text.to_string()) + .fg(if header.enabled { enabled } else { disabled }) + .block( + Block::default() + .fg(self.colors.normal.white) + .borders(Borders::BOTTOM), + ) + }; + + let name = make_paragraph(&header.pair.0); + let value = make_paragraph(&header.pair.1); + + frame.render_widget(name, row[0]); + frame.render_widget(value, row[1]); + } } impl Renderable for HeadersEditor<'_> { @@ -44,19 +68,40 @@ impl Renderable for HeadersEditor<'_> { return Ok(()); }; - let table = Table::default() - .header(Row::new(vec![ - Cell::new("Name".fg(self.colors.normal.red)), - Cell::new("Value".fg(self.colors.normal.red)), - ])) - .rows(headers.iter().map(|header_map| { - Row::new(vec![ - header_map.pair.0.to_string(), - header_map.pair.1.to_string(), - ]) - })); + let size = build_layout(size); + let row_height = 2; + let [titles_size, headers_size] = Layout::default() + .direction(Direction::Vertical) + .constraints([Constraint::Length(row_height), Constraint::Fill(1)]) + .areas(size); + + let [name_title_size, value_title_size] = Layout::default() + .direction(Direction::Horizontal) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)]) + .areas(titles_size); - frame.render_widget(table, size); + let title_name = Paragraph::new("Name").fg(self.colors.normal.red).bold(); + let title_value = Paragraph::new("Value").fg(self.colors.normal.red).bold(); + + let pane_height = headers_size.height; + let items_fitting_onscreen = pane_height.div(row_height) as usize; + + Layout::default() + .constraints((0..items_fitting_onscreen).map(|_| Constraint::Length(row_height))) + .direction(Direction::Vertical) + .split(headers_size) + .iter() + .map(|row| { + Layout::default() + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)]) + .direction(Direction::Horizontal) + .split(*row) + }) + .zip(headers.iter()) + .for_each(|pair| self.draw_row(pair, frame)); + + frame.render_widget(title_name, name_title_size); + frame.render_widget(title_value, value_title_size); Ok(()) } @@ -73,3 +118,16 @@ impl Eventful for HeadersEditor<'_> { Ok(None) } } + +fn build_layout(size: Rect) -> Rect { + let [_, content, _] = Layout::default() + .constraints([ + Constraint::Length(1), + Constraint::Fill(1), + Constraint::Length(1), + ]) + .direction(Direction::Horizontal) + .areas(size); + + content +} diff --git a/hac-client/src/pages/collection_viewer/request_uri.rs b/hac-client/src/pages/collection_viewer/request_uri.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_viewer/response_viewer.rs b/hac-client/src/pages/collection_viewer/response_viewer.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/collection_viewer/sidebar.rs b/hac-client/src/pages/collection_viewer/sidebar.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/confirm_popup.rs b/hac-client/src/pages/confirm_popup.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/error_popup.rs b/hac-client/src/pages/error_popup.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/input.rs b/hac-client/src/pages/input.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/overlay.rs b/hac-client/src/pages/overlay.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/spinner.rs b/hac-client/src/pages/spinner.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/terminal_too_small.rs b/hac-client/src/pages/terminal_too_small.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/pages/under_construction.rs b/hac-client/src/pages/under_construction.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/screen_manager.rs b/hac-client/src/screen_manager.rs old mode 100644 new mode 100755 diff --git a/hac-client/src/utils.rs b/hac-client/src/utils.rs old mode 100644 new mode 100755 diff --git a/hac-client/tests/collection_dashboard.rs b/hac-client/tests/collection_dashboard.rs old mode 100644 new mode 100755 diff --git a/hac-colors/Cargo.toml b/hac-colors/Cargo.toml old mode 100644 new mode 100755 diff --git a/hac-colors/src/colors.rs b/hac-colors/src/colors.rs old mode 100644 new mode 100755 diff --git a/hac-colors/src/lib.rs b/hac-colors/src/lib.rs old mode 100644 new mode 100755 diff --git a/hac-config/Cargo.toml b/hac-config/Cargo.toml old mode 100644 new mode 100755 diff --git a/hac-config/src/config.rs b/hac-config/src/config.rs old mode 100644 new mode 100755 diff --git a/hac-config/src/data.rs b/hac-config/src/data.rs old mode 100644 new mode 100755 diff --git a/hac-config/src/default_config.rs b/hac-config/src/default_config.rs old mode 100644 new mode 100755 diff --git a/hac-config/src/lib.rs b/hac-config/src/lib.rs old mode 100644 new mode 100755 diff --git a/hac-core/Cargo.toml b/hac-core/Cargo.toml old mode 100644 new mode 100755 diff --git a/hac-core/src/collection.rs b/hac-core/src/collection.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/collection/collection.rs b/hac-core/src/collection/collection.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/collection/errors.rs b/hac-core/src/collection/errors.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/collection/types.rs b/hac-core/src/collection/types.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/command.rs b/hac-core/src/command.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/fs.rs b/hac-core/src/fs.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/fs/error.rs b/hac-core/src/fs/error.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/fs/fs.rs b/hac-core/src/fs/fs.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/lib.rs b/hac-core/src/lib.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/net.rs b/hac-core/src/net.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/net/request_manager.rs b/hac-core/src/net/request_manager.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/net/request_strategies.rs b/hac-core/src/net/request_strategies.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/net/request_strategies/http_strategy.rs b/hac-core/src/net/request_strategies/http_strategy.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/net/response_decoders.rs b/hac-core/src/net/response_decoders.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/net/response_decoders/json_decoder.rs b/hac-core/src/net/response_decoders/json_decoder.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/syntax.rs b/hac-core/src/syntax.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/syntax/highlighter.rs b/hac-core/src/syntax/highlighter.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/syntax/queries/json/highlights.scm b/hac-core/src/syntax/queries/json/highlights.scm old mode 100644 new mode 100755 diff --git a/hac-core/src/text_object.rs b/hac-core/src/text_object.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/text_object/cursor.rs b/hac-core/src/text_object/cursor.rs old mode 100644 new mode 100755 diff --git a/hac-core/src/text_object/text_object.rs b/hac-core/src/text_object/text_object.rs old mode 100644 new mode 100755 diff --git a/rust-toolchain.toml b/rust-toolchain.toml old mode 100644 new mode 100755