@@ -3,16 +3,40 @@ use std::collections::HashMap;
33
44use crate :: {
55 module:: { Module , ModuleMessage } ,
6- util,
7- websearch:: bits:: SearchError ,
8- widglets,
6+ util, widglets,
97} ;
108
11- mod bits;
12- use bits:: SearchResult ;
13- pub use bits:: WebMsg ;
9+ // mod dictionary;
1410mod wikipedia;
1511
12+ #[ derive( Debug , Clone ) ]
13+ pub enum WebMsg {
14+ GotResult ( String , Result < Vec < SearchResult > , SearchError > ) ,
15+ FetchedImage ( ( String , Result < iced:: widget:: image:: Handle , ( ) > ) ) ,
16+ ResultActivated ( String ) , // URL
17+ }
18+
19+ #[ derive( Debug , Clone ) ]
20+ pub struct SearchResult {
21+ pub destination_url : String ,
22+ pub title : String ,
23+ pub description : String ,
24+ pub image_url : Option < String > ,
25+ }
26+
27+ #[ derive( Debug , Clone , thiserror:: Error ) ]
28+ pub enum SearchError {
29+ BadResponse ( String ) ,
30+ }
31+
32+ impl std:: fmt:: Display for SearchError {
33+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
34+ match self {
35+ Self :: BadResponse ( inner) => f. write_str ( & format ! ( "Bad Response: {inner}" ) ) ,
36+ }
37+ }
38+ }
39+
1640#[ derive( Debug ) ]
1741pub struct Web {
1842 input_for_results : String ,
@@ -57,9 +81,9 @@ impl Web {
5781 let first = input_chars. clone ( ) . next ( ) ;
5882 let search_text = input. trim ( ) . to_string ( ) ;
5983
60- match ( first, search_text ) {
84+ match first {
6185 // get first char
62- ( Some ( 'w' ) , search_text ) => {
86+ Some ( 'w' ) => {
6387 log:: debug!( "wikipedia time!" ) ;
6488 let client = self . client . clone ( ) ;
6589
@@ -75,7 +99,11 @@ impl Web {
7599 |r| ModuleMessage :: WebMessage ( WebMsg :: GotResult ( r. 0 , r. 1 ) ) ,
76100 )
77101 }
78- ( None , _) => {
102+ Some ( 'd' ) => {
103+ log:: debug!( "Dictionary module" ) ;
104+ Task :: none ( )
105+ }
106+ None => {
79107 log:: info!( "Did not match in web searcher" ) ;
80108 Task :: none ( )
81109 }
0 commit comments