@@ -265,7 +265,7 @@ impl Tab {
265265
266266 let this = self . clone ( ) ;
267267 let fut = async move {
268- let cache = match Self :: send_request ( & mut req_ctx) . await {
268+ let cache = match this . send_request ( & mut req_ctx) . await {
269269 Ok ( Some ( cache) ) => {
270270 info ! ( "Page loaded, can be cached ({})" , url. clone( ) ) ;
271271 Some ( cache)
@@ -306,10 +306,11 @@ impl Tab {
306306 * self . imp ( ) . url . borrow_mut ( ) = url. to_string ( ) ;
307307 self . notify ( "url" ) ;
308308
309+ let this = self . clone ( ) ;
309310 async move {
310311 let buf = BufReader :: new ( & * cache) ;
311312 draw_ctx. clear ( ) ;
312- let res = Self :: display_gemini ( & mut draw_ctx, buf) . await ;
313+ let res = this . display_gemini ( & mut draw_ctx, buf) . await ;
313314 match res {
314315 Ok ( _) => {
315316 info ! ( "Loaded {} from cache" , & url) ;
@@ -400,49 +401,54 @@ impl Tab {
400401
401402 Err ( anyhow:: Error :: msg ( "Clicked text doesn't have a link tag" ) )
402403 }
403- async fn open_file_url ( req : & mut RequestCtx ) -> Result < ( ) > {
404+ async fn open_file_url ( & self , req : & mut RequestCtx ) -> Result < ( ) > {
404405 let path = req
405406 . url
406407 . to_file_path ( )
407408 . map_err ( |_| anyhow:: Error :: msg ( "Can't convert link to file path" ) ) ?;
409+
410+ let this = self . clone ( ) ;
408411 let file = File :: open ( & path) . await ?;
409412 let lines = BufReader :: new ( file) ;
410413 match path. extension ( ) . map ( |x| x. to_str ( ) ) {
411414 Some ( Some ( "gmi" ) ) | Some ( Some ( "gemini" ) ) => {
412- Self :: display_gemini ( & mut req. draw_ctx , lines) . await ?;
415+ this . display_gemini ( & mut req. draw_ctx , lines) . await ?;
413416 }
414417 _ => {
415418 Self :: display_text ( & mut req. draw_ctx , lines) . await ?;
416419 }
417420 }
418421 Ok ( ( ) )
419422 }
420- async fn send_request ( req : & mut RequestCtx ) -> Result < Option < Vec < u8 > > > {
423+ async fn send_request ( & self , req : & mut RequestCtx ) -> Result < Option < Vec < u8 > > > {
421424 req. draw_ctx . clear ( ) ;
425+ let this = self . clone ( ) ;
422426 match req. url . scheme ( ) {
423427 "about" => {
424428 let reader = futures:: io:: BufReader :: new ( common:: ABOUT_PAGE . as_bytes ( ) ) ;
425- Self :: display_gemini ( & mut req. draw_ctx , reader) . await ?;
429+ this . display_gemini ( & mut req. draw_ctx , reader) . await ?;
426430 Ok ( None )
427431 }
428432 "file" => {
429- Self :: open_file_url ( req) . await ?;
433+ self . open_file_url ( req) . await ?;
430434 Ok ( None )
431435 }
432- "gemini" => Self :: open_gemini_url ( req) . await ,
436+ "gemini" => self . open_gemini_url ( req) . await ,
433437 _ => {
434438 Self :: display_url_confirmation ( & mut req. draw_ctx , & req. url ) ;
435439 Ok ( None )
436440 }
437441 }
438442 }
439- async fn open_gemini_url ( req : & mut RequestCtx ) -> anyhow:: Result < Option < Vec < u8 > > > {
443+ async fn open_gemini_url ( & self , req : & mut RequestCtx ) -> anyhow:: Result < Option < Vec < u8 > > > {
440444 let res: gemini:: Response = req. gemini_client . fetch ( req. url . as_str ( ) ) . await ?;
441445
442446 use gemini:: Status :: * ;
443447 let meta = res. meta ( ) . to_owned ( ) ;
444448 let status = res. status ( ) ;
445449 debug ! ( "Status: {:?}" , & status) ;
450+
451+ let this = self . clone ( ) ;
446452 let res = match status {
447453 Input ( _) => {
448454 Self :: display_input ( & mut req. draw_ctx , req. url . clone ( ) , & meta) ;
@@ -452,7 +458,7 @@ impl Tab {
452458 let body = res. body ( ) . context ( "Body not found" ) ?;
453459 let buffered = futures:: io:: BufReader :: new ( body) ;
454460 if meta. contains ( "text/gemini" ) {
455- let res = Self :: display_gemini ( & mut req. draw_ctx , buffered) . await ?;
461+ let res = this . display_gemini ( & mut req. draw_ctx , buffered) . await ?;
456462 Some ( res)
457463 } else if meta. contains ( "text" ) {
458464 Self :: display_text ( & mut req. draw_ctx , buffered) . await ?;
@@ -627,9 +633,12 @@ click on the button below\n",
627633 // FIXME: Handle open
628634 }
629635 async fn display_gemini < T : AsyncBufRead + Unpin > (
636+ & self ,
630637 draw_ctx : & mut DrawCtx ,
631638 mut reader : T ,
632639 ) -> anyhow:: Result < Vec < u8 > > {
640+ let imp = self . imp ( ) ;
641+
633642 let mut parser = gemini:: Parser :: new ( ) ;
634643 let mut text_iter = draw_ctx. text_buffer . end_iter ( ) ;
635644
@@ -638,6 +647,8 @@ click on the button below\n",
638647 let mut total = 0 ;
639648 let mut n;
640649
650+ let mut title_updated = false ;
651+
641652 loop {
642653 n = reader. read_line_lossy ( & mut data) . await ?;
643654 if n == 0 {
@@ -649,6 +660,8 @@ click on the button below\n",
649660 if let PageElement :: Preformatted ( line) = token {
650661 preformatted. push_str ( & line) ;
651662 } else {
663+ // preformatted text is handled different hoping to add scrollbars for it,
664+ // in the future, maybe
652665 if !preformatted. is_empty ( ) {
653666 draw_ctx. insert_preformatted ( & mut text_iter, & preformatted) ;
654667 preformatted. clear ( ) ;
@@ -659,6 +672,11 @@ click on the button below\n",
659672 }
660673 PageElement :: Heading ( line) => {
661674 draw_ctx. insert_heading ( & mut text_iter, & line) ;
675+ if !title_updated {
676+ title_updated = true ;
677+ imp. title . replace ( line. trim_end ( ) . trim_start_matches ( "#" ) . to_string ( ) ) ;
678+ self . notify ( "title" ) ;
679+ }
662680 }
663681 PageElement :: Quote ( line) => {
664682 draw_ctx. insert_quote ( & mut text_iter, & line) ;
0 commit comments