1
1
use anyhow:: Result ;
2
- use chrono:: { Timelike , Utc } ;
3
2
use colored:: {
4
3
Color :: { Blue , BrightBlack , Yellow } ,
5
4
Colorize ,
@@ -23,7 +22,6 @@ pub struct Graph {
23
22
temperatures : String ,
24
23
graph : String ,
25
24
precipitation : String ,
26
- time_indicator_col : usize ,
27
25
}
28
26
29
27
#[ derive( Default , Serialize , Deserialize , PartialEq , Eq , Debug , Clone , Copy ) ]
@@ -67,8 +65,12 @@ impl Graph {
67
65
68
66
println ! (
69
67
"{}" ,
70
- self . prepare_separator( border_variant, width, '╤' )
71
- . color_option( BrightBlack , color_variant) ,
68
+ & match border_variant {
69
+ BorderVariant :: double => Separator :: Double . fmt( width, border_variant) ,
70
+ BorderVariant :: solid => Separator :: Solid . fmt( width, border_variant) ,
71
+ _ => Separator :: Dashed . fmt( width, border_variant) ,
72
+ }
73
+ . color_option( BrightBlack , color_variant)
72
74
) ;
73
75
74
76
println ! (
@@ -103,8 +105,12 @@ impl Graph {
103
105
104
106
println ! (
105
107
"{}" ,
106
- self . prepare_separator( border_variant, width, '╧' )
107
- . color_option( BrightBlack , color_variant) ,
108
+ match border_variant {
109
+ BorderVariant :: double => Separator :: Double . fmt( width, border_variant) ,
110
+ BorderVariant :: solid => Separator :: Solid . fmt( width, border_variant) ,
111
+ _ => Separator :: Dashed . fmt( width, border_variant) ,
112
+ }
113
+ . color_option( BrightBlack , color_variant)
108
114
) ;
109
115
110
116
let hours = match units. time {
@@ -124,24 +130,12 @@ impl Graph {
124
130
) ;
125
131
}
126
132
127
- pub async fn prepare (
128
- weather : & Weather ,
129
- current_hour : usize ,
130
- night : bool ,
131
- graph_variant : & GraphVariant ,
132
- lang : & str ,
133
- ) -> Result < Self > {
133
+ pub async fn prepare ( weather : & Weather , night : bool , graph_variant : & GraphVariant , lang : & str ) -> Result < Self > {
134
134
let temperatures = Self :: prepare_temperature ( weather, night, lang) . await ?;
135
135
let precipitation = Self :: prepare_precipitation ( & weather. hourly . precipitation [ ..=24 ] ) ?;
136
136
let graph = Self :: prepare_graph ( & weather. hourly . temperature_2m [ ..=24 ] , graph_variant) ?;
137
- let time_indicator_col = current_hour * 3 + ( Timelike :: minute ( & Utc :: now ( ) ) / 20 ) as usize ;
138
-
139
- Ok ( Graph {
140
- temperatures,
141
- graph,
142
- time_indicator_col,
143
- precipitation,
144
- } )
137
+
138
+ Ok ( Graph { temperatures, graph, precipitation } )
145
139
}
146
140
147
141
async fn prepare_temperature ( weather : & Weather , night : bool , lang : & str ) -> Result < String > {
@@ -219,32 +213,4 @@ impl Graph {
219
213
220
214
Ok ( graph)
221
215
}
222
-
223
- fn prepare_separator ( & self , border_variant : & BorderVariant , width : usize , time_indicator : char ) -> String {
224
- let col_correction = 3 ;
225
-
226
- match border_variant {
227
- BorderVariant :: double => format ! (
228
- "╟{:─>current_hour$}{:─>width$}╢" ,
229
- time_indicator,
230
- "" ,
231
- current_hour = self . time_indicator_col + col_correction,
232
- width = width - self . time_indicator_col - col_correction
233
- ) ,
234
- BorderVariant :: solid => format ! (
235
- "┠{:─>current_hour$}{:─>width$}┨" ,
236
- time_indicator,
237
- "" ,
238
- current_hour = self . time_indicator_col + col_correction,
239
- width = width - self . time_indicator_col - col_correction
240
- ) ,
241
- _ => format ! (
242
- "├{:┈>current_hour$}{:┈>width$}┤" ,
243
- time_indicator,
244
- "" ,
245
- current_hour = self . time_indicator_col + col_correction,
246
- width = width - self . time_indicator_col - col_correction
247
- ) ,
248
- }
249
- }
250
216
}
0 commit comments