parsed `pijul channel` text blob into individual UI components

CrepeGoat
Oct 9, 2024, 6:20 AM
6ECOC7L5ZARQZIDELJODXFZQK5JJKRS5C6IVC3S7V2WDBTOBX3ZAC

Dependencies

  • [2] G2CHQAOP parsed `pijul log` text blob into individual entries & fields
  • [3] NSE6BLWA init slint project from https://github.com/slint-ui/slint-rust-template
  • [4] IQY5LHEN add GUI element to display simple `pijul log` results
  • [5] 4RPYR65C connect GUI to pijul to display simple channel list
  • [*] NCRTU7M4 cargo init

Change contents

  • replacement in ui/app-window.slint at line 1
    [3.57][3.0:84]()
    import { Button, VerticalBox, HorizontalBox, ScrollView } from "std-widgets.slint";
    [3.57]
    [2.0]
    import { Button, VerticalBox, HorizontalBox, ScrollView, ListView } from "std-widgets.slint";
  • edit in ui/app-window.slint at line 48
    [2.890]
    [2.890]
    component ChannelsList {
    in-out property <[string]> channels;
    in-out property <int> active;
  • edit in ui/app-window.slint at line 53
    [2.891]
    [3.116]
    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}";
    }
    }
    }
    }
  • replacement in ui/app-window.slint at line 83
    [3.161][3.0:47]()
    in-out property <string> channel_list: "";
    [3.161]
    [2.892]
    in-out property <[string]> channels <=> chs.channels;
    in-out property <int> active-channel <=> chs.active;
  • edit in ui/app-window.slint at line 89
    [3.169][3.169:206](),[3.206][3.328:329](),[3.328][3.328:329]()
    width: 600px;
    height: 400px;
  • replacement in ui/app-window.slint at line 101
    [3.363][3.363:634]()
    VerticalBox {
    alignment: start;
    preferred-width: 150px;
    Text {
    text: "channels";
    }
    Text {
    text: "\{root.channel_list}";
    }
    [3.363]
    [3.634]
    chs := ChannelsList {
    channels: [];
    active: 0;
  • edit in ui/app-window.slint at line 106
    [3.649]
    [3.649]
    // TODO convert to a (Standard)ListView?
  • edit in ui/app-window.slint at line 108
    [3.674]
    [3.674]
    preferred-width: 500px;
  • edit in ui/app-window.slint at line 111
    [3.742][3.742:786]()
    preferred-width: 500px;
  • replacement in src/main.rs at line 10
    [3.1044][2.1204:1240]()
    use slint::{ModelRc, SharedString};
    [3.1044]
    [3.733]
    use slint::SharedString;
  • replacement in src/main.rs at line 33
    [3.816][3.816:884]()
    ui.set_channel_list(SharedString::from(&channel_list));
    [3.816]
    [3.1045]
    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));
  • replacement in src/cmds.rs at line 4
    [3.979][3.979:1068]()
    pub fn channel(exe: &std::path::Path, repo: &std::path::Path) -> Result<String, Error> {
    [3.979]
    [3.1068]
    pub fn channel(exe: &std::path::Path, repo: &std::path::Path) -> Result<ChannelsList, Error> {
  • replacement in src/cmds.rs at line 13
    [3.1800][3.1800:1842]()
    Ok(String::from_utf8(output.stdout)?)
    [3.1800]
    [3.1842]
    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)
  • edit in src/cmds.rs at line 64
    [3.1928]
    [2.2059]
    }
    #[derive(Debug)]
    pub struct ChannelsList {
    pub(crate) entries: Vec<String>,
    pub(crate) active: usize,
  • edit in src/cmds.rs at line 72
    [2.2062]
    [2.2062]
    impl ChannelsList {
    pub(crate) fn new() -> Self {
    Self {
    entries: Vec::new(),
    active: usize::MAX,
    }
    }
    }