@ -276,48 +276,6 @@ pub enum RedrawEvent {
} ,
}
#[ derive(Debug) ]
pub enum ChannelStreamType {
Stdio ,
Stderr ,
Socket ,
Job ,
}
impl Default for ChannelStreamType {
fn default ( ) -> Self {
Self ::Stdio
}
}
#[ derive(Debug) ]
pub enum ChannelMode {
Bytes ,
Terminal ,
Rpc ,
}
impl Default for ChannelMode {
fn default ( ) -> Self {
Self ::Bytes
}
}
#[ derive(Debug, Default) ]
pub struct ClientInfo {
pub name : String ,
}
#[ derive(Debug, Default) ]
pub struct ChannelInfo {
pub id : u64 ,
pub stream : ChannelStreamType ,
pub mode : ChannelMode ,
pub pty : Option < String > ,
pub buffer : Option < String > ,
pub client : Option < ClientInfo > ,
}
fn unpack_color ( packed_color : u64 ) -> Color4f {
let packed_color = packed_color as u32 ;
let r = ( ( packed_color & 0x00ff_0000 ) > > 16 ) as f32 ;
@ -919,74 +877,3 @@ pub fn parse_redraw_event(event_value: Value) -> Result<Vec<RedrawEvent>> {
Ok ( parsed_events )
}
pub fn parse_channel_stream_type ( channel_stream_value : Value ) -> Result < ChannelStreamType > {
match parse_string ( channel_stream_value ) ? . as_ref ( ) {
"stdio" = > Ok ( ChannelStreamType ::Stdio ) ,
"stderr" = > Ok ( ChannelStreamType ::Stderr ) ,
"socket" = > Ok ( ChannelStreamType ::Socket ) ,
"job" = > Ok ( ChannelStreamType ::Job ) ,
stream_type = > Err ( ParseError ::Format ( format! ( "{:?}" , stream_type ) ) ) ,
}
}
pub fn parse_channel_mode ( channel_mode_value : Value ) -> Result < ChannelMode > {
match parse_string ( channel_mode_value ) ? . as_ref ( ) {
"bytes" = > Ok ( ChannelMode ::Bytes ) ,
"terminal" = > Ok ( ChannelMode ::Terminal ) ,
"rpc" = > Ok ( ChannelMode ::Rpc ) ,
channel_mode = > Err ( ParseError ::Format ( format! ( "{:?}" , channel_mode ) ) ) ,
}
}
pub fn parse_client_info ( client_info_value : Value ) -> Result < ClientInfo > {
let client_info_map = parse_map ( client_info_value ) ? ;
let mut client_info = ClientInfo ::default ( ) ;
for info_property in client_info_map {
if let ( Value ::String ( name ) , value ) = info_property {
match ( name . as_str ( ) . unwrap ( ) , value ) {
( "name" , name ) = > client_info . name = parse_string ( name ) ? ,
_ = > debug ! ( "Ignored client type property: {}" , name ) ,
}
} else {
debug ! ( "Invalid client info format" ) ;
}
}
Ok ( client_info )
}
pub fn parse_channel_info ( channel_value : Value ) -> Result < ChannelInfo > {
let channel_map = parse_map ( channel_value ) ? ;
let mut channel_info = ChannelInfo ::default ( ) ;
for channel_property in channel_map {
if let ( Value ::String ( name ) , value ) = channel_property {
match ( name . as_str ( ) . unwrap ( ) , value ) {
( "id" , channel_id ) = > channel_info . id = parse_u64 ( channel_id ) ? ,
( "stream" , stream ) = > channel_info . stream = parse_channel_stream_type ( stream ) ? ,
( "mode" , mode ) = > channel_info . mode = parse_channel_mode ( mode ) ? ,
( "pty" , pty ) = > channel_info . pty = Some ( parse_string ( pty ) ? ) ,
( "buffer" , buffer ) = > channel_info . buffer = Some ( parse_string ( buffer ) ? ) ,
( "client" , client_info ) = > {
channel_info . client = Some ( parse_client_info ( client_info ) ? )
}
_ = > debug ! ( "Ignored channel info property: {}" , name ) ,
}
} else {
debug ! ( "Invalid channel info format" ) ;
}
}
Ok ( channel_info )
}
pub fn parse_channel_list ( channel_infos : Vec < Value > ) -> Result < Vec < ChannelInfo > > {
channel_infos
. into_iter ( )
. map ( parse_channel_info )
. collect ::< Result < Vec < ChannelInfo > > > ( )
}