6ECOC7L5ZARQZIDELJODXFZQK5JJKRS5C6IVC3S7V2WDBTOBX3ZAC
VerticalBox {
alignment: start;
spacing: 0;
preferred-width: 150px;
Text {
text: "channels";
}
// TODO convert to a (Standard)ListView?
for ch[index] in channels: HorizontalBox {
alignment: start;
spacing: 0;
padding: 0;
Rectangle {
width: 10px;
height: 10px;
visible: index == root.active;
background: blue;
}
Text {
text: "\{ch}";
}
}
}
}
ui.set_channel_list(SharedString::from(&channel_list));
let channel_strs = channel_list
.entries
.into_iter()
.map(SharedString::from)
.collect::<Vec<_>>();
ui.set_channels((&channel_strs[..]).into());
ui.set_active_channel(i32::try_from(channel_list.active).unwrap_or(-1));
Ok(String::from_utf8(output.stdout)?)
parse_channel_output(output.stdout)
}
fn parse_channel_output(output: Vec<u8>) -> Result<ChannelsList, Error> {
let channels_str = String::from_utf8(output)?;
let channels_list = channels_str.split('\n').map(|substr| substr.trim()).fold(
ChannelsList::new(),
|mut channels_list, ch_str| {
if ch_str.starts_with("* ") {
channels_list.active = channels_list.entries.len();
channels_list.entries.push(ch_str[2..].to_string());
} else {
channels_list.entries.push(ch_str.to_string());
}
channels_list
},
);
Ok(channels_list)