@@ -3,19 +3,20 @@ use crossterm::{
3
3
execute,
4
4
terminal:: { disable_raw_mode, enable_raw_mode, EnterAlternateScreen , LeaveAlternateScreen } ,
5
5
} ;
6
- use sqlx:: postgres:: PgListener ;
7
- use sqlx:: PgPool ;
8
- use std:: sync:: Arc ;
9
- use std:: { error:: Error , io} ;
10
- use tokio:: { sync:: Mutex , time:: Duration } ;
11
- use tui:: {
6
+ use ratatui:: text:: Line ;
7
+ use ratatui:: {
12
8
backend:: { Backend , CrosstermBackend } ,
13
9
layout:: { Constraint , Direction , Layout } ,
14
10
style:: { Color , Modifier , Style } ,
15
- text:: { Span , Spans , Text } ,
11
+ text:: { Span , Text } ,
16
12
widgets:: { Block , Borders , List , ListItem , Paragraph } ,
17
13
Frame , Terminal ,
18
14
} ;
15
+ use sqlx:: postgres:: PgListener ;
16
+ use sqlx:: PgPool ;
17
+ use std:: sync:: Arc ;
18
+ use std:: { error:: Error , io} ;
19
+ use tokio:: { sync:: Mutex , time:: Duration } ;
19
20
use unicode_width:: UnicodeWidthStr ;
20
21
21
22
struct ChatApp {
@@ -53,7 +54,7 @@ impl ChatApp {
53
54
. await
54
55
. iter ( )
55
56
. map ( |m| {
56
- let content = vec ! [ Spans :: from( Span :: raw( m. to_owned( ) ) ) ] ;
57
+ let content = vec ! [ Line :: from( Span :: raw( m. to_owned( ) ) ) ] ;
57
58
ListItem :: new ( content)
58
59
} )
59
60
. collect ( ) ;
@@ -85,7 +86,7 @@ impl ChatApp {
85
86
}
86
87
}
87
88
88
- fn ui < B : Backend > ( & mut self , frame : & mut Frame < B > , messages : Vec < ListItem > ) {
89
+ fn ui ( & mut self , frame : & mut Frame , messages : Vec < ListItem > ) {
89
90
let chunks = Layout :: default ( )
90
91
. direction ( Direction :: Vertical )
91
92
. margin ( 2 )
@@ -99,7 +100,7 @@ impl ChatApp {
99
100
)
100
101
. split ( frame. size ( ) ) ;
101
102
102
- let text = Text :: from ( Spans :: from ( vec ! [
103
+ let text = Text :: from ( Line :: from ( vec ! [
103
104
Span :: raw( "Press " ) ,
104
105
Span :: styled( "Enter" , Style :: default ( ) . add_modifier( Modifier :: BOLD ) ) ,
105
106
Span :: raw( " to send the message, " ) ,
@@ -109,7 +110,7 @@ impl ChatApp {
109
110
let help_message = Paragraph :: new ( text) ;
110
111
frame. render_widget ( help_message, chunks[ 0 ] ) ;
111
112
112
- let input = Paragraph :: new ( self . input . as_ref ( ) )
113
+ let input = Paragraph :: new ( self . input . as_str ( ) )
113
114
. style ( Style :: default ( ) . fg ( Color :: Yellow ) )
114
115
. block ( Block :: default ( ) . borders ( Borders :: ALL ) . title ( "Input" ) ) ;
115
116
frame. render_widget ( input, chunks[ 1 ] ) ;
@@ -131,7 +132,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
131
132
// setup postgres
132
133
let conn_url =
133
134
std:: env:: var ( "DATABASE_URL" ) . expect ( "Env var DATABASE_URL is required for this example." ) ;
134
- let pool = sqlx :: PgPool :: connect ( & conn_url) . await ?;
135
+ let pool = PgPool :: connect ( & conn_url) . await ?;
135
136
136
137
let mut listener = PgListener :: connect ( & conn_url) . await ?;
137
138
listener. listen ( "chan0" ) . await ?;
0 commit comments