Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): upgrade ratatui and all other dependencies to the latest #34

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,596 changes: 620 additions & 976 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openapi-tui"
version = "0.9.3"
version = "0.9.4"
edition = "2021"
description = "This TUI allows you to list and browse APIs described by the openapi specification."

Expand Down Expand Up @@ -36,7 +36,7 @@ libc = "0.2.153"
log = "0.4.21"
openapi-31 = { version = "0.4.0" }
pretty_assertions = "1.4.0"
ratatui = { version = "0.26.1", features = ["serde", "macros"] }
ratatui = { version = "0.27.0", features = ["serde", "macros"] }
reqwest = { version = "0.12.2", features = ["native-tls-vendored"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.115"
Expand All @@ -45,14 +45,15 @@ signal-hook = "0.3.17"
strip-ansi-escapes = "0.2.0"
strum = { version = "0.26.2", features = ["derive"] }
syntect = "5.2.0"
syntect-tui = "3.0.2"
syntect-tui = "3.0.3"
tokio = { version = "1.37.0", features = ["full"] }
tokio-util = "0.7.10"
tracing = "0.1.40"
tracing-error = "0.2.0"
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "serde"] }
tui-input = "0.8.0"
tui-textarea = "0.4.0"
tui-input = "0.9.0"
tui-textarea = "0.5.1"

[build-dependencies]
vergen = { version = "8.3.1", features = ["build", "git", "gitoxide", "cargo"] }
anyhow = "1.0.86"
vergen-git2 = { version = "1.0.0", features = ["build", "cargo"] }
8 changes: 5 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
vergen::EmitBuilder::builder().all_build().all_git().emit()?;
Ok(())
use anyhow::Result;
use vergen_git2::{BuildBuilder, Emitter, Git2Builder};

pub fn main() -> Result<()> {
Emitter::default().add_instructions(&BuildBuilder::all_build()?)?.add_instructions(&Git2Builder::all_git()?)?.emit()
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly"
channel = "stable"
79 changes: 38 additions & 41 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,24 @@ impl App {
.popup
.as_mut()
.and_then(|pane| pane.handle_events(e.clone(), &mut self.state).ok())
.map(|response| {
match response {
.map(|response| match response {
Some(tui::EventResponse::Continue(action)) => {
action_tx.send(action).ok();
false
},
Some(tui::EventResponse::Stop(action)) => {
action_tx.send(action).ok();
true
},
_ => false,
})
.unwrap_or(false);
stop_event_propagation = stop_event_propagation
|| self
.pages
.get_mut(self.active_page)
.and_then(|page| page.handle_events(e.clone(), &mut self.state).ok())
.map(|response| match response {
Some(tui::EventResponse::Continue(action)) => {
action_tx.send(action).ok();
false
Expand All @@ -104,45 +120,23 @@ impl App {
true
},
_ => false,
}
})
.unwrap_or(false);
stop_event_propagation = stop_event_propagation
|| self
.pages
.get_mut(self.active_page)
.and_then(|page| page.handle_events(e.clone(), &mut self.state).ok())
.map(|response| {
match response {
Some(tui::EventResponse::Continue(action)) => {
action_tx.send(action).ok();
false
},
Some(tui::EventResponse::Stop(action)) => {
action_tx.send(action).ok();
true
},
_ => false,
}
})
.unwrap_or(false);

stop_event_propagation = stop_event_propagation
|| self
.footer
.handle_events(e.clone(), &mut self.state)
.map(|response| {
match response {
Some(tui::EventResponse::Continue(action)) => {
action_tx.send(action).ok();
false
},
Some(tui::EventResponse::Stop(action)) => {
action_tx.send(action).ok();
true
},
_ => false,
}
.map(|response| match response {
Some(tui::EventResponse::Continue(action)) => {
action_tx.send(action).ok();
false
},
Some(tui::EventResponse::Stop(action)) => {
action_tx.send(action).ok();
true
},
_ => false,
})
.unwrap_or(false);

Expand Down Expand Up @@ -273,13 +267,16 @@ impl App {

while let Ok(request) = request_rx.try_recv() {
if let Ok(response) = reqwest::Client::new().execute(request.request).await {
self.state.responses.insert(request.operation_id, Response {
status: response.status(),
version: response.version(),
headers: response.headers().clone(),
content_length: response.content_length(),
body: response.text().await?.clone(),
});
self.state.responses.insert(
request.operation_id,
Response {
status: response.status(),
version: response.version(),
headers: response.headers().clone(),
content_length: response.content_length(),
body: response.text().await?.clone(),
},
);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/pages/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,9 @@ impl Page for Home {
KeyCode::Up | KeyCode::Char('k') | KeyCode::Char('K') => EventResponse::Stop(Action::Up),
KeyCode::Char('g') | KeyCode::Char('G') => EventResponse::Stop(Action::Go),
KeyCode::Backspace | KeyCode::Char('b') | KeyCode::Char('B') => EventResponse::Stop(Action::Back),
KeyCode::Enter => {
EventResponse::Stop(Action::NewCall(
state.active_operation().and_then(|op| op.operation.operation_id.clone()),
))
},
KeyCode::Enter => EventResponse::Stop(Action::NewCall(
state.active_operation().and_then(|op| op.operation.operation_id.clone()),
)),
KeyCode::Char('f') | KeyCode::Char('F') => EventResponse::Stop(Action::ToggleFullScreen),
KeyCode::Char(c) if ('1'..='9').contains(&c) => {
EventResponse::Stop(Action::Tab(c.to_digit(10).unwrap_or(0) - 1))
Expand Down
39 changes: 17 additions & 22 deletions src/panes/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,26 @@ impl Pane for AddressPane {
String::from("http://localhost")
};
let title = operation_item.operation.summary.clone().unwrap_or_default();
const INNER_MARGIN: Margin = Margin { horizontal: 1, vertical: 1 };

let inner = area.inner(&INNER_MARGIN);
let inner = area.inner(Margin { horizontal: 1, vertical: 1 });
frame.render_widget(
match operation_item.r#type {
OperationItemType::Path => {
Paragraph::new(Line::from(vec![
Span::styled(
format!("{:7}", operation_item.method.as_str()),
Style::default().fg(Self::method_color(operation_item.method.as_str())),
),
Span::styled(base_url, Style::default().fg(Color::DarkGray)),
Span::styled(&operation_item.path, Style::default().fg(Color::White)),
]))
},
OperationItemType::Webhook => {
Paragraph::new(Line::from(vec![
Span::styled("EVENT ", Style::default().fg(Color::LightMagenta)),
Span::styled(
format!("{} ", operation_item.method.as_str()),
Style::default().fg(Self::method_color(operation_item.method.as_str())),
),
Span::styled(&operation_item.path, Style::default().fg(Color::White)),
]))
},
OperationItemType::Path => Paragraph::new(Line::from(vec![
Span::styled(
format!("{:7}", operation_item.method.as_str()),
Style::default().fg(Self::method_color(operation_item.method.as_str())),
),
Span::styled(base_url, Style::default().fg(Color::DarkGray)),
Span::styled(&operation_item.path, Style::default().fg(Color::White)),
])),
OperationItemType::Webhook => Paragraph::new(Line::from(vec![
Span::styled("EVENT ", Style::default().fg(Color::LightMagenta)),
Span::styled(
format!("{} ", operation_item.method.as_str()),
Style::default().fg(Self::method_color(operation_item.method.as_str())),
),
Span::styled(&operation_item.path, Style::default().fg(Color::White)),
])),
},
inner,
);
Expand Down
11 changes: 7 additions & 4 deletions src/panes/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ impl Pane for ApisPane {
}
Some(Line::from(vec![
Span::styled(
format!(" {:7}", match operation_item.r#type {
OperationItemType::Path => operation_item.method.as_str(),
OperationItemType::Webhook => "EVENT",
}),
format!(
" {:7}",
match operation_item.r#type {
OperationItemType::Path => operation_item.method.as_str(),
OperationItemType::Webhook => "EVENT",
}
),
match operation_item.r#type {
OperationItemType::Path => Self::method_color(operation_item.method.as_str()),
OperationItemType::Webhook => Color::LightMagenta,
Expand Down
20 changes: 8 additions & 12 deletions src/panes/body_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ impl<'a> BodyEditor<'a> {
}
}

impl RequestPane for BodyEditor<'_> {
}
impl RequestPane for BodyEditor<'_> {}

impl RequestBuilder for BodyEditor<'_> {
fn reqeust(&self, request: reqwest::RequestBuilder) -> reqwest::RequestBuilder {
Expand Down Expand Up @@ -92,14 +91,12 @@ impl Pane for BodyEditor<'_> {

fn handle_key_events(&mut self, key: KeyEvent, state: &mut State) -> Result<Option<EventResponse<Action>>> {
match state.input_mode {
InputMode::Insert => {
match key.code {
KeyCode::Esc => Ok(Some(EventResponse::Stop(Action::Submit))),
_ => {
self.input.input(key);
Ok(Some(EventResponse::Stop(Action::Noop)))
},
}
InputMode::Insert => match key.code {
KeyCode::Esc => Ok(Some(EventResponse::Stop(Action::Submit))),
_ => {
self.input.input(key);
Ok(Some(EventResponse::Stop(Action::Noop)))
},
},
_ => Ok(None),
}
Expand Down Expand Up @@ -154,8 +151,7 @@ impl Pane for BodyEditor<'_> {
}

fn draw(&mut self, frame: &mut Frame<'_>, area: Rect, state: &State) -> Result<()> {
let margin_h1_v1: Margin = Margin { horizontal: 1, vertical: 1 };
let inner = area.inner(&margin_h1_v1);
let inner = area.inner(Margin { horizontal: 1, vertical: 1 });

if self.focused && state.input_mode == InputMode::Insert {
self.input.set_cursor_style(Style::default().add_modifier(Modifier::REVERSED));
Expand Down
10 changes: 4 additions & 6 deletions src/panes/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ impl HistoryPane {
let history = operation_ids
.iter()
.filter_map(|opertation_item| {
opertation_item.operation.operation_id.as_ref().map(|operation_id| {
OperationHistoryItem {
operation_id: operation_id.clone(),
method: opertation_item.method.clone(),
path: opertation_item.path.clone(),
}
opertation_item.operation.operation_id.as_ref().map(|operation_id| OperationHistoryItem {
operation_id: operation_id.clone(),
method: opertation_item.method.clone(),
path: opertation_item.path.clone(),
})
})
.collect::<Vec<OperationHistoryItem>>();
Expand Down
20 changes: 8 additions & 12 deletions src/panes/parameter_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ impl ParameterEditor {
}
}

impl RequestPane for ParameterEditor {
}
impl RequestPane for ParameterEditor {}

impl RequestBuilder for ParameterEditor {
fn path(&self, url: String) -> String {
Expand Down Expand Up @@ -224,14 +223,12 @@ impl Pane for ParameterEditor {

fn handle_key_events(&mut self, key: KeyEvent, state: &mut State) -> Result<Option<EventResponse<Action>>> {
match state.input_mode {
InputMode::Insert => {
match key.code {
KeyCode::Enter => Ok(Some(EventResponse::Stop(Action::Submit))),
_ => {
self.input.handle_event(&Event::Key(key));
Ok(Some(EventResponse::Stop(Action::Noop)))
},
}
InputMode::Insert => match key.code {
KeyCode::Enter => Ok(Some(EventResponse::Stop(Action::Submit))),
_ => {
self.input.handle_event(&Event::Key(key));
Ok(Some(EventResponse::Stop(Action::Noop)))
},
},
_ => Ok(None),
}
Expand Down Expand Up @@ -355,8 +352,7 @@ impl Pane for ParameterEditor {
}

fn draw(&mut self, frame: &mut Frame<'_>, area: Rect, state: &State) -> Result<()> {
let margin_h1_v1: Margin = Margin { horizontal: 1, vertical: 1 };
let inner = area.inner(&margin_h1_v1);
let inner = area.inner(Margin { horizontal: 1, vertical: 1 });

frame.render_widget(
Tabs::new(self.parameters.iter().map(|item| {
Expand Down
7 changes: 2 additions & 5 deletions src/panes/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ impl Pane for RequestPane {
}

fn draw(&mut self, frame: &mut Frame<'_>, area: Rect, _state: &State) -> Result<()> {
let inner_margin: Margin = Margin { horizontal: 1, vertical: 1 };

let inner = area.inner(&inner_margin);
let inner = area.inner(Margin { horizontal: 1, vertical: 1 });

frame.render_widget(
Tabs::new(self.schemas.iter().map(|item| {
Expand All @@ -212,8 +210,7 @@ impl Pane for RequestPane {
inner,
);

let inner_margin: Margin = Margin { horizontal: 1, vertical: 1 };
let mut inner = inner.inner(&inner_margin);
let mut inner = inner.inner(Margin { horizontal: 1, vertical: 1 });
inner.height = inner.height.saturating_add(1);
self.schema_viewer.render_widget(frame, inner);

Expand Down
7 changes: 2 additions & 5 deletions src/panes/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ impl Pane for ResponsePane {
}

fn draw(&mut self, frame: &mut Frame<'_>, area: Rect, _state: &State) -> Result<()> {
let inner_margin: Margin = Margin { horizontal: 1, vertical: 1 };

let inner = area.inner(&inner_margin);
let inner = area.inner(Margin { horizontal: 1, vertical: 1 });
frame.render_widget(
Tabs::new(self.schemas.iter().map(|resp| {
Span::styled(
Expand All @@ -195,8 +193,7 @@ impl Pane for ResponsePane {
inner,
);

let inner_margin: Margin = Margin { horizontal: 1, vertical: 1 };
let mut inner = inner.inner(&inner_margin);
let mut inner = inner.inner(Margin { horizontal: 1, vertical: 1 });
inner.height = inner.height.saturating_add(1);
self.schema_viewer.render_widget(frame, inner);

Expand Down
Loading