cargo: fmt
This commit is contained in:
parent
05879a8758
commit
09b0e7af9e
16
src/api.rs
16
src/api.rs
|
@ -1,4 +1,4 @@
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
@ -15,12 +15,16 @@ pub struct SearchResults {
|
||||||
pub struct Search {
|
pub struct Search {
|
||||||
pub currentPage: String,
|
pub currentPage: String,
|
||||||
pub hasNextPage: bool,
|
pub hasNextPage: bool,
|
||||||
pub results: Vec<SearchResults>
|
pub results: Vec<SearchResults>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn query_anime(query: String) -> Result<Search, reqwest::Error> {
|
pub async fn query_anime(query: String) -> Result<Search, reqwest::Error> {
|
||||||
reqwest::get(format!("https://altoku-api.vercel.app/anime/gogoanime/{}?page=1", query))
|
reqwest::get(format!(
|
||||||
.await.expect("Failed to get from API")
|
"https://altoku-api.vercel.app/anime/gogoanime/{}?page=1",
|
||||||
.json::<Search>()
|
query
|
||||||
.await
|
))
|
||||||
|
.await
|
||||||
|
.expect("Failed to get from API")
|
||||||
|
.json::<Search>()
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::app::{App, AppResult};
|
|
||||||
use crate::api::query_anime;
|
use crate::api::query_anime;
|
||||||
|
use crate::app::{App, AppResult};
|
||||||
|
|
||||||
use crossterm::event::*;
|
use crossterm::event::*;
|
||||||
use tui_input::backend::crossterm::EventHandler;
|
use tui_input::backend::crossterm::EventHandler;
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use ratatui::{
|
use ratatui::{backend::CrosstermBackend, prelude::*};
|
||||||
prelude::*,
|
|
||||||
backend::CrosstermBackend,
|
|
||||||
};
|
|
||||||
|
|
||||||
use altoku::{
|
use altoku::{
|
||||||
app::{App, AppResult},
|
app::{App, AppResult},
|
||||||
tui::Tui,
|
|
||||||
event::{Event, EventHandler},
|
event::{Event, EventHandler},
|
||||||
handler::handle_key_events,
|
handler::handle_key_events,
|
||||||
|
tui::Tui,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
32
src/ui.rs
32
src/ui.rs
|
@ -22,17 +22,15 @@ pub fn render(app: &mut App, frame: &mut Frame) {
|
||||||
)
|
)
|
||||||
.split(frame.size());
|
.split(frame.size());
|
||||||
|
|
||||||
let text: Vec<Line> = vec![
|
let text: Vec<Line> = vec![Line::from(vec![
|
||||||
Line::from(vec![
|
"Press ".into(),
|
||||||
"Press ".into(),
|
"Esc".bold(),
|
||||||
"Esc".bold(),
|
" or ".into(),
|
||||||
" or ".into(),
|
"Ctrl+C".bold(),
|
||||||
"Ctrl+C".bold(),
|
" to quit, and ".into(),
|
||||||
" to quit, and ".into(),
|
"Enter".bold(),
|
||||||
"Enter".bold(),
|
" to submit your query.".into(),
|
||||||
" to submit your query.".into(),
|
])];
|
||||||
]),
|
|
||||||
];
|
|
||||||
let help_message = Paragraph::new(text);
|
let help_message = Paragraph::new(text);
|
||||||
frame.render_widget(help_message, chunks[0]);
|
frame.render_widget(help_message, chunks[0]);
|
||||||
|
|
||||||
|
@ -42,12 +40,14 @@ pub fn render(app: &mut App, frame: &mut Frame) {
|
||||||
let input = Paragraph::new(app.input.value())
|
let input = Paragraph::new(app.input.value())
|
||||||
.style(Style::default().fg(Color::Yellow))
|
.style(Style::default().fg(Color::Yellow))
|
||||||
.scroll((0, scroll as u16))
|
.scroll((0, scroll as u16))
|
||||||
.block(Block::default().borders(Borders::ALL).title("Search (Anime)"));
|
.block(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title("Search (Anime)"),
|
||||||
|
);
|
||||||
frame.render_widget(input, chunks[1]);
|
frame.render_widget(input, chunks[1]);
|
||||||
frame.set_cursor(
|
frame.set_cursor(
|
||||||
chunks[1].x
|
chunks[1].x + ((app.input.visual_cursor()).max(scroll) - scroll) as u16 + 1,
|
||||||
+ ((app.input.visual_cursor()).max(scroll) - scroll) as u16
|
|
||||||
+ 1,
|
|
||||||
chunks[1].y + 1,
|
chunks[1].y + 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Reference in a new issue