-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
139 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
hac-client/src/pages/collection_viewer/request_editor/auth_editor.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crossterm::event::KeyEvent; | ||
use ratatui::{layout::Rect, widgets::Paragraph, Frame}; | ||
|
||
use crate::pages::{Eventful, Renderable}; | ||
|
||
#[derive(Debug)] | ||
pub struct AuthEditor<'ae> { | ||
colors: &'ae hac_colors::colors::Colors, | ||
} | ||
|
||
impl<'ae> AuthEditor<'ae> { | ||
pub fn new(colors: &'ae hac_colors::colors::Colors) -> Self { | ||
AuthEditor { colors } | ||
} | ||
} | ||
|
||
impl Renderable for AuthEditor<'_> { | ||
fn draw(&mut self, frame: &mut Frame, size: Rect) -> anyhow::Result<()> { | ||
frame.render_widget(Paragraph::new("hello from auth editor").centered(), size); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Eventful for AuthEditor<'_> { | ||
type Result = (); | ||
|
||
fn handle_key_event(&mut self, key_event: KeyEvent) -> anyhow::Result<Option<Self::Result>> { | ||
Ok(None) | ||
} | ||
} |
76 changes: 75 additions & 1 deletion
76
hac-client/src/pages/collection_viewer/request_editor/headers_editor.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,75 @@ | ||
pub struct HeadersEditor {} | ||
use crate::pages::{collection_viewer::collection_store::CollectionStore, Eventful, Renderable}; | ||
|
||
use std::{cell::RefCell, rc::Rc}; | ||
|
||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; | ||
use ratatui::{ | ||
layout::Rect, | ||
style::Stylize, | ||
widgets::{Cell, Paragraph, Row, Table}, | ||
Frame, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub enum HeadersEditorEvent { | ||
Quit, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct HeadersEditor<'he> { | ||
colors: &'he hac_colors::colors::Colors, | ||
collection_store: Rc<RefCell<CollectionStore>>, | ||
} | ||
|
||
impl<'he> HeadersEditor<'he> { | ||
pub fn new( | ||
colors: &'he hac_colors::colors::Colors, | ||
collection_store: Rc<RefCell<CollectionStore>>, | ||
) -> Self { | ||
HeadersEditor { | ||
colors, | ||
collection_store, | ||
} | ||
} | ||
} | ||
|
||
impl Renderable for HeadersEditor<'_> { | ||
fn draw(&mut self, frame: &mut Frame, size: Rect) -> anyhow::Result<()> { | ||
let Some(request) = self.collection_store.borrow().get_selected_request() else { | ||
return Ok(()); | ||
}; | ||
|
||
let request = request.read().expect("failed to read selected request"); | ||
let Some(headers) = request.headers.as_ref() else { | ||
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(), | ||
]) | ||
})); | ||
|
||
frame.render_widget(table, size); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Eventful for HeadersEditor<'_> { | ||
type Result = HeadersEditorEvent; | ||
|
||
fn handle_key_event(&mut self, key_event: KeyEvent) -> anyhow::Result<Option<Self::Result>> { | ||
if let (KeyCode::Char('c'), KeyModifiers::CONTROL) = (key_event.code, key_event.modifiers) { | ||
return Ok(Some(HeadersEditorEvent::Quit)); | ||
} | ||
|
||
Ok(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters