added diff view

CrepeGoat
Oct 16, 2024, 6:58 AM
BD456SZFVRW32OG6PN2TN5R3SAGMVH64KW7HQA7LHAVXMIA4HIJAC

Dependencies

  • [2] F6YAQWVD added UI for `pijul change`
  • [3] NBBTJI4I fixed bug s.t. choosing a new channel clears the log selection & delta view
  • [4] 337EO2TU add selection callback to changelog UI (& fix deselection)
  • [5] 4RPYR65C connect GUI to pijul to display simple channel list
  • [6] IQY5LHEN add GUI element to display simple `pijul log` results
  • [7] SOTD66FO set Changelog UI to display log from selected channel in ChannelsList UI
  • [8] NSE6BLWA init slint project from https://github.com/slint-ui/slint-rust-template
  • [9] I4NM4O3Z make changelog elements interactable
  • [10] XERTHGSY consolidated `pijul log` UI elements into their own component
  • [*] HZV5P57Y changed channel and log views to use `ListView` (looks much cleaner)
  • [*] NCRTU7M4 cargo init

Change contents

  • edit in ui/app-window.slint at line 29
    [2.403]
    [2.403]
    }
    }
    }
    component DiffEntry inherits Rectangle {
    VerticalBox {
    label := Text {
    text: "active diff";
  • edit in ui/app-window.slint at line 39
    [2.419]
    [2.419]
    in-out property <bool> is-selected: false;
    in property <bool> has-hover;
    states [
    selected when root.is-selected: {
    root.background: Palette.selection-background;
    label.color: Palette.selection-foreground;
    }
    lowlighted when root.has-hover: {
    root.background: Palette.alternate-background;
    label.color: Palette.alternate-foreground;
    }
    ]
  • replacement in ui/app-window.slint at line 104
    [4.109][4.168:208]()
    in-out property <int> selected: -1;
    [4.109]
    [4.208]
    in-out property <int> selected: -2;
    public function deselect() {
    root.selected = -2;
    }
  • edit in ui/app-window.slint at line 115
    [12.214]
    [4.318]
    diff-entry := DiffEntry {
    is-selected: root.selected == -1;
    has-hover: touch0.has-hover;
  • edit in ui/app-window.slint at line 120
    [4.319]
    [12.215]
    touch0 := TouchArea {
    clicked => {
    root.selected = -1;
    root.selection-changed(-1);
    }
    }
    }
  • edit in ui/app-window.slint at line 239
    [2.618]
    [4.168]
    callback request-diff-delta(string);
    function fill-diff-view() {
    if log.selected >= 0 && log.selected < log.changes_log.length {
    root.request-change-delta(changes_log[log.selected].hash)
    } else {
    root.request-diff-delta(chs.channels[chs.selected])
    }
    }
  • replacement in ui/app-window.slint at line 256
    [4.113][2.619:811]()
    if log.selected >= 0 {
    root.request-change-delta(changes_log[log.selected].hash)
    } else {
    delta = "";
    }
    [4.113]
    [4.454]
    fill-diff-view();
  • replacement in ui/app-window.slint at line 266
    [4.261][3.0:39](),[3.39][3.39:71]()
    log.selected = -1;
    delta = "";
    [4.261]
    [4.261]
    log.deselect();
    root.request-diff-delta(chs.channels[chs.selected])
  • replacement in ui/app-window.slint at line 274
    [2.961][2.961:1173]()
    if log.selected >= 0 {
    root.request-change-delta(changes_log[log.selected].hash)
    } else {
    delta = "";
    }
    [2.961]
    [2.1173]
    fill-diff-view();
  • edit in src/main.rs at line 108
    [2.1887]
    [2.1887]
    Ok(delta) => delta,
    Err(e) => {
    println!("{:?}", e);
    return;
    }
    };
    ui.set_delta((&String::from(delta)[..]).into());
    }
    });
    ui.on_request_diff_delta({
    let ui_handle = ui.as_weak();
    move |ch_name: SharedString| {
    let ch_name = ch_name.as_str();
    let ui = ui_handle.unwrap();
    let exe_path_string = ui.get_exe_path();
    let exe_path = Path::new(exe_path_string.as_str());
    let repo_path_string = ui.get_repo_path();
    let repo_path = Path::new(repo_path_string.as_str());
    let diff_output = cmds::diff(
    exe_path,
    repo_path,
    Some(ch_name).filter(|cn| !cn.is_empty()),
    );
    let delta = match diff_output {
  • edit in src/cmds.rs at line 61
    [2.2393]
    [2.2393]
    let output = cmd.output()?;
    check_exit_status(cmd, output.status)?;
    // TODO this will fail when diffing binary data
    Ok(String::from_utf8(output.stdout)?)
    }
    pub fn diff(
    exe: &std::path::Path,
    repo: &std::path::Path,
    ch_name_maybe: Option<&str>,
    ) -> Result<String, Error> {
    let mut cmd = Command::new(exe);
    let cmd = cmd
    .arg("diff")
    .arg("--no-prompt")
    .arg("--repository")
    .arg(repo);
    if let Some(ch_name) = ch_name_maybe {
    cmd.arg("--channel").arg(ch_name);
    }