This commit is contained in:
parent
55c0912608
commit
f719983c62
2 changed files with 46 additions and 24 deletions
|
@ -25,7 +25,7 @@ use web_time::Instant;
|
|||
|
||||
use crate::app::{
|
||||
password_locker::PasswordLocker,
|
||||
weather_icon::{WeatherIcon, DAY_ICONS},
|
||||
weather_icon::{WeatherIcon, WEATHER_ICONS},
|
||||
};
|
||||
|
||||
mod password_locker;
|
||||
|
@ -143,7 +143,7 @@ impl<E: AppExecutor> App<E> {
|
|||
lon: -111.89066476757807,
|
||||
country: String::from("US"),
|
||||
},
|
||||
"metric".to_owned(),
|
||||
"imperial".to_owned(),
|
||||
dotenv!("OPENWEATHERMAP_API_KEY").to_owned(),
|
||||
);
|
||||
weather_client.get_current_weather().await.unwrap()
|
||||
|
@ -225,23 +225,42 @@ impl<E: AppExecutor> App<E> {
|
|||
|
||||
let layout = Layout::new(
|
||||
Direction::Vertical,
|
||||
[Constraint::Length(12), Constraint::Min(0)],
|
||||
[Constraint::Length(20), Constraint::Min(0)],
|
||||
)
|
||||
.split(weather_area.inner(Margin::new(2, 2)));
|
||||
|
||||
let layout_upper = Layout::new(
|
||||
Direction::Horizontal,
|
||||
[Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)],
|
||||
if weather_area.width < (weather_area.height * 2) {
|
||||
Direction::Vertical
|
||||
} else {
|
||||
Direction::Horizontal
|
||||
},
|
||||
[
|
||||
Constraint::Length(if weather_area.width < (weather_area.height * 2) {
|
||||
28 / 2
|
||||
} else {
|
||||
28
|
||||
}),
|
||||
Constraint::Min(0),
|
||||
],
|
||||
)
|
||||
.split(layout[0]);
|
||||
|
||||
frame.render_widget(
|
||||
WeatherIcon(DAY_ICONS.get(&weather.weather[0].icon).unwrap()),
|
||||
WeatherIcon(
|
||||
WEATHER_ICONS
|
||||
.get(&weather.weather[0].icon[..weather.weather[0].icon.len() - 1])
|
||||
.unwrap(),
|
||||
weather.weather[0].icon[weather.weather[0].icon.len() - 1..]
|
||||
.bytes()
|
||||
.next()
|
||||
.unwrap(),
|
||||
),
|
||||
layout_upper[0],
|
||||
);
|
||||
frame.render_widget(
|
||||
Paragraph::new(format!(
|
||||
"{} {}°C\n~{}°C -{}°C +{}°C\n{} {} {}m/s SSE\nVisibility: {}km",
|
||||
"{} {}°F\n~{}°F -{}°F +{}°F\n{} {} {}mph\nVisibility: {}km",
|
||||
weather.name,
|
||||
weather.main.temp.unwrap_or(f64::NAN),
|
||||
weather.main.feels_like.unwrap_or(f64::NAN),
|
||||
|
@ -263,11 +282,7 @@ impl<E: AppExecutor> App<E> {
|
|||
))
|
||||
.fg(Color::Rgb(226, 190, 89))
|
||||
.bg(Color::Black),
|
||||
if weather_area.width < (weather_area.height * 2) {
|
||||
layout[1]
|
||||
} else {
|
||||
layout_upper[1]
|
||||
},
|
||||
layout_upper[1],
|
||||
);
|
||||
} else {
|
||||
frame.render_widget(
|
||||
|
|
|
@ -3,8 +3,8 @@ use ratatui::{style::Color, widgets::Widget};
|
|||
#[cfg(target_arch = "wasm32")]
|
||||
use ratzilla::ratatui;
|
||||
|
||||
pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
||||
"01d" => [
|
||||
pub const WEATHER_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
||||
"01" => [
|
||||
"",
|
||||
"",
|
||||
r#"
|
||||
|
@ -23,7 +23,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
============+
|
||||
"#,
|
||||
],
|
||||
"02d" => [
|
||||
"02" => [
|
||||
"",
|
||||
r#"
|
||||
......
|
||||
|
@ -53,7 +53,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
|
||||
"#,
|
||||
],
|
||||
"03d" => [
|
||||
"03" => [
|
||||
"",
|
||||
r#"
|
||||
.........
|
||||
|
@ -69,7 +69,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
"#,
|
||||
"",
|
||||
],
|
||||
"04d" => [
|
||||
"04" => [
|
||||
r#"
|
||||
########
|
||||
%#########
|
||||
|
@ -100,7 +100,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
"#,
|
||||
"",
|
||||
],
|
||||
"09d" => [
|
||||
"09" => [
|
||||
r#"
|
||||
#######
|
||||
-%#########
|
||||
|
@ -133,7 +133,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
"#,
|
||||
"",
|
||||
],
|
||||
"10d" => [
|
||||
"10" => [
|
||||
r#"
|
||||
|
||||
|
||||
|
@ -180,7 +180,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
|
||||
"#,
|
||||
],
|
||||
"11d" => [
|
||||
"11" => [
|
||||
r#"
|
||||
######
|
||||
#########
|
||||
|
@ -233,7 +233,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
+=
|
||||
"#,
|
||||
],
|
||||
"13d" => [
|
||||
"13" => [
|
||||
r#"
|
||||
##
|
||||
# ######## #
|
||||
|
@ -250,7 +250,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
"",
|
||||
"",
|
||||
],
|
||||
"50d" => [
|
||||
"50" => [
|
||||
r#"
|
||||
##########
|
||||
|
||||
|
@ -267,7 +267,7 @@ pub const DAY_ICONS: phf::Map<&'static str, [&'static str; 3]> = phf_map! {
|
|||
],
|
||||
};
|
||||
|
||||
pub struct WeatherIcon(pub &'static [&'static str; 3]);
|
||||
pub struct WeatherIcon(pub &'static [&'static str; 3], pub u8);
|
||||
|
||||
impl Widget for WeatherIcon {
|
||||
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer)
|
||||
|
@ -277,7 +277,14 @@ impl Widget for WeatherIcon {
|
|||
for (layer, color) in [
|
||||
(0, Color::Rgb(72, 72, 72)),
|
||||
(1, Color::Rgb(242, 242, 242)),
|
||||
(2, Color::Rgb(236, 110, 76)),
|
||||
(
|
||||
2,
|
||||
if self.1 == b'd' {
|
||||
Color::Rgb(236, 110, 76)
|
||||
} else {
|
||||
Color::Rgb(72, 72, 72)
|
||||
},
|
||||
),
|
||||
] {
|
||||
for (y, line) in self.0[layer].lines().skip(1).enumerate() {
|
||||
for (x, byte) in line.bytes().enumerate() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue