╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const builtin = @import("builtin"); 3 const evt = @import("../../event.zig"); 4 const ui = @import("../../ui.zig"); 5 const xit = @import("xit"); 6 const rp = xit.repo; 7 const hash = xit.hash; 8 const xitui = xit.xitui; 9 const wgt = xitui.widget; 10 const layout = xitui.layout; 11 const Key = xitui.input.Key; 12 const Grid = xitui.grid.Grid; 13 const Focus = xitui.focus.Focus; 14 const inp = @import("../input.zig"); 15 const diff3 = @import("../../diff3.zig"); 16 const Comment = @import("Comment.zig"); 17 18 const wasm = builtin.target.cpu.arch == .wasm32; 19 20 // how much of a description the detail pane shows before linking to the 21 // /description page, the same limit commit messages use. 22 pub const max_description_size = 2 * 1024; 23 24 // how many issues one window shows before a "next" link appears. 25 pub const page_size = 20; 26 27 // how many tags the tags view shows at most. 28 pub const max_tags = 1000; 29 30 // one issue from the repo's consumed event database, with its hex event id 31 // (the id lives in the event envelope, not the payload). 32 pub const IssueWithId = struct { 33 id: []const u8, 34 issue: evt.Issue.Record, 35 // the creation commit's author 36 author: ui.Author = .unknown, 37 // whether the issue has an unresolved merge conflict 38 conflicted: bool = false, 39 comments: Comment.Window = .empty, 40 }; 41 42 // one side of a conflicted field: its value and who set it 43 pub const Side = struct { 44 text: []const u8, 45 author: ui.Author = .unknown, 46 }; 47 48 pub const FieldConflict = struct { 49 ours: Side, 50 theirs: Side, 51 }; 52 53 // the selected issue's conflict, read for the resolve view. ours is the live 54 // record; the chunks split the description against the merge base. 55 pub const Conflict = struct { 56 title: ?FieldConflict = null, 57 tags: ?FieldConflict = null, 58 description: ?struct { 59 chunks: []const diff3.Chunk, 60 ours_author: ui.Author = .unknown, 61 theirs_author: ui.Author = .unknown, 62 } = null, 63 }; 64 65 // one status's windowed listing. 66 pub const Window = struct { 67 issues: []const IssueWithId, 68 // the id of the previous window's first issue, or null when this window 69 // is already the first. 70 prev_id: ?[]const u8, 71 // the id of the next window's first issue, or null when this is the last 72 // window. 73 next_id: ?[]const u8, 74 // how many issues the listing holds across all windows. 75 count: usize, 76 77 pub const empty: Window = .{ .issues = &.{}, .prev_id = null, .next_id = null, .count = 0 }; 78 }; 79 80 // "owner/name", so the view can build /repo/owner/name/issues/... links. 81 identity: []const u8, 82 // the url-encoded tag the lists are filtered to ("" = unfiltered). 83 tag: []const u8, 84 // the hex event id of the issue its status's window is rooted at ("" = the 85 // first window), mirrored into the url. 86 selected_id: []const u8, 87 // the comment shown in the selected issue's detail pane. 88 comment_id: []const u8, 89 // the selected issue's comment window (0 = the first window). 90 comments_start: usize, 91 // the selected comment and its immediate replies. 92 comment_page: ?Comment.Permalink = null, 93 open: Window, 94 closed: Window, 95 // the conflicted issues' listing; its count also gates the conflicts tab. 96 conflicts: Window, 97 // the selected issue's conflict, set when the page shows the resolve view. 98 conflict: ?Conflict = null, 99 // the resolve view's comma-separated fields prefilled from their side, 100 // mirrored from the url. 101 theirs_picks: []const u8 = "", 102 // the view the page shows initially (a selected issue's status overrides the route's) 103 view: ui.RoutablePage.IssuesView, 104 // the /description page: the detail pane shows the selected issue's whole 105 // description behind a back link. 106 description_page: bool = false, 107 // every tag in the repo, in sorted order, for the tags view. 108 tags: []const []const u8, 109 // the on-disk repo this page was read from, for the terminal submit path 110 // (the web posts the new-issue form to the issue route instead). 111 repo_source: ?ui.RepoSource = null, 112 113 const Self = @This(); 114 115 // `status`'s windowed listing. 116 pub fn window(self: *const Self, status: evt.Issue.Status) *const Window { 117 return switch (status) { 118 .open => &self.open, 119 .closed => &self.closed, 120 }; 121 } 122 123 // whether `field` (a field name or "d<n>" hunk name) is listed in the url's 124 // theirs: picks. 125 pub fn theirsPicked(self: *const Self, field: []const u8) bool { 126 var it = std.mem.splitScalar(u8, self.theirs_picks, ','); 127 while (it.next()) |pick| { 128 if (std.mem.eql(u8, pick, field)) return true; 129 } 130 return false; 131 } 132 133 // the issue `selected_id` names, in whichever window holds it. 134 pub fn selectedIssue(self: *const Self) ?*const IssueWithId { 135 if (self.selected_id.len == 0) return null; 136 for ([_]*const Window{ &self.open, &self.closed }) |win| { 137 for (win.issues) |*entry| { 138 if (std.mem.eql(u8, entry.id, self.selected_id)) return entry; 139 } 140 } 141 return null; 142 } 143 144 // an empty listing, for the wasm / no-repo paths. 145 pub fn emptyResult(aa: std.mem.Allocator, identity: []const u8, tag: []const u8, selected_id: []const u8, comment_id: []const u8, comments_start: usize, theirs_picks: []const u8, view: ui.RoutablePage.IssuesView) !Self { 146 return .{ 147 .identity = try aa.dupe(u8, identity), 148 .tag = try aa.dupe(u8, tag), 149 .selected_id = try aa.dupe(u8, selected_id), 150 .comment_id = try aa.dupe(u8, comment_id), 151 .comments_start = comments_start, 152 .open = .empty, 153 .closed = .empty, 154 .conflicts = .empty, 155 .theirs_picks = try aa.dupe(u8, theirs_picks), 156 // a description url shows a status list, the issue's own status 157 // picking it once the issue is read; conflicts and resolve urls also 158 // start there, upgraded by init when the conflict data exists. 159 .view = switch (view) { 160 .description, .conflicts, .resolve => .open, 161 else => view, 162 }, 163 .description_page = view == .description, 164 .tags = &.{}, 165 }; 166 } 167 168 // read one window per status of an opened repo's issues (filtered to `tag` 169 // when set), ordered by creation time (newest first). the window of the issue 170 // `selected_id` names starts at it ("" = the beginning). a git repo reads the 171 // event db next to it (synced from the events branch on each page build); a 172 // xit repo reads its own db. 173 pub fn init( 174 comptime repo_kind: rp.RepoKind, 175 comptime repo_opts: rp.RepoOpts(repo_kind), 176 arena: *std.heap.ArenaAllocator, 177 repo: *rp.Repo(repo_kind, repo_opts), 178 io: std.Io, 179 // the admin db's moment, for resolving author emails to user names (null 180 // in local mode, which has no users) 181 admin_moment: ?evt.AdminDB.HashMap(.read_only), 182 identity: []const u8, 183 tag: []const u8, 184 selected_id: []const u8, 185 comment_id: []const u8, 186 comments_start: usize, 187 theirs_picks: []const u8, 188 view: ui.RoutablePage.IssuesView, 189 ) !Self { 190 const empty = try emptyResult(arena.allocator(), identity, tag, selected_id, comment_id, comments_start, theirs_picks, view); 191 192 const aa = arena.allocator(); 193 const DB = evt.EventDB(repo_opts.hash); 194 const rooted = empty.selected_id.len != 0; 195 const tagged = empty.tag.len != 0; 196 // an explicitly named issue or tag that doesn't exist is a bad url 197 // (NotFound -> 404); the bare route falls through to an empty listing. 198 const strict = rooted or tagged; 199 200 // a repo with no consumed events has no moment yet. 201 const gpa = arena.child_allocator; 202 var event_db_maybe: ?evt.LocalEventDB(repo_opts.hash) = if (repo_kind == .git) try evt.LocalEventDB(repo_opts.hash).openReadOnly(io, gpa, repo.core.repo_dir) else null; 203 defer if (event_db_maybe) |*event_db| event_db.deinit(io, gpa); 204 const haxy_moment = (if (event_db_maybe) |*event_db| 205 evt.currentMomentFromDb(repo_opts.hash, event_db.db) 206 else if (repo_kind == .git) 207 return empty 208 else 209 evt.currentMoment(repo_opts, repo)) catch { 210 if (strict) return error.NotFound; 211 return empty; 212 }; 213 214 // the sorted sets to window, per status: the tag's sets when filtered, 215 // else the top-level per-status sets. a missing set is an empty window. 216 var open_set: ?DB.SortedSet(.read_only) = null; 217 var closed_set: ?DB.SortedSet(.read_only) = null; 218 if (tagged) { 219 const tag_to_issues_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "tag+status->issue-id-set")) orelse return error.NotFound; 220 const tag_to_issues = try DB.SortedMap(.read_only).init(tag_to_issues_cursor); 221 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, empty.tag)); 222 open_set = try tagStatusSet(DB, tag_to_issues, decoded, .open); 223 closed_set = try tagStatusSet(DB, tag_to_issues, decoded, .closed); 224 // a tag no issue carries is a bad url 225 if (open_set == null and closed_set == null) return error.NotFound; 226 } else if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "status->issue-id-set"))) |status_to_issues_cursor| { 227 const status_to_issues = try DB.SortedMap(.read_only).init(status_to_issues_cursor); 228 open_set = try statusSet(DB, status_to_issues, .open); 229 closed_set = try statusSet(DB, status_to_issues, .closed); 230 } else if (rooted) return error.NotFound; 231 232 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->issue")) orelse { 233 if (strict) return error.NotFound; 234 return empty; 235 }; 236 const event_id_to_issue = try DB.HashMap(.read_only).init(event_id_to_issue_cursor); 237 238 // the conflicted issues' container: a set view for membership and 239 // windowing, a map view for the resolve entry, over the same cursor. 240 var conflict_set: ?DB.SortedSet(.read_only) = null; 241 var conflicts_map: ?DB.SortedMap(.read_only) = null; 242 if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.conflicts_key))) |cursor| { 243 conflict_set = try DB.SortedSet(.read_only).init(cursor); 244 conflicts_map = try DB.SortedMap(.read_only).init(cursor); 245 } 246 247 // a named issue roots its own status's window at itself (the conflicts 248 // view's window instead); the other windows start at the beginning. 249 var resolved_view = empty.view; 250 var open_root: ?[]const u8 = null; 251 var closed_root: ?[]const u8 = null; 252 var conflicts_root: ?[]const u8 = null; 253 var conflict_data: ?Conflict = null; 254 if (rooted) { 255 if (empty.selected_id.len != evt.event_id_size * 2) return error.NotFound; 256 var id_bytes: [evt.event_id_size]u8 = undefined; 257 _ = std.fmt.hexToBytes(&id_bytes, empty.selected_id) catch return error.NotFound; 258 const issue_cursor = try event_id_to_issue.getCursor(hash.hashInt(repo_opts.hash, &id_bytes)) orelse return error.NotFound; 259 const issue_map = try DB.HashMap(.read_only).init(issue_cursor); 260 const issue_event = try evt.read(evt.Issue.Record, DB, repo_opts.hash, arena, issue_map); 261 const order_key = try aa.dupe(u8, &evt.orderKeyDesc(issue_event.created_ts, &id_bytes)); 262 263 if (view == .conflicts) { 264 // the id roots the conflicts window, so it must be conflicted 265 const set = conflict_set orelse return error.NotFound; 266 if (!try set.contains(order_key)) return error.NotFound; 267 conflicts_root = order_key; 268 } else { 269 // the named issue must be in its windowed set (a tag url can name 270 // an issue that doesn't carry the tag). 271 const set = (switch (issue_event.event.status) { 272 .open => open_set, 273 .closed => closed_set, 274 }) orelse return error.NotFound; 275 if (!try set.contains(order_key)) return error.NotFound; 276 277 switch (issue_event.event.status) { 278 .open => open_root = order_key, 279 .closed => closed_root = order_key, 280 } 281 // an edit url keeps its view; otherwise the issue's status picks it. 282 if (view != .edit) resolved_view = switch (issue_event.event.status) { 283 .open => .open, 284 .closed => .closed, 285 }; 286 287 // a resolve url shows the resolve view only while the issue still 288 // has a conflict entry; otherwise the status list stands. the 289 // wasm client renders from the snapshot, so the diff machinery 290 // this pulls in is gated out of its build. 291 if (comptime !wasm) { 292 if (view == .resolve) { 293 if (conflicts_map) |map| { 294 if (try map.getCursor(order_key)) |conflict_cursor| { 295 const conflict_entry = try DB.HashMap(.read_only).init(conflict_cursor); 296 conflict_data = try readConflict(repo_kind, repo_opts, arena, repo, io, admin_moment, haxy_moment, &id_bytes, issue_event, conflict_entry); 297 resolved_view = .resolve; 298 } 299 } 300 } 301 } 302 } 303 } 304 305 const thread_comments_start = if (empty.comment_id.len == 0) comments_start else 0; 306 const open_window = try loadWindow(repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, open_set, open_root, conflict_set, empty.selected_id, thread_comments_start); 307 const closed_window = try loadWindow(repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, closed_set, closed_root, conflict_set, empty.selected_id, thread_comments_start); 308 const conflicts_window = try loadWindow(repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, conflict_set, conflicts_root, conflict_set, empty.selected_id, thread_comments_start); 309 if (view == .conflicts and conflicts_window.count > 0) resolved_view = .conflicts; 310 311 const comment_page = if (empty.comment_id.len == 0) 312 null 313 else 314 try Comment.init(repo_opts.hash, arena, admin_moment, haxy_moment, empty.selected_id, empty.comment_id, comments_start); 315 316 // every tag in the repo, in the tag map's sorted order. the keys are 317 // "tag,status", so a tag's entries are adjacent and dedup by prefix. 318 var tags: std.ArrayList([]const u8) = .empty; 319 if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "tag+status->issue-id-set"))) |tag_to_issues_cursor| { 320 const tag_to_issues = try DB.SortedMap(.read_only).init(tag_to_issues_cursor); 321 var tag_iter = try tag_to_issues.iterator(); 322 while (try tag_iter.next()) |kv_pair_cursor| { 323 if (tags.items.len == max_tags) break; 324 var kv_cursor = kv_pair_cursor; 325 const kv_pair = try kv_cursor.readKeyValuePair(); 326 const key = try kv_pair.key_cursor.readBytesAlloc(aa, null); 327 const space = std.mem.indexOfScalar(u8, key, ' ') orelse continue; 328 const key_tag = key[0..space]; 329 if (tags.getLastOrNull()) |last| { 330 if (std.mem.eql(u8, last, key_tag)) continue; 331 } 332 try tags.append(aa, key_tag); 333 } 334 } 335 336 return .{ 337 .identity = empty.identity, 338 .tag = empty.tag, 339 .selected_id = empty.selected_id, 340 .comment_id = empty.comment_id, 341 .comments_start = comments_start, 342 .comment_page = comment_page, 343 .open = open_window, 344 .closed = closed_window, 345 .conflicts = conflicts_window, 346 .conflict = conflict_data, 347 .theirs_picks = empty.theirs_picks, 348 .view = resolved_view, 349 .description_page = empty.description_page, 350 .tags = tags.items, 351 }; 352 } 353 354 // `status`'s sorted set within `statuses` (null when the status has no issues) 355 fn statusSet( 356 comptime DB: type, 357 statuses: DB.SortedMap(.read_only), 358 status: evt.Issue.Status, 359 ) !?DB.SortedSet(.read_only) { 360 const cursor = (try statuses.getCursor(@tagName(status))) orelse return null; 361 return try DB.SortedSet(.read_only).init(cursor); 362 } 363 364 // the set at `tag_to_issues`'s "tag,status" key (null when no issue carries 365 // `tag` with `status`, or the tag is too long to exist) 366 fn tagStatusSet( 367 comptime DB: type, 368 tag_to_issues: DB.SortedMap(.read_only), 369 tag: []const u8, 370 status: evt.Issue.Status, 371 ) !?DB.SortedSet(.read_only) { 372 var key_buffer: evt.Issue.TagStatusKey = undefined; 373 const key = evt.Issue.tagStatusKey(&key_buffer, tag, status) catch return null; 374 const cursor = (try tag_to_issues.getCursor(key)) orelse return null; 375 return try DB.SortedSet(.read_only).init(cursor); 376 } 377 378 // read one window of `set_maybe` (null = an empty listing) starting at 379 // `root_key` (null = the beginning) 380 fn loadWindow( 381 comptime hash_kind: hash.HashKind, 382 arena: *std.heap.ArenaAllocator, 383 admin_moment: ?evt.AdminDB.HashMap(.read_only), 384 haxy_moment: evt.EventDB(hash_kind).HashMap(.read_only), 385 event_id_to_issue: evt.EventDB(hash_kind).HashMap(.read_only), 386 set_maybe: ?evt.EventDB(hash_kind).SortedSet(.read_only), 387 root_key: ?[]const u8, 388 conflict_set: ?evt.EventDB(hash_kind).SortedSet(.read_only), 389 selected_id: []const u8, 390 comments_start: usize, 391 ) !Window { 392 const set = set_maybe orelse return .empty; 393 const DB = evt.EventDB(hash_kind); 394 const aa = arena.allocator(); 395 396 // seek once to the window start: the root key, or the set's first entry. 397 var prev_id: ?[]const u8 = null; 398 var iter = if (root_key) |key| blk: { 399 // the previous window starts page_size ranks back ("" = the first 400 // window, linked as the bare list route). 401 const rank = try set.rank(key); 402 if (rank > 0 and rank <= page_size) { 403 prev_id = ""; 404 } else if (rank > page_size) { 405 const kv = try set.getIndexKeyValuePair(@intCast(rank - page_size)) orelse return error.NotFound; 406 var prev_key: [@sizeOf(u64) + evt.event_id_size]u8 = undefined; 407 _ = try kv.key_cursor.readBytes(&prev_key); 408 const prev_hex = std.fmt.bytesToHex(prev_key[@sizeOf(u64)..].*, .lower); 409 prev_id = try aa.dupe(u8, &prev_hex); 410 } 411 break :blk try set.iteratorFrom(key); 412 } else try set.iteratorFromIndex(0); 413 414 // collect this window's issues, plus a peek at the one after it (its id is 415 // the next window's start). the trailing bytes of each set key are the 416 // issue event id. 417 var issues: std.ArrayList(IssueWithId) = .empty; 418 var next_id: ?[]const u8 = null; 419 while (try iter.next()) |id_cursor_val| { 420 var id_cursor = id_cursor_val; 421 const id_kv = try id_cursor.readKeyValuePair(); 422 var order_key: [@sizeOf(u64) + evt.event_id_size]u8 = undefined; 423 _ = try id_kv.key_cursor.readBytes(&order_key); 424 const id_hex = std.fmt.bytesToHex(order_key[@sizeOf(u64)..].*, .lower); 425 if (issues.items.len == page_size) { 426 next_id = try aa.dupe(u8, &id_hex); 427 break; 428 } 429 const issue_cursor = try event_id_to_issue.getCursor(hash.hashInt(hash_kind, order_key[@sizeOf(u64)..])) orelse continue; 430 const issue_map = try DB.HashMap(.read_only).init(issue_cursor); 431 const issue_event = try evt.read(evt.Issue.Record, DB, hash_kind, arena, issue_map); 432 try issues.append(aa, .{ 433 .id = try aa.dupe(u8, &id_hex), 434 .issue = issue_event, 435 .author = try ui.Author.initFromEmail(admin_moment, arena, issue_event.author_email), 436 .conflicted = if (conflict_set) |cs| try cs.contains(&order_key) else false, 437 .comments = try Comment.loadWindow( 438 hash_kind, 439 arena, 440 admin_moment, 441 haxy_moment, 442 evt.Comment.thread_id_to_comment_id_set_key, 443 &id_hex, 444 if (std.mem.eql(u8, &id_hex, selected_id)) comments_start else 0, 445 ), 446 }); 447 } 448 449 return .{ 450 .issues = issues.items, 451 .prev_id = prev_id, 452 .next_id = next_id, 453 .count = @intCast(try set.count()), 454 }; 455 } 456 457 // the selected issue's conflict entry, shaped for the resolve view. `ours` is 458 // the live record. 459 fn readConflict( 460 comptime repo_kind: rp.RepoKind, 461 comptime repo_opts: rp.RepoOpts(repo_kind), 462 arena: *std.heap.ArenaAllocator, 463 repo: *rp.Repo(repo_kind, repo_opts), 464 io: std.Io, 465 admin_moment: ?evt.AdminDB.HashMap(.read_only), 466 haxy_moment: evt.EventDB(repo_opts.hash).HashMap(.read_only), 467 id_bytes: *const [evt.event_id_size]u8, 468 ours: evt.Issue.Record, 469 conflict_entry: evt.EventDB(repo_opts.hash).HashMap(.read_only), 470 ) !Conflict { 471 const DB = evt.EventDB(repo_opts.hash); 472 const aa = arena.allocator(); 473 const gpa = arena.child_allocator; 474 475 const fields_cursor = (try conflict_entry.getCursor(hash.hashInt(repo_opts.hash, evt.conflicted_fields_key))) orelse return error.NotFound; 476 const conflicted_fields = try fields_cursor.readBytesAlloc(aa, null); 477 478 const their_cursor = (try conflict_entry.getCursor(hash.hashInt(repo_opts.hash, evt.their_record_key))) orelse return error.NotFound; 479 const theirs = try evt.read(evt.Issue.Record, DB, repo_opts.hash, arena, try DB.HashMap(.read_only).init(their_cursor)); 480 481 // absent when both sides created the issue independently 482 var base: ?evt.Issue.Record = null; 483 if (try conflict_entry.getCursor(hash.hashInt(repo_opts.hash, evt.base_record_key))) |base_cursor| { 484 base = try evt.read(evt.Issue.Record, DB, repo_opts.hash, arena, try DB.HashMap(.read_only).init(base_cursor)); 485 } 486 487 // each side's field->oid map, for attributing the versions; a field a 488 // merge left unattributed reads as an unknown author 489 var their_field_oids: ?DB.SortedMap(.read_only) = null; 490 if (try conflict_entry.getCursor(hash.hashInt(repo_opts.hash, evt.their_field_to_oid_key))) |cursor| { 491 their_field_oids = try DB.SortedMap(.read_only).init(cursor); 492 } 493 var our_field_oids: ?DB.SortedMap(.read_only) = null; 494 if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.id_to_field_to_oid_key))) |map_cursor| { 495 const id_to_field_to_oid = try DB.HashMap(.read_only).init(map_cursor); 496 if (try id_to_field_to_oid.getCursor(hash.hashInt(repo_opts.hash, id_bytes))) |cursor| { 497 our_field_oids = try DB.SortedMap(.read_only).init(cursor); 498 } 499 } 500 501 var conflict = Conflict{}; 502 var field_iter = std.mem.splitScalar(u8, conflicted_fields, ' '); 503 while (field_iter.next()) |field| { 504 // status can't conflict (two changes of a two-value field agree) 505 const known = std.meta.stringToEnum(enum { title, tags, description }, field) orelse continue; 506 const our_author = try oidAuthor(repo_kind, repo_opts, arena, repo, io, admin_moment, try readFieldOid(repo_opts.hash, our_field_oids, field)); 507 const their_author = try oidAuthor(repo_kind, repo_opts, arena, repo, io, admin_moment, try readFieldOid(repo_opts.hash, their_field_oids, field)); 508 switch (known) { 509 .title => conflict.title = .{ 510 .ours = .{ .text = ours.event.title, .author = our_author }, 511 .theirs = .{ .text = theirs.event.title, .author = their_author }, 512 }, 513 .tags => conflict.tags = .{ 514 .ours = .{ .text = ours.event.tags, .author = our_author }, 515 .theirs = .{ .text = theirs.event.tags, .author = their_author }, 516 }, 517 .description => conflict.description = .{ 518 .chunks = try diff3.chunks(io, gpa, arena, if (base) |b| b.event.description else "", ours.event.description, theirs.event.description), 519 .ours_author = our_author, 520 .theirs_author = their_author, 521 }, 522 } 523 } 524 return conflict; 525 } 526 527 // the oid `field` maps to in a field->oid map, or null 528 fn readFieldOid( 529 comptime hash_kind: hash.HashKind, 530 field_oids_maybe: ?evt.EventDB(hash_kind).SortedMap(.read_only), 531 field: []const u8, 532 ) !?[hash.byteLen(hash_kind)]u8 { 533 const field_oids = field_oids_maybe orelse return null; 534 const cursor = (try field_oids.getCursor(field)) orelse return null; 535 var oid: [hash.byteLen(hash_kind)]u8 = undefined; 536 _ = try cursor.readBytes(&oid); 537 return oid; 538 } 539 540 // the author of the event commit `oid_maybe` names 541 fn oidAuthor( 542 comptime repo_kind: rp.RepoKind, 543 comptime repo_opts: rp.RepoOpts(repo_kind), 544 arena: *std.heap.ArenaAllocator, 545 repo: *rp.Repo(repo_kind, repo_opts), 546 io: std.Io, 547 admin_moment: ?evt.AdminDB.HashMap(.read_only), 548 oid_maybe: ?[hash.byteLen(repo_opts.hash)]u8, 549 ) !ui.Author { 550 const oid = oid_maybe orelse return .unknown; 551 const gpa = arena.child_allocator; 552 var start_oids = [_][hash.hexLen(repo_opts.hash)]u8{std.fmt.bytesToHex(oid, .lower)}; 553 var commit_iter = repo.log(io, gpa, start_oids[0..1]) catch return .unknown; 554 defer commit_iter.deinit(); 555 const commit_object = (commit_iter.next(gpa) catch return .unknown) orelse return .unknown; 556 defer commit_object.deinit(); 557 return try ui.Author.init(admin_moment, arena, commit_object.content.commit.metadata.author orelse ""); 558 } 559 560 pub const View = struct { 561 // a vertical box: the header tabs on top, then a stack holding a 562 // master-detail split (issue list + description pane) per status list, 563 // plus the tags view. 564 box: wgt.Box(ui.Widget), // vert: [header_index] = tabs, [stack_index] = stack 565 data: *const Self, 566 session: *ui.Session, 567 // per-split state, indexed like the stack's split children: the issue the 568 // pane shows, and its description and author text boxes' focus ids. 569 detailed_index: [stack_child_max]?usize, 570 description_id: [stack_child_max]?usize, 571 author_id: [stack_child_max]?usize, 572 573 const header_index: usize = 0; 574 const stack_index: usize = 1; 575 // indices within the stack, 1:1 with the header tabs. 576 const open_view_index: usize = 0; 577 const closed_view_index: usize = 1; 578 const tags_view_index: usize = 2; 579 // the new-issue form, or the edit or resolve form when the page was 580 // loaded at one of their urls. 581 const form_view_index: usize = 3; 582 // the conflicts split; the tab and stack child exist only when the repo 583 // has conflicted issues. 584 const conflicts_view_index: usize = 4; 585 const stack_child_max: usize = conflicts_view_index + 1; 586 // the leading stack children that are status splits; the conflicts split 587 // sits apart at conflicts_view_index. 588 const split_count: usize = 2; 589 // indices within a split (the horizontal box inside the stack). 590 const list_index: usize = 0; 591 const detail_index: usize = 1; 592 const list_max_width: usize = 40; 593 const detail_min_width: usize = 40; 594 // indices within the new-issue form. 595 const title_field_index: usize = 0; 596 const tags_field_index: usize = 1; 597 const description_field_index: usize = 2; 598 const submit_field_index: usize = 3; 599 600 fn viewIndex(view: ui.RoutablePage.IssuesView) usize { 601 return switch (view) { 602 .open => open_view_index, 603 .closed => closed_view_index, 604 .tags => tags_view_index, 605 .new, .edit, .resolve => form_view_index, 606 .conflicts => conflicts_view_index, 607 // init resolves a description url to its issue's status list 608 .description => unreachable, 609 }; 610 } 611 612 // the status a status split lists; the conflicts split has none (its 613 // issues carry their own). 614 fn splitStatus(index: usize) evt.Issue.Status { 615 return if (index == open_view_index) .open else .closed; 616 } 617 618 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 619 var outer = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 620 errdefer outer.deinit(allocator); 621 622 // the tabs at the top. 623 { 624 var hdr = try Header.init(allocator, session, data); 625 errdefer hdr.deinit(allocator); 626 try outer.children.put(allocator, hdr.getFocus().id, .{ .widget = .{ .repo_issues_header = hdr }, .rect = null, .min_size = null }); 627 } 628 629 // the stack enters `outer` before its children enter it, so an error 630 // frees each child exactly once. 631 { 632 var stack = try wgt.Stack(ui.Widget).init(allocator); 633 errdefer stack.deinit(allocator); 634 try outer.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 635 } 636 const stack = &outer.children.values()[stack_index].widget.stack; 637 638 // a master-detail split per status list. 639 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 640 var split = try initSplit(allocator, session, data, status); 641 errdefer split.deinit(allocator); 642 try stack.children.put(allocator, split.getFocus().id, .{ .box = split }); 643 } 644 645 // the tags view 646 { 647 var tf = try ui.TagFlow.init(allocator); 648 errdefer tf.deinit(allocator); 649 var items: std.ArrayList(ui.TagFlow.Item) = .empty; 650 defer items.deinit(allocator); 651 // when filtered, the first item clears the filter 652 if (data.tag.len != 0) 653 try items.append(allocator, .{ .text = "✕", .link = try issuesLink(session.page_arena, data.identity, .open, "", "") }); 654 for (data.tags) |tag| 655 try items.append(allocator, .{ .text = tag, .link = try tagLink(session.page_arena, data.identity, .open, tag) }); 656 try tf.setItems(allocator, items.items); 657 try stack.children.put(allocator, tf.getFocus().id, .{ .tag_flow = tf }); 658 } 659 660 // the new-issue form, or — on an edit or resolve url — that form in 661 // its place, prefilled with the selected issue's content. a 662 // logged-out session can't create events, so the unauthorized view 663 // stands in. 664 if (session.data.is_local or session.data.user_id != null) { 665 if (data.view == .resolve) { 666 // on the web the page grows to the form's height and the 667 // browser scrolls it; the terminal scrolls the form itself 668 var form_widget: ui.Widget = blk: { 669 var form = try initResolveForm(allocator, session, data); 670 errdefer form.deinit(allocator); 671 break :blk if (session.is_terminal) 672 .{ .scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = form }, .{ .direction = .vert }) } 673 else 674 .{ .box = form }; 675 }; 676 errdefer form_widget.deinit(allocator); 677 try stack.children.put(allocator, form_widget.getFocus().id, form_widget); 678 } else { 679 const aa = session.page_arena.allocator(); 680 const action = if (data.view == .edit) 681 (if (data.identity.len == 0) 682 try std.fmt.allocPrint(aa, "form:/issue:{s}/edit", .{data.selected_id}) 683 else 684 try std.fmt.allocPrint(aa, "form:/repo/{s}/issue:{s}/edit", .{ data.identity, data.selected_id })) 685 else if (data.identity.len == 0) 686 "form:/issue" 687 else 688 try std.fmt.allocPrint(aa, "form:/repo/{s}/issue", .{data.identity}); 689 const issue = if (data.view == .edit) 690 (if (data.selectedIssue()) |entry| &entry.issue else null) 691 else 692 null; 693 var form = try initIssueForm(allocator, session, action, issue); 694 errdefer form.deinit(allocator); 695 try stack.children.put(allocator, form.getFocus().id, .{ .box = form }); 696 } 697 } else { 698 var message = try ui.Unauthorized.View.init(allocator); 699 errdefer message.deinit(allocator); 700 try stack.children.put(allocator, message.getFocus().id, .{ .unauthorized = message }); 701 } 702 703 // the conflicts split; its tab exists only when the repo has 704 // conflicts, so skip the child too to keep the stack 1:1 with the 705 // tabs. 706 if (data.conflicts.count > 0) { 707 var split = try initSplit(allocator, session, data, null); 708 errdefer split.deinit(allocator); 709 try stack.children.put(allocator, split.getFocus().id, .{ .box = split }); 710 } 711 712 // the stack starts on the page's view. 713 stack.getFocus().child_id = stack.children.keys()[viewIndex(data.view)]; 714 715 // focus entering the view lands on the tabs first. 716 outer.getFocus().child_id = outer.children.keys()[header_index]; 717 718 return .{ 719 .box = outer, 720 .data = data, 721 .session = session, 722 .detailed_index = @splat(null), 723 .description_id = @splat(null), 724 .author_id = @splat(null), 725 }; 726 } 727 728 // the master-detail split showing `status`'s window, or the conflicts 729 // window when null. 730 fn initSplit(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self, status_maybe: ?evt.Issue.Status) !wgt.Box(ui.Widget) { 731 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 732 errdefer box.deinit(allocator); 733 734 const win = if (status_maybe) |status| data.window(status) else &data.conflicts; 735 736 // the issue list (one focusable row per title), plus a "next" link that 737 // reloads the page rooted at the following issue. 738 { 739 var list_scroll = blk: { 740 var list_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert, .stretch = true }); 741 errdefer list_box.deinit(allocator); 742 if (win.prev_id) |prev| 743 try addRow(allocator, &list_box, "← previous", "", try windowLink(session.page_arena, data, status_maybe, prev)); 744 for (win.issues) |entry| { 745 // conflicts take precedence over the comment count 746 const label: []const u8 = if (entry.conflicted and status_maybe != null) 747 " conflict " 748 else if (entry.comments.count > 0) 749 try std.fmt.allocPrint(session.page_arena.allocator(), " {d} comments ", .{entry.comments.count}) 750 else 751 ""; 752 try addRow(allocator, &list_box, entry.issue.event.title, label, try issueRowLink(session.page_arena, data.identity, entry.id)); 753 } 754 if (win.next_id) |next| 755 try addRow(allocator, &list_box, "next →", "", try windowLink(session.page_arena, data, status_maybe, next)); 756 // select the window's first issue (past a leading "previous" 757 // row) so its description shows on load. 758 if (win.issues.len > 0) 759 list_box.getFocus().child_id = list_box.children.keys()[if (win.prev_id != null) 1 else 0] 760 else if (list_box.children.count() > 0) 761 list_box.getFocus().child_id = list_box.children.keys()[0]; 762 break :blk try wgt.Scroll(ui.Widget).init(allocator, .{ .box = list_box }, .{ .direction = .vert, .web_native = !session.is_terminal }); 763 }; 764 errdefer list_scroll.deinit(allocator); 765 try box.children.put(allocator, list_scroll.getFocus().id, .{ .widget = .{ .scroll = list_scroll }, .rect = null, .min_size = .{ .width = list_max_width, .height = null }, .max_size = .{ .width = list_max_width, .height = null } }); 766 } 767 768 // the detail pane — a frame around a scroll of the description 769 { 770 var detail_outer = blk: { 771 var detail_scroll = blk2: { 772 var detail_inner = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 773 errdefer detail_inner.deinit(allocator); 774 // fill the pane (content top-left, scroll bar pinned to the 775 // edge) rather than shrinking to the description. 776 break :blk2 try wgt.Scroll(ui.Widget).init(allocator, .{ .box = detail_inner }, .{ .direction = .vert, .web_native = !session.is_terminal, .fill = true }); 777 }; 778 errdefer detail_scroll.deinit(allocator); 779 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = .hidden, .direction = .vert }); 780 errdefer frame.deinit(allocator); 781 // the tool row sits above the scroll (populateDetail fills 782 // it per issue) so it can't scroll out from under the web 783 // overlay <form>, whose position doesn't track pane scrolling. 784 { 785 var row = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 786 errdefer row.deinit(allocator); 787 try frame.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 788 } 789 // the frame's selected child is its scroll, so the focus chain 790 // reaches the description (populateDetail points the scroll's 791 // inner box at it), letting focus recovery descend into the pane. 792 frame.getFocus().child_id = detail_scroll.getFocus().id; 793 try frame.children.put(allocator, detail_scroll.getFocus().id, .{ .widget = .{ .scroll = detail_scroll }, .rect = null, .min_size = null }); 794 break :blk frame; 795 }; 796 errdefer detail_outer.deinit(allocator); 797 try box.children.put(allocator, detail_outer.getFocus().id, .{ .widget = .{ .box = detail_outer }, .rect = null, .min_size = .{ .width = detail_min_width, .height = null } }); 798 } 799 800 box.getFocus().child_id = box.children.keys()[list_index]; 801 return box; 802 } 803 804 // an issue form: title/tags/description inputs and a submit button, 805 // prefilled from `issue` when given. its form: subtree makes the web 806 // overlay wrap them in a <form> POSTing to `action`'s route. 807 fn initIssueForm(allocator: std.mem.Allocator, session: *ui.Session, action: []const u8, issue: ?*const evt.Issue.Record) !wgt.Box(ui.Widget) { 808 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 809 errdefer box.deinit(allocator); 810 box.getFocus().kind = .{ .custom = action }; 811 812 { 813 var title = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " title ", .name = "title", .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal }); 814 errdefer title.deinit(allocator); 815 title.getFocus().focusable = true; 816 if (issue) |i| try title.setContent(allocator, i.event.title); 817 try box.children.put(allocator, title.getFocus().id, .{ .widget = .{ .text_input = title }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 818 } 819 820 { 821 var tags = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " tags (separate with spaces) ", .name = "tags", .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal }); 822 errdefer tags.deinit(allocator); 823 tags.getFocus().focusable = true; 824 if (issue) |i| try tags.setContent(allocator, i.event.tags); 825 try box.children.put(allocator, tags.getFocus().id, .{ .widget = .{ .text_input = tags }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 826 } 827 828 { 829 var description = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " description ", .name = "description", .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal, .multiline = true, .scroll = .{ .fill = true } }); 830 errdefer description.deinit(allocator); 831 description.getFocus().focusable = true; 832 if (issue) |i| try description.setContent(allocator, i.event.description); 833 try box.children.put(allocator, description.getFocus().id, .{ .widget = .{ .text_input = description }, .rect = null, .min_size = null }); 834 } 835 836 try addSubmitButton(allocator, &box); 837 838 box.getFocus().child_id = box.children.keys()[title_field_index]; 839 return box; 840 } 841 842 // a form's submit button, then a spacer absorbing the leftover 843 // min-height the box hands its last child, so the button keeps its 844 // natural height 845 fn addSubmitButton(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget)) !void { 846 { 847 var submit = try ui.SubmitButton.init(allocator); 848 errdefer submit.deinit(allocator); 849 try box.children.put(allocator, submit.getFocus().id, .{ .widget = .{ .submit_button = submit }, .rect = null, .min_size = .{ .width = null, .height = 3 } }); 850 } 851 { 852 var spacer = try ui.Spacer.init(allocator); 853 errdefer spacer.deinit(allocator); 854 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 855 } 856 } 857 858 // the conflict resolve form. the "use this" links are navigations that 859 // flip the url's theirs: pick, reloading the prefills; one submit 860 // settles every conflict. the form: subtree makes the web overlay POST 861 // to the resolve route. 862 fn initResolveForm(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !wgt.Box(ui.Widget) { 863 const aa = session.page_arena.allocator(); 864 // init only picks the resolve view once it has read the conflict 865 const conflict = if (data.conflict) |*c| c else unreachable; 866 867 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 868 errdefer box.deinit(allocator); 869 box.getFocus().kind = .{ .custom = if (data.identity.len == 0) 870 try std.fmt.allocPrint(aa, "form:/issue:{s}/resolve", .{data.selected_id}) 871 else 872 try std.fmt.allocPrint(aa, "form:/repo/{s}/issue:{s}/resolve", .{ data.identity, data.selected_id }) }; 873 874 if (conflict.title) |*fc| { 875 try addLabel(allocator, &box, "title conflict:"); 876 try addFieldConflict(allocator, &box, session, data, "title", fc); 877 } 878 if (conflict.tags) |*fc| { 879 try addLabel(allocator, &box, "tags conflict:"); 880 try addFieldConflict(allocator, &box, session, data, "tags", fc); 881 } 882 883 if (conflict.description) |*desc| { 884 try addLabel(allocator, &box, "description conflict:"); 885 var hunk_index: usize = 0; 886 for (desc.chunks, 0..) |*chunk, chunk_index| { 887 switch (chunk.*) { 888 .same => |text| { 889 var tb = try wgt.TextBox(ui.Widget).init(allocator, text, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word }); 890 errdefer tb.deinit(allocator); 891 tb.getFocus().focusable = true; 892 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 893 }, 894 // an auto-resolved chunk: only one side changed it, so its 895 // version stands, shown distinctly with its author 896 .auto => |auto| { 897 const author = if (auto.theirs) desc.theirs_author else desc.ours_author; 898 const verb: []const u8 = if (auto.text == null) "removed" else "edited"; 899 const label = switch (author) { 900 .user_name, .email => |name| try std.fmt.allocPrint(aa, " {s} by {s} ", .{ verb, name }), 901 .unknown => try std.fmt.allocPrint(aa, " {s} by {s} ", .{ verb, if (auto.theirs) @as([]const u8, "them") else "us" }), 902 }; 903 var tb = try wgt.TextBox(ui.Widget).init(allocator, auto.text orelse "(removed)", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word, .label = label }); 904 errdefer tb.deinit(allocator); 905 tb.getFocus().focusable = true; 906 try box.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 907 }, 908 .conflict => |hunk| { 909 // a blank row on each side sets the group apart from 910 // the flowing shared and auto-resolved chunks 911 if (chunk_index > 0) try addGap(allocator, &box); 912 const name = try std.fmt.allocPrint(aa, "d{d}", .{hunk_index}); 913 hunk_index += 1; 914 const picked_theirs = data.theirsPicked(name); 915 try addVersionRow(allocator, &box, try sideLabel(aa, desc.ours_author, true), hunk.ours orelse "", try useThisLink(session, data, name, false)); 916 try addVersionRow(allocator, &box, try sideLabel(aa, desc.theirs_author, false), hunk.theirs orelse "", try useThisLink(session, data, name, true)); 917 var resolution_input = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " resolution ", .name = name, .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal, .multiline = true }); 918 errdefer resolution_input.deinit(allocator); 919 resolution_input.getFocus().focusable = true; 920 try resolution_input.setContent(allocator, (if (picked_theirs) hunk.theirs else hunk.ours) orelse ""); 921 try box.children.put(allocator, resolution_input.getFocus().id, .{ .widget = .{ .text_input = resolution_input }, .rect = null, .min_size = null }); 922 if (chunk_index + 1 < desc.chunks.len) try addGap(allocator, &box); 923 }, 924 } 925 } 926 } 927 928 try addSubmitButton(allocator, &box); 929 930 box.getFocus().child_id = box.children.keys()[0]; 931 return box; 932 } 933 934 // one conflicted scalar field: both sides' version rows, then the 935 // resolution input prefilled from the picked side. 936 fn addFieldConflict(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), session: *ui.Session, data: *const Self, comptime name: []const u8, fc: *const FieldConflict) !void { 937 const aa = session.page_arena.allocator(); 938 try addVersionRow(allocator, box, try sideLabel(aa, fc.ours.author, true), fc.ours.text, try useThisLink(session, data, name, false)); 939 try addVersionRow(allocator, box, try sideLabel(aa, fc.theirs.author, false), fc.theirs.text, try useThisLink(session, data, name, true)); 940 941 var resolution_input = try wgt.TextInput(ui.Widget).init(allocator, .{ .label = " resolution ", .name = name, .visible_width = null, .rounded_corners = true, .render_content = session.is_terminal }); 942 errdefer resolution_input.deinit(allocator); 943 resolution_input.getFocus().focusable = true; 944 try resolution_input.setContent(allocator, if (data.theirsPicked(name)) fc.theirs.text else fc.ours.text); 945 try box.children.put(allocator, resolution_input.getFocus().id, .{ .widget = .{ .text_input = resolution_input }, .rect = null, .min_size = null }); 946 } 947 948 // a blank row setting a conflict group apart from its neighbors 949 fn addGap(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget)) !void { 950 var text = try wgt.Text(ui.Widget).init(allocator, " "); 951 errdefer text.deinit(allocator); 952 try box.children.put(allocator, text.getFocus().id, .{ .widget = .{ .text = text }, .rect = null, .min_size = null }); 953 } 954 955 fn addLabel(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), content: []const u8) !void { 956 var label = try ui.SectionLabel.init(allocator, content); 957 errdefer label.deinit(allocator); 958 try box.children.put(allocator, label.getFocus().id, .{ .widget = .{ .section_label = label }, .rect = null, .min_size = null }); 959 } 960 961 // one side of a conflict: the "use this" link on the left, the version 962 // itself as a labeled read-only box. 963 fn addVersionRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), label: []const u8, text: []const u8, link: []const u8) !void { 964 var row = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 965 errdefer row.deinit(allocator); 966 967 { 968 const use_label = "use this"; 969 var use = try wgt.TextBox(ui.Widget).init(allocator, use_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 970 errdefer use.deinit(allocator); 971 use.getFocus().focusable = true; 972 use.getFocus().kind = .{ .custom = link }; 973 try row.children.put(allocator, use.getFocus().id, .{ 974 .widget = .{ .text_box = use }, 975 .rect = null, 976 .min_size = .{ .width = use_label.len + 2, .height = null }, 977 .max_size = .{ .width = use_label.len + 2, .height = null }, 978 }); 979 } 980 981 { 982 var tb = try wgt.TextBox(ui.Widget).init(allocator, if (text.len > 0) text else "(removed)", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word, .label = label }); 983 errdefer tb.deinit(allocator); 984 tb.getFocus().focusable = true; 985 try row.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 986 } 987 988 row.getFocus().child_id = row.children.keys()[0]; 989 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 990 } 991 992 // the label of one side's version box, naming its author 993 fn sideLabel(aa: std.mem.Allocator, author: ui.Author, ours: bool) ![]const u8 { 994 return switch (author) { 995 .user_name, .email => |name| try std.fmt.allocPrint(aa, " edited by {s} ", .{name}), 996 .unknown => if (ours) " current version " else " their version ", 997 }; 998 } 999 1000 // the a: link that reloads the resolve page with `name` picked from ours 1001 // or theirs, reprefilling its resolution input 1002 fn useThisLink(session: *ui.Session, data: *const Self, name: []const u8, theirs: bool) ![]const u8 { 1003 const aa = session.page_arena.allocator(); 1004 var picks: std.ArrayList(u8) = .empty; 1005 var it = std.mem.splitScalar(u8, data.theirs_picks, ','); 1006 while (it.next()) |pick| { 1007 if (pick.len == 0 or std.mem.eql(u8, pick, name)) continue; 1008 if (picks.items.len > 0) try picks.append(aa, ','); 1009 try picks.appendSlice(aa, pick); 1010 } 1011 if (theirs) { 1012 if (picks.items.len > 0) try picks.append(aa, ','); 1013 try picks.appendSlice(aa, name); 1014 } 1015 const route = ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, picks.items) orelse return error.RouteTooLong; 1016 return std.fmt.allocPrint(aa, "a:{s}", .{try route.toUrl(session.page_arena)}); 1017 } 1018 1019 // the resolve form's page-constant initial value for the input `name`: 1020 // the picked side of its conflicted field or hunk 1021 fn resolvePrefill(self: *View, name: []const u8) ?[]const u8 { 1022 const conflict = if (self.data.conflict) |*c| c else return null; 1023 const theirs = self.data.theirsPicked(name); 1024 if (std.mem.eql(u8, name, "title")) { 1025 const fc = if (conflict.title) |*f| f else return null; 1026 return if (theirs) fc.theirs.text else fc.ours.text; 1027 } 1028 if (std.mem.eql(u8, name, "tags")) { 1029 const fc = if (conflict.tags) |*f| f else return null; 1030 return if (theirs) fc.theirs.text else fc.ours.text; 1031 } 1032 if (std.mem.startsWith(u8, name, "d")) { 1033 const desc = if (conflict.description) |*d| d else return null; 1034 const hunk_index = std.fmt.parseInt(usize, name[1..], 10) catch return null; 1035 var seen: usize = 0; 1036 for (desc.chunks) |chunk| switch (chunk) { 1037 .conflict => |hunk| { 1038 if (seen == hunk_index) return (if (theirs) hunk.theirs else hunk.ours) orelse ""; 1039 seen += 1; 1040 }, 1041 else => {}, 1042 }; 1043 } 1044 return null; 1045 } 1046 1047 fn addRow(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), text: []const u8, bottom_label: []const u8, link: []const u8) !void { 1048 var row = try wgt.TextBox(ui.Widget).init(allocator, text, .{ .border_style = .hidden, .rounded_corners = true, .wrap_kind = .word, .bottom_label = bottom_label }); 1049 errdefer row.deinit(allocator); 1050 row.getFocus().focusable = true; 1051 if (link.len != 0) row.getFocus().kind = .{ .custom = link }; 1052 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .text_box = row }, .rect = null, .min_size = null, .max_size = .{ .width = null, .height = 5 } }); 1053 } 1054 1055 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 1056 self.box.deinit(allocator); 1057 } 1058 1059 fn header(self: *View) *Header { 1060 return &self.box.children.values()[header_index].widget.repo_issues_header; 1061 } 1062 1063 fn viewStack(self: *View) *wgt.Stack(ui.Widget) { 1064 return &self.box.children.values()[stack_index].widget.stack; 1065 } 1066 1067 // `index`'s master-detail split inside the stack. 1068 fn resultsBox(self: *View, index: usize) *wgt.Box(ui.Widget) { 1069 return &self.viewStack().children.values()[index].box; 1070 } 1071 1072 // the tags view's flow inside the stack. 1073 fn tagsView(self: *View) *ui.TagFlow { 1074 return &self.viewStack().children.values()[tags_view_index].tag_flow; 1075 } 1076 1077 // the new-issue, edit, or resolve form inside the stack, or null when the 1078 // unauthorized view stands in for it. 1079 fn issueForm(self: *View) ?*wgt.Box(ui.Widget) { 1080 return switch (self.viewStack().children.values()[form_view_index]) { 1081 .box => |*box| box, 1082 // the resolve form sits inside a scroll on the terminal 1083 .scroll => |*scroll| &scroll.child.box, 1084 else => null, 1085 }; 1086 } 1087 1088 // the resolve form's scroll on the terminal (the web page scrolls itself) 1089 fn resolveScroll(self: *View) ?*wgt.Scroll(ui.Widget) { 1090 return switch (self.viewStack().children.values()[form_view_index]) { 1091 .scroll => |*scroll| scroll, 1092 else => null, 1093 }; 1094 } 1095 1096 fn listScroll(self: *View, index: usize) *wgt.Scroll(ui.Widget) { 1097 return &self.resultsBox(index).children.values()[list_index].widget.scroll; 1098 } 1099 1100 fn listBox(self: *View, index: usize) *wgt.Box(ui.Widget) { 1101 return &self.listScroll(index).child.box; 1102 } 1103 1104 // the detail frame's children: the tool row above the scroll pane. 1105 const tool_row_index: usize = 0; 1106 const detail_scroll_index: usize = 1; 1107 1108 fn detailOuter(self: *View, index: usize) *wgt.Box(ui.Widget) { 1109 return &self.resultsBox(index).children.values()[detail_index].widget.box; 1110 } 1111 1112 fn toolRow(self: *View, index: usize) *wgt.Box(ui.Widget) { 1113 return &self.detailOuter(index).children.values()[tool_row_index].widget.box; 1114 } 1115 1116 fn detailScroll(self: *View, index: usize) *wgt.Scroll(ui.Widget) { 1117 return &self.detailOuter(index).children.values()[detail_scroll_index].widget.scroll; 1118 } 1119 1120 fn detailInner(self: *View, index: usize) *wgt.Box(ui.Widget) { 1121 return &self.detailScroll(index).child.box; 1122 } 1123 1124 fn window(self: *View, index: usize) *const Window { 1125 if (index == conflicts_view_index) return &self.data.conflicts; 1126 return self.data.window(splitStatus(index)); 1127 } 1128 1129 fn stackSelectedIndex(self: *View) ?usize { 1130 const stack = self.viewStack(); 1131 const cid = stack.getFocus().child_id orelse return null; 1132 return stack.children.getIndex(cid); 1133 } 1134 1135 // the stack's selected master-detail split (null when the tags view or the 1136 // new-issue form shows). 1137 fn selectedSplitIndex(self: *View) ?usize { 1138 const idx = self.stackSelectedIndex() orelse return null; 1139 return if (idx < split_count or idx == conflicts_view_index) idx else null; 1140 } 1141 1142 fn detailActive(self: *View, index: usize) bool { 1143 const rb = self.resultsBox(index); 1144 const cid = rb.getFocus().child_id orelse return false; 1145 return rb.children.getIndex(cid) == detail_index; 1146 } 1147 1148 fn headerActive(self: *View) bool { 1149 const cid = self.box.getFocus().child_id orelse return false; 1150 return self.box.children.getIndex(cid) == header_index; 1151 } 1152 1153 fn tagsViewActive(self: *View) bool { 1154 if (self.headerActive()) return false; 1155 return self.stackSelectedIndex() == tags_view_index; 1156 } 1157 1158 fn formViewActive(self: *View) bool { 1159 if (self.headerActive()) return false; 1160 return self.stackSelectedIndex() == form_view_index; 1161 } 1162 1163 // the selected issue's index, or null when a window-navigation row is 1164 // selected (a leading "previous" row shifts the issue rows down by one). 1165 fn selectedIssueIndex(self: *View, index: usize) ?usize { 1166 const lb = self.listBox(index); 1167 const cid = lb.getFocus().child_id orelse return null; 1168 const idx = lb.children.getIndex(cid) orelse return null; 1169 const win = self.window(index); 1170 const lead: usize = if (win.prev_id != null) 1 else 0; 1171 if (idx < lead or idx - lead >= win.issues.len) return null; 1172 return idx - lead; 1173 } 1174 1175 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1176 self.clearGrid(); 1177 1178 // each header tab maps 1:1 to a stack child by position. mirror the 1179 // selection into the url: the view the page's window is rooted at 1180 // keeps its rooted url, the others get their list route (keeping the 1181 // tag filter). 1182 if (self.header().getSelectedIndex()) |index| { 1183 const stack = self.viewStack(); 1184 stack.getFocus().child_id = stack.children.keys()[index]; 1185 self.session.data.current_page = (if (index == form_view_index) 1186 (switch (self.data.view) { 1187 .edit => ui.RoutablePage.repoIssuesEditRoute(self.data.identity, self.data.selected_id), 1188 .resolve => ui.RoutablePage.repoIssuesResolveRoute(self.data.identity, self.data.selected_id, self.data.theirs_picks), 1189 else => ui.RoutablePage.repoIssuesNewRoute(self.data.identity), 1190 }) 1191 else if (index == conflicts_view_index) 1192 ui.RoutablePage.repoIssuesConflictsRoute(self.data.identity, if (self.data.view == .conflicts) self.data.selected_id else "") 1193 else if (index == viewIndex(self.data.view) and self.data.selected_id.len != 0) 1194 (if (self.data.description_page) 1195 ui.RoutablePage.repoIssuesDescriptionRoute(self.data.identity, self.data.selected_id) 1196 else if (self.data.comment_page) |page| 1197 ui.RoutablePage.repoCommentsRoute(self.data.identity, self.data.selected_id, page.selected.id, page.replies.start) 1198 else 1199 ui.RoutablePage.repoIssueCommentsRoute(self.data.identity, self.data.selected_id, self.data.comments_start)) 1200 else if (index == tags_view_index) 1201 ui.RoutablePage.repoIssuesTagsRoute(self.data.identity, self.data.tag) 1202 else 1203 ui.RoutablePage.repoIssuesRoute(self.data.identity, splitStatus(index), self.data.tag, "")) orelse self.session.data.current_page; 1204 } 1205 1206 if (self.selectedSplitIndex()) |i| { 1207 // swap the detail pane to the selected issue when it changes. 1208 try self.refreshDetail(allocator, i); 1209 1210 // mirror the focused issue into the url, but only while focus is 1211 // inside the split. an issue's url is the same whether or not the 1212 // list is filtered, so the mirror drops the tag. 1213 if (root_focus.grandchild_id) |g| { 1214 if (self.resultsBox(i).getFocus().children.contains(g)) { 1215 if (self.selectedIssueIndex(i)) |sel| { 1216 // selecting another issue leaves the description page 1217 // behind, like it leaves the tag filter behind. 1218 const entry = &self.window(i).issues[sel]; 1219 const mirrored = if (self.data.description_page and std.mem.eql(u8, entry.id, self.data.selected_id)) 1220 ui.RoutablePage.repoIssuesDescriptionRoute(self.data.identity, entry.id) 1221 else if (self.data.comment_page) |page| 1222 if (std.mem.eql(u8, entry.id, self.data.selected_id)) 1223 ui.RoutablePage.repoCommentsRoute(self.data.identity, entry.id, page.selected.id, page.replies.start) 1224 else 1225 ui.RoutablePage.repoIssueCommentsRoute(self.data.identity, entry.id, 0) 1226 else if (std.mem.eql(u8, entry.id, self.data.selected_id)) 1227 ui.RoutablePage.repoIssueCommentsRoute(self.data.identity, entry.id, entry.comments.start) 1228 else 1229 ui.RoutablePage.repoIssueCommentsRoute(self.data.identity, entry.id, 0); 1230 if (mirrored) |route| self.session.data.current_page = route; 1231 } 1232 } 1233 } 1234 1235 // the selected list row shows a border (the focused TextBox 1236 // upgrades it to a double border itself); the rest stay borderless. 1237 const lb = self.listBox(i); 1238 for (lb.children.keys(), lb.children.values()) |id, *child| { 1239 switch (child.widget) { 1240 .text_box => |*tb| tb.options.border_style = if (lb.getFocus().child_id == id) .single else .hidden, 1241 else => {}, 1242 } 1243 } 1244 1245 // the pane's selected child shows the selection border: the 1246 // description directly, the tags via the flow's selected item. 1247 // cap the list at list_max_width only while the detail pane fits 1248 // beside it. the box drops the detail when the width can't hold 1249 // both minimums, so when it's that narrow we lift the cap and let 1250 // the list fill the whole width. 1251 const both_panes_fit = if (constraint.max_size.width) |w| w >= list_max_width + detail_min_width else true; 1252 self.resultsBox(i).children.values()[list_index].max_size = if (both_panes_fit) .{ .width = list_max_width, .height = null } else null; 1253 1254 // stretch the detail pane across the rest of the width so it fills 1255 // the area rather than shrinking to its content; its scroll fills 1256 // the pane. 1257 if (constraint.max_size.width) |w| { 1258 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = if (both_panes_fit) w - list_max_width else w, .height = null }; 1259 } else { 1260 self.resultsBox(i).children.values()[detail_index].min_size = .{ .width = detail_min_width, .height = null }; 1261 } 1262 } 1263 1264 // refresh the form inputs' entries in the session's focus-id -> input 1265 // map with this frame's addresses, so the web/wasm form handling can 1266 // find them by focus id 1267 if (self.issueForm()) |form| { 1268 const inputs_arena = self.session.arena.allocator(); 1269 for (form.children.values()) |*child| switch (child.widget) { 1270 .text_input => |*ti| try self.session.text_inputs.put(inputs_arena, ti.getFocus().id, ti), 1271 else => {}, 1272 }; 1273 1274 // on an edit page, register the issue's content as the inputs' 1275 // page-constant initial values, which the web overlay renders 1276 // into them. 1277 if (self.data.view == .edit) { 1278 if (self.data.selectedIssue()) |entry| { 1279 const fields = form.children.values(); 1280 try self.session.input_values.put(inputs_arena, fields[title_field_index].widget.text_input.getFocus().id, entry.issue.event.title); 1281 try self.session.input_values.put(inputs_arena, fields[tags_field_index].widget.text_input.getFocus().id, entry.issue.event.tags); 1282 try self.session.input_values.put(inputs_arena, fields[description_field_index].widget.text_input.getFocus().id, entry.issue.event.description); 1283 } 1284 } 1285 1286 // the resolve form's inputs prefill from the picked side, which 1287 // is url state and so page-constant like the edit values above 1288 if (self.data.view == .resolve) { 1289 for (form.children.values()) |*child| switch (child.widget) { 1290 .text_input => |*ti| if (self.resolvePrefill(ti.options.name)) |value| { 1291 try self.session.input_values.put(inputs_arena, ti.getFocus().id, value); 1292 }, 1293 else => {}, 1294 }; 1295 } 1296 } 1297 1298 try self.box.build(allocator, constraint, root_focus); 1299 } 1300 1301 fn refreshDetail(self: *View, allocator: std.mem.Allocator, index: usize) !void { 1302 const sel = self.selectedIssueIndex(index) orelse return; 1303 if (self.detailed_index[index]) |d| if (d == sel) return; 1304 try self.populateDetail(allocator, index, sel); 1305 self.detailed_index[index] = sel; 1306 } 1307 1308 fn populateDetail(self: *View, allocator: std.mem.Allocator, index: usize, sel: usize) !void { 1309 const entry = self.window(index).issues[sel]; 1310 const inner = self.detailInner(index); 1311 // the /description page replaces its issue's detail with a back link 1312 // and the whole description; other issues keep their normal detail. 1313 const description_page = self.data.description_page and std.mem.eql(u8, entry.id, self.data.selected_id); 1314 const comment_page = if (std.mem.eql(u8, entry.id, self.data.selected_id)) self.data.comment_page else null; 1315 1316 for (inner.children.values()) |*child| child.widget.deinit(allocator); 1317 inner.children.clearAndFree(allocator); 1318 inner.getFocus().child_id = null; 1319 self.author_id[index] = null; 1320 1321 // the tool row: the open/close and edit buttons; the description page 1322 // shows none. 1323 { 1324 const row = self.toolRow(index); 1325 for (row.children.values()) |*child| child.widget.deinit(allocator); 1326 row.children.clearAndFree(allocator); 1327 row.getFocus().child_id = null; 1328 row.getFocus().kind = .container; 1329 } 1330 if (!description_page and comment_page == null) { 1331 const row = self.toolRow(index); 1332 const pa = self.session.page_arena.allocator(); 1333 1334 { 1335 var spacer = try ui.Spacer.init(allocator); 1336 errdefer spacer.deinit(allocator); 1337 try row.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1338 } 1339 1340 // a conflicted issue's only action is resolving it. the button 1341 // stays visible logged out; the resolve page shows the 1342 // unauthorized view then. 1343 if (entry.conflicted) { 1344 const label = "resolve conflict"; 1345 var button = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1346 errdefer button.deinit(allocator); 1347 button.getFocus().focusable = true; 1348 const route = ui.RoutablePage.repoIssuesResolveRoute(self.data.identity, entry.id, "") orelse return error.RouteTooLong; 1349 button.getFocus().kind = .{ .custom = try std.fmt.allocPrint(pa, "a:{s}", .{try route.toUrl(self.session.page_arena)}) }; 1350 try row.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = .{ .width = label.len + 2, .height = null } }); 1351 } else { 1352 // a logged-out session can't flip the status, so it gets no 1353 // open/close button (and no form action on the row) 1354 if (self.session.data.is_local or self.session.data.user_id != null) { 1355 const action: []const u8 = switch (entry.issue.event.status) { 1356 .open => "close", 1357 .closed => "open", 1358 }; 1359 row.getFocus().kind = .{ .custom = if (self.data.identity.len == 0) 1360 try std.fmt.allocPrint(pa, "form:/issue:{s}/{s}", .{ entry.id, action }) 1361 else 1362 try std.fmt.allocPrint(pa, "form:/repo/{s}/issue:{s}/{s}", .{ self.data.identity, entry.id, action }) }; 1363 1364 var button = try wgt.TextBox(ui.Widget).init(allocator, action, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1365 errdefer button.deinit(allocator); 1366 button.getFocus().focusable = true; 1367 // the renderer distinguishes plain clickables from buttons that 1368 // should POST to a server route by this kind. 1369 button.getFocus().kind = .{ .custom = "submit" }; 1370 try row.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = .{ .width = action.len + 2, .height = null } }); 1371 } 1372 1373 // the edit button links to the issue's edit page. 1374 { 1375 var button = try wgt.TextBox(ui.Widget).init(allocator, "edit", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1376 errdefer button.deinit(allocator); 1377 button.getFocus().focusable = true; 1378 const route = ui.RoutablePage.repoIssuesEditRoute(self.data.identity, entry.id) orelse return error.RouteTooLong; 1379 button.getFocus().kind = .{ .custom = try std.fmt.allocPrint(pa, "a:{s}", .{try route.toUrl(self.session.page_arena)}) }; 1380 try row.children.put(allocator, button.getFocus().id, .{ .widget = .{ .text_box = button }, .rect = null, .min_size = .{ .width = "edit".len + 2, .height = null } }); 1381 } 1382 } 1383 1384 // the resolve button on a conflicted issue, else the open/close 1385 // button when present, the edit button otherwise 1386 row.getFocus().child_id = row.children.keys()[button_in_row_index]; 1387 } 1388 1389 if (comment_page) |page| { 1390 var back = try Comment.linkBox(allocator, self.session, "← back to issue", ui.RoutablePage.repoIssueCommentsRoute(self.data.identity, entry.id, 0) orelse return error.RouteTooLong); 1391 errdefer back.deinit(allocator); 1392 try inner.children.put(allocator, back.getFocus().id, .{ .widget = .{ .text_box = back }, .rect = null, .min_size = null }); 1393 1394 try Comment.appendComment(allocator, inner, self.session, self.data.identity, page.selected); 1395 try Comment.appendCount(allocator, inner, page.replies.count, "reply", "replies", self.session.page_arena.allocator()); 1396 for (page.replies.comments) |comment| try Comment.appendComment(allocator, inner, self.session, self.data.identity, comment); 1397 try Comment.appendWindowNav(allocator, inner, self.session, self.data.identity, page.thread_id, page.selected.id, page.replies); 1398 1399 var spacer = try ui.Spacer.init(allocator); 1400 errdefer spacer.deinit(allocator); 1401 try inner.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1402 1403 inner.getFocus().child_id = inner.children.keys()[0]; 1404 const sc = self.detailScroll(index); 1405 sc.x = 0; 1406 sc.y = 0; 1407 sc.getFocus().version +%= 1; 1408 return; 1409 } 1410 1411 if (description_page) { 1412 // the back link, in the title slot so the pane's input handling 1413 // applies to it unchanged. 1414 var tb = try wgt.TextBox(ui.Widget).init(allocator, "← back to issue", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1415 errdefer tb.deinit(allocator); 1416 tb.getFocus().focusable = true; 1417 tb.getFocus().kind = .{ .custom = try issuesLink(self.session.page_arena, self.data.identity, entry.issue.event.status, "", entry.id) }; 1418 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1419 } else { 1420 // the issue's title as a focusable word-wrapped text box. 1421 { 1422 var tb = try wgt.TextBox(ui.Widget).init(allocator, entry.issue.event.title, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word, .label = " title " }); 1423 errdefer tb.deinit(allocator); 1424 tb.getFocus().focusable = true; 1425 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1426 } 1427 1428 self.author_id[index] = blk: { 1429 var tb = try ui.authorBox(allocator, self.session.page_arena, entry.author); 1430 errdefer tb.deinit(allocator); 1431 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1432 break :blk tb.getFocus().id; 1433 }; 1434 1435 // the issue's tags, each linking to this status's list filtered to 1436 // that tag. 1437 { 1438 var items: std.ArrayList(ui.TagFlow.Item) = .empty; 1439 defer items.deinit(allocator); 1440 var tag_iter = evt.Issue.tagIterator(entry.issue.event.tags); 1441 while (tag_iter.next()) |tag| { 1442 if (tag.len == 0) continue; 1443 try items.append(allocator, .{ .text = tag, .link = try tagLink(self.session.page_arena, self.data.identity, entry.issue.event.status, tag) }); 1444 } 1445 if (items.items.len > 0) { 1446 var tf = try ui.TagFlow.init(allocator); 1447 errdefer tf.deinit(allocator); 1448 try tf.setItems(allocator, items.items); 1449 try inner.children.put(allocator, tf.getFocus().id, .{ .widget = .{ .tag_flow = tf }, .rect = null, .min_size = null }); 1450 } 1451 } 1452 } 1453 1454 // the description as a focusable word-wrapped text box. past the limit 1455 // it's cut at the last whole line and links to the /description page, 1456 // which shows the whole thing. 1457 self.description_id[index] = blk: { 1458 const whole = entry.issue.event.description; 1459 const cut_short = !description_page and whole.len > max_description_size; 1460 const shown = if (cut_short) 1461 std.mem.trimEnd(u8, whole[0 .. std.mem.lastIndexOfScalar(u8, whole[0..max_description_size], '\n') orelse 0], " \t\r\n") 1462 else if (whole.len == 0) 1463 "(no description)" 1464 else 1465 whole; 1466 var tb = try wgt.TextBox(ui.Widget).init(allocator, shown, .{ 1467 .border_style = .single, 1468 .rounded_corners = true, 1469 .wrap_kind = .word, 1470 .label = " description ", 1471 .bottom_label = if (cut_short) " click or press enter to see more " else "", 1472 }); 1473 errdefer tb.deinit(allocator); 1474 tb.getFocus().focusable = true; 1475 if (cut_short) tb.getFocus().kind = .{ .custom = try descriptionLink(self.session.page_arena, self.data.identity, entry.id) }; 1476 try inner.children.put(allocator, tb.getFocus().id, .{ .widget = .{ .text_box = tb }, .rect = null, .min_size = null }); 1477 break :blk tb.getFocus().id; 1478 }; 1479 1480 if (!description_page) { 1481 try Comment.appendCount(allocator, inner, entry.comments.count, "comment", "comments", self.session.page_arena.allocator()); 1482 for (entry.comments.comments) |comment| try Comment.appendComment(allocator, inner, self.session, self.data.identity, comment); 1483 try Comment.appendWindowNav(allocator, inner, self.session, self.data.identity, entry.id, null, entry.comments); 1484 1485 var spacer = try ui.Spacer.init(allocator); 1486 errdefer spacer.deinit(allocator); 1487 try inner.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1488 } 1489 1490 // select the title by default 1491 inner.getFocus().child_id = inner.children.keys()[title_child_index]; 1492 1493 // reset the scroll to the top for the newly-shown issue: directly on the 1494 // terminal (the wasm offset), and via a version bump on the web (so the 1495 // renderer's scroll id changes and JS drops the preserved position). 1496 const sc = self.detailScroll(index); 1497 sc.x = 0; 1498 sc.y = 0; 1499 sc.getFocus().version +%= 1; 1500 } 1501 1502 pub fn input(self: *View, allocator: std.mem.Allocator, raw_key: Key, root_focus: *Focus) !void { 1503 // wheel input moves focus like the arrows 1504 const key: Key = if (raw_key == .mouse and raw_key.mouse.action == .scroll) 1505 (if (raw_key.mouse.action.scroll == .up) .arrow_up else .arrow_down) 1506 else 1507 raw_key; 1508 1509 if (self.headerActive()) { 1510 // down from the tabs re-enters the stack if the selected view has 1511 // something to focus; other keys move the tabs. 1512 if (inp.vertDirection(key) == .down) { 1513 const enterable = if (self.viewStack().getSelected()) |selected| switch (selected.*) { 1514 .tag_flow => |*tf| tf.text_boxes.items.len > 0, 1515 // nothing focusable in the unauthorized view 1516 .unauthorized => false, 1517 else => true, 1518 } else false; 1519 if (enterable) root_focus.setFocus(self.box.children.keys()[stack_index]); 1520 } else { 1521 try self.header().input(allocator, key, root_focus); 1522 } 1523 return; 1524 } 1525 if (self.tagsViewActive()) { 1526 self.tagsViewInput(key, root_focus); 1527 return; 1528 } 1529 if (self.formViewActive()) { 1530 if (self.data.view == .resolve) { 1531 try self.resolveInput(allocator, key, root_focus); 1532 } else { 1533 try self.formInput(allocator, key, root_focus); 1534 } 1535 return; 1536 } 1537 const i = self.selectedSplitIndex() orelse return; 1538 if (self.detailActive(i)) { 1539 try self.detailInput(allocator, i, key, root_focus); 1540 } else { 1541 try self.listInput(i, key, root_focus); 1542 } 1543 } 1544 1545 // arrow keys move the tag selection; up from the top row crosses to the 1546 // header tabs. 1547 fn tagsViewInput(self: *View, key: Key, root_focus: *Focus) void { 1548 const tf = self.tagsView(); 1549 const cid = tf.focus.child_id orelse return; 1550 const cur = tf.indexOfFocusId(cid) orelse return; 1551 const count = tf.text_boxes.items.len; 1552 switch (key) { 1553 .arrow_left => if (cur > 0) root_focus.setFocus(tf.text_boxes.items[cur - 1].getFocus().id), 1554 .arrow_right => if (cur + 1 < count) root_focus.setFocus(tf.text_boxes.items[cur + 1].getFocus().id), 1555 .arrow_up => if (tf.rowStep(cur, false)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id) else self.focusHeader(root_focus), 1556 .arrow_down => if (tf.rowStep(cur, true)) |i| root_focus.setFocus(tf.text_boxes.items[i].getFocus().id), 1557 .home => root_focus.setFocus(tf.text_boxes.items[0].getFocus().id), 1558 .end => root_focus.setFocus(tf.text_boxes.items[count - 1].getFocus().id), 1559 else => {}, 1560 } 1561 } 1562 1563 fn listInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 1564 // up/down (and the scroll wheel) move the selection a row; page up/down 1565 // jump a fixed amount. right/Enter cross into the detail pane. up from 1566 // the top row crosses into the header tabs. 1567 if (inp.rowDelta(key, @intCast(self.listBox(index).children.count()))) |delta| { 1568 const lb = self.listBox(index); 1569 const at_top = if (lb.getFocus().child_id) |cid| lb.children.getIndex(cid) == 0 else true; 1570 if (delta < 0 and at_top) return self.focusHeader(root_focus); 1571 ui.moveRowFocus(lb, self.listScroll(index), root_focus, delta); 1572 return; 1573 } 1574 switch (key) { 1575 .enter, .arrow_right => try self.focusDetail(index, root_focus), 1576 else => {}, 1577 } 1578 } 1579 1580 fn detailInput(self: *View, allocator: std.mem.Allocator, index: usize, key: Key, root_focus: *Focus) !void { 1581 if (self.data.comment_page != null and std.mem.eql(u8, self.window(index).issues[self.detailed_index[index] orelse return].id, self.data.selected_id)) { 1582 try self.commentInput(index, key, root_focus); 1583 } else if (self.toolRowFocused(index)) { 1584 try self.toolRowInput(allocator, index, key, root_focus); 1585 } else if (self.titleFocused(index)) { 1586 try self.titleInput(index, key, root_focus); 1587 } else if (self.authorFocused(index)) { 1588 try self.authorInput(index, key, root_focus); 1589 } else if (self.tagsFocused(index)) { 1590 try self.tagsInput(index, key, root_focus); 1591 } else if (self.descriptionFocused(index)) { 1592 try self.descriptionInput(index, key, root_focus); 1593 } else { 1594 try self.commentInput(index, key, root_focus); 1595 } 1596 } 1597 1598 // the tool row: enter or a click on the open/close button flips the 1599 // issue's status; the edit and resolve buttons are a: links the host 1600 // follows. arrows cross between the buttons and to the neighboring 1601 // widgets. 1602 fn toolRowInput(self: *View, allocator: std.mem.Allocator, index: usize, key: Key, root_focus: *Focus) !void { 1603 const row = self.toolRow(index); 1604 const cur = if (row.getFocus().child_id) |cid| row.children.getIndex(cid) orelse return else return; 1605 const on_status = cur == button_in_row_index and self.statusButton(index) != null; 1606 switch (key) { 1607 .arrow_left => if (cur > button_in_row_index) root_focus.setFocus(row.children.keys()[cur - 1]) else try self.focusList(index, root_focus), 1608 .arrow_right => if (cur + 1 < row.children.count()) root_focus.setFocus(row.children.keys()[cur + 1]), 1609 .arrow_up => self.focusHeader(root_focus), 1610 .arrow_down => self.focusTitle(index, root_focus), 1611 .enter => if (on_status) try self.toggleIssueStatus(allocator, index), 1612 .mouse => |mouse| if (self.statusButton(index)) |button| { 1613 if (inp.leftClickOn(root_focus, button.getFocus().id, mouse)) try self.toggleIssueStatus(allocator, index); 1614 }, 1615 else => {}, 1616 } 1617 } 1618 1619 fn titleInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 1620 switch (key) { 1621 .arrow_left => try self.focusList(index, root_focus), 1622 .arrow_up => self.focusToolRow(index, root_focus), 1623 .arrow_down => if (self.authorPresent(index)) self.focusAuthor(index, root_focus) else try self.focusDescription(index, root_focus), 1624 else => {}, 1625 } 1626 } 1627 1628 // the author box's a: link (when it has one) is followed by the host on 1629 // enter / a click; arrows cross to the neighboring widgets. 1630 fn authorInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 1631 switch (key) { 1632 .arrow_left => try self.focusList(index, root_focus), 1633 .arrow_up => self.focusTitle(index, root_focus), 1634 .arrow_down => if (self.tagFlow(index) != null) try self.focusTags(index, root_focus) else try self.focusDescription(index, root_focus), 1635 else => {}, 1636 } 1637 } 1638 1639 fn descriptionInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 1640 const sc = self.detailScroll(index); 1641 switch (key) { 1642 .arrow_left => return self.focusList(index, root_focus), 1643 // once the scroll can't move further, cross into the tags (or the 1644 // open/close button when the issue has none). 1645 .arrow_up => { 1646 const before = sc.y; 1647 sc.y -= 1; 1648 sc.clampToContent(); 1649 if (sc.y == before) { 1650 if (self.tagFlow(index) != null) 1651 try self.focusTags(index, root_focus) 1652 else if (self.authorPresent(index)) 1653 self.focusAuthor(index, root_focus) 1654 else 1655 self.focusTitle(index, root_focus); 1656 } 1657 return; 1658 }, 1659 .arrow_down => { 1660 if (self.moveDetailFocus(index, root_focus, true)) return; 1661 const before = sc.y; 1662 sc.y += 1; 1663 sc.clampToContent(); 1664 if (sc.y == before) _ = self.moveDetailFocus(index, root_focus, true); 1665 return; 1666 }, 1667 .page_up => sc.y -= 10, 1668 .page_down => sc.y += 10, 1669 .home => sc.y = 0, 1670 .end => sc.y = std.math.maxInt(isize), 1671 else => return, 1672 } 1673 sc.clampToContent(); 1674 } 1675 1676 fn commentInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 1677 switch (key) { 1678 .arrow_left => if (!self.moveCommentHorizontal(index, root_focus, false)) return self.focusList(index, root_focus), 1679 .arrow_right => _ = self.moveCommentHorizontal(index, root_focus, true), 1680 .arrow_up => _ = self.moveCommentVertical(index, root_focus, false), 1681 .arrow_down => _ = self.moveCommentVertical(index, root_focus, true), 1682 .page_up => self.detailScroll(index).y -= 10, 1683 .page_down => self.detailScroll(index).y += 10, 1684 .home => self.detailScroll(index).y = 0, 1685 .end => self.detailScroll(index).y = std.math.maxInt(isize), 1686 else => return, 1687 } 1688 self.detailScroll(index).clampToContent(); 1689 } 1690 1691 fn focusedDetailChild(self: *View, index: usize, root_focus: *Focus) ?usize { 1692 const inner = self.detailInner(index); 1693 var id = root_focus.grandchild_id orelse return null; 1694 while (inner.getFocus().children.get(id)) |child| { 1695 if (child.parent_id == inner.getFocus().id) return inner.children.getIndex(id); 1696 id = child.parent_id; 1697 } 1698 return null; 1699 } 1700 1701 fn detailChildFocusable(self: *View, index: usize, child_index: usize) bool { 1702 const child = &self.detailInner(index).children.values()[child_index].widget; 1703 return switch (child.*) { 1704 .repo_comment => true, 1705 .box => |*box| for (box.children.values()) |*item| { 1706 if (item.widget.getFocus().focusable) break true; 1707 } else false, 1708 else => child.getFocus().focusable, 1709 }; 1710 } 1711 1712 fn focusDetailChild(self: *View, index: usize, child_index: usize, last: bool, root_focus: *Focus) void { 1713 const inner = self.detailInner(index); 1714 const child = &inner.children.values()[child_index]; 1715 var target = inner.children.keys()[child_index]; 1716 var rect = child.rect orelse return; 1717 switch (child.widget) { 1718 .repo_comment => |*comment| { 1719 if (comment.rowRect(last)) |row_rect| { 1720 rect.x += row_rect.x; 1721 rect.y += row_rect.y; 1722 rect.size = row_rect.size; 1723 } 1724 if (last) comment.focusBody(root_focus) else comment.focusMetadata(root_focus); 1725 }, 1726 .box => |*box| if (box.children.count() > 0) { 1727 target = box.children.keys()[if (last) box.children.count() - 1 else 0]; 1728 root_focus.setFocus(target); 1729 }, 1730 else => root_focus.setFocus(target), 1731 } 1732 self.detailScroll(index).scrollToRect(rect); 1733 } 1734 1735 fn moveCommentVertical(self: *View, index: usize, root_focus: *Focus, down: bool) bool { 1736 const inner = self.detailInner(index); 1737 const current = self.focusedDetailChild(index, root_focus) orelse return false; 1738 if (inner.children.values()[current].widget == .repo_comment) { 1739 const comment = &inner.children.values()[current].widget.repo_comment; 1740 if (down and !comment.bodyFocused()) { 1741 self.focusDetailChild(index, current, true, root_focus); 1742 return true; 1743 } 1744 if (!down and comment.bodyFocused()) { 1745 self.focusDetailChild(index, current, false, root_focus); 1746 return true; 1747 } 1748 } 1749 1750 var next = current; 1751 while (true) { 1752 if (down) { 1753 next += 1; 1754 if (next >= inner.children.count()) return false; 1755 } else { 1756 if (next == 0) return false; 1757 next -= 1; 1758 } 1759 if (!self.detailChildFocusable(index, next)) continue; 1760 self.focusDetailChild(index, next, !down, root_focus); 1761 return true; 1762 } 1763 } 1764 1765 fn moveCommentHorizontal(self: *View, index: usize, root_focus: *Focus, right: bool) bool { 1766 const inner = self.detailInner(index); 1767 const current = self.focusedDetailChild(index, root_focus) orelse return false; 1768 const child = &inner.children.values()[current]; 1769 if (child.widget == .repo_comment) { 1770 const moved = child.widget.repo_comment.moveHorizontal(root_focus, right); 1771 if (moved) if (child.rect) |rect| self.detailScroll(index).scrollToRect(rect); 1772 return moved; 1773 } 1774 const row = switch (child.widget) { 1775 .box => |*box| box, 1776 else => return false, 1777 }; 1778 const selected = row.getFocus().child_id orelse return false; 1779 const selected_index = row.children.getIndex(selected) orelse return false; 1780 const target = if (right) selected_index + 1 else selected_index -| 1; 1781 if (target == selected_index or target >= row.children.count()) return false; 1782 root_focus.setFocus(row.children.keys()[target]); 1783 if (child.rect) |rect| self.detailScroll(index).scrollToRect(rect); 1784 return true; 1785 } 1786 1787 fn moveDetailFocus(self: *View, index: usize, root_focus: *Focus, down: bool) bool { 1788 return self.moveCommentVertical(index, root_focus, down); 1789 } 1790 1791 // up/down (and tab/shift+tab) move between a form's fields; up from the 1792 // title crosses into the header tabs. the multiline description keeps 1793 // enter and any up/down that has a row to move to. 1794 fn formInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1795 const form = self.issueForm() orelse return; 1796 const cid = form.getFocus().child_id orelse return; 1797 const cur = form.children.getIndex(cid) orelse return; 1798 1799 if (cur == description_field_index) { 1800 const child = &form.children.values()[cur]; 1801 if (try multilineKeepsKey(&child.widget.text_input, allocator, key)) 1802 return child.widget.input(allocator, key, root_focus); 1803 } 1804 1805 switch (key) { 1806 .arrow_up, .back_tab => if (cur > 0) 1807 root_focus.setFocus(form.children.keys()[cur - 1]) 1808 else 1809 self.focusHeader(root_focus), 1810 .arrow_down, .tab => if (cur < submit_field_index) { 1811 root_focus.setFocus(form.children.keys()[cur + 1]); 1812 }, 1813 .enter => if (cur == submit_field_index) try self.submitForm(allocator), 1814 .mouse => |mouse| if (cur == submit_field_index) { 1815 const submit = &form.children.values()[cur].widget.submit_button; 1816 if (inp.leftClickOn(root_focus, submit.buttonId(), mouse)) try self.submitForm(allocator); 1817 }, 1818 else => try form.children.values()[cur].widget.input(allocator, key, root_focus), 1819 } 1820 } 1821 1822 // the multiline hunk inputs keep enter and any up/down that has a row to 1823 // move to; enter on a "use this" link is a navigation the host follows 1824 // before this runs. 1825 fn resolveInput(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1826 const form = self.issueForm() orelse return; 1827 const cid = form.getFocus().child_id orelse return; 1828 const cur = form.children.getIndex(cid) orelse return; 1829 const child = &form.children.values()[cur]; 1830 1831 if (child.widget == .text_input) { 1832 const ti = &child.widget.text_input; 1833 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 1834 return child.widget.input(allocator, key, root_focus); 1835 } 1836 1837 const on_submit = child.widget == .submit_button; 1838 1839 switch (key) { 1840 .arrow_up, .back_tab => if (resolveStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 1841 .arrow_down, .tab => if (resolveStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 1842 .arrow_left, .arrow_right => switch (child.widget) { 1843 .box => |*row| { 1844 const row_cid = row.getFocus().child_id orelse return; 1845 const row_index = row.children.getIndex(row_cid) orelse return; 1846 if (key == .arrow_left) { 1847 if (row_index > 0) root_focus.setFocus(row.children.keys()[row_index - 1]); 1848 } else if (row_index + 1 < row.children.count()) { 1849 root_focus.setFocus(row.children.keys()[row_index + 1]); 1850 } 1851 }, 1852 else => try child.widget.input(allocator, key, root_focus), 1853 }, 1854 .enter => if (on_submit) try self.submitResolution(allocator), 1855 .mouse => |mouse| if (on_submit) { 1856 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 1857 }, 1858 else => try child.widget.input(allocator, key, root_focus), 1859 } 1860 } 1861 1862 // a multiline input keeps enter and any up/down that has a row to move to 1863 fn multilineKeepsKey(text_input: *wgt.TextInput(ui.Widget), allocator: std.mem.Allocator, key: Key) !bool { 1864 return switch (key) { 1865 .enter => true, 1866 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 1867 .arrow_down => !try text_input.cursorOnLastRow(allocator), 1868 else => false, 1869 }; 1870 } 1871 1872 // the neighboring focusable resolve-form child, skipping the spacer and 1873 // the blank gap rows 1874 fn resolveStep(form: *wgt.Box(ui.Widget), cur: usize, down: bool) ?usize { 1875 var i = cur; 1876 while (true) { 1877 if (down) { 1878 i += 1; 1879 if (i >= form.children.count()) return null; 1880 } else { 1881 if (i == 0) return null; 1882 i -= 1; 1883 } 1884 switch (form.children.values()[i].widget) { 1885 .spacer, .text => continue, 1886 else => return i, 1887 } 1888 } 1889 } 1890 1891 // focus the resolve-form child at `i` (a version row focuses its selected 1892 // child) and keep it visible on the terminal 1893 fn focusResolveChild(self: *View, form: *wgt.Box(ui.Widget), i: usize, root_focus: *Focus) void { 1894 const child = &form.children.values()[i]; 1895 switch (child.widget) { 1896 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 1897 else => root_focus.setFocus(form.children.keys()[i]), 1898 } 1899 if (self.session.is_terminal) { 1900 if (self.resolveScroll()) |sc| { 1901 if (child.rect) |rect| sc.scrollToRect(rect); 1902 } 1903 } 1904 } 1905 1906 // re-emit the conflicted issue's event with the resolved content; any 1907 // event on the issue settles its conflict entry. this is the terminal 1908 // path; the web posts the form to the resolve route. 1909 fn submitResolution(self: *View, allocator: std.mem.Allocator) !void { 1910 if (comptime wasm) return; 1911 const io = self.session.io orelse return; 1912 const src = self.data.repo_source orelse return; 1913 const entry = self.data.selectedIssue() orelse return; 1914 const author_email = (try self.session.eventAuthorEmail()) orelse return; 1915 const form = self.issueForm() orelse return; 1916 1917 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 1918 var title: ?[]u8 = null; 1919 var tags: ?[]u8 = null; 1920 var hunks: std.ArrayList([]const u8) = .empty; 1921 defer { 1922 if (title) |t| allocator.free(t); 1923 if (tags) |t| allocator.free(t); 1924 for (hunks.items) |h| allocator.free(h); 1925 hunks.deinit(allocator); 1926 } 1927 for (form.children.values()) |*child| switch (child.widget) { 1928 .text_input => |*ti| { 1929 const text = try ti.text(allocator); 1930 errdefer allocator.free(text); 1931 if (std.mem.eql(u8, ti.options.name, "title")) { 1932 title = text; 1933 } else if (std.mem.eql(u8, ti.options.name, "tags")) { 1934 tags = text; 1935 } else { 1936 try hunks.append(allocator, text); 1937 } 1938 }, 1939 else => {}, 1940 }; 1941 1942 var id_bytes: [evt.event_id_size]u8 = undefined; 1943 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 1944 1945 switch (src.repo_kind) { 1946 inline else => |repo_kind| { 1947 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 1948 defer any_repo.deinit(io, allocator); 1949 switch (any_repo) { 1950 inline else => |*repo| evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .resolve = .{ 1951 .title = title, 1952 .tags = tags, 1953 .hunks = hunks.items, 1954 } }, author_email) catch |err| switch (err) { 1955 // leave the form up for correction 1956 error.InvalidFields => return, 1957 else => |e| return e, 1958 }, 1959 } 1960 }, 1961 } 1962 1963 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, entry.issue.event.status, "", entry.id) orelse return; 1964 try self.session.navigate(route); 1965 } 1966 1967 // the terminal submit paths: the new form commits a new-issue event, the 1968 // edit form re-emits the selected issue's event with the form's content. 1969 // the web posts the forms to their routes instead. 1970 fn submitForm(self: *View, allocator: std.mem.Allocator) !void { 1971 if (self.data.view == .edit) { 1972 try self.submitEditedIssue(allocator); 1973 } else { 1974 try self.submitNewIssue(allocator); 1975 } 1976 } 1977 1978 // commit the new issue to the repo's events branch and navigate to it. 1979 // this is the terminal path; the web posts the form to the issue route, 1980 // so the wasm side never runs (or compiles) the repo access below. 1981 fn submitNewIssue(self: *View, allocator: std.mem.Allocator) !void { 1982 if (comptime wasm) return; 1983 const io = self.session.io orelse return; 1984 const src = self.data.repo_source orelse return; 1985 const author_email = (try self.session.eventAuthorEmail()) orelse return; 1986 1987 const form = self.issueForm() orelse return; 1988 const title_input = &form.children.values()[title_field_index].widget.text_input; 1989 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 1990 const description_input = &form.children.values()[description_field_index].widget.text_input; 1991 1992 const title = try title_input.text(allocator); 1993 defer allocator.free(title); 1994 const tags = try tags_input.text(allocator); 1995 defer allocator.free(tags); 1996 const description = try description_input.text(allocator); 1997 defer allocator.free(description); 1998 1999 if (!evt.Issue.fieldsValid(title, tags)) return; 2000 2001 var id_bytes: [evt.event_id_size]u8 = undefined; 2002 io.random(&id_bytes); 2003 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 2004 2005 const event = evt.EventWithId{ 2006 .id = event_id_hex, 2007 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 2008 .author_email = author_email, 2009 .event = .{ .issue = .{ 2010 .title = title, 2011 .description = description, 2012 .tags = tags, 2013 } }, 2014 }; 2015 2016 switch (src.repo_kind) { 2017 inline else => |repo_kind| { 2018 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 2019 defer any_repo.deinit(io, allocator); 2020 switch (any_repo) { 2021 inline else => |*repo| try evt.consume(repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 2022 } 2023 }, 2024 } 2025 2026 // wipe the form so a return visit starts fresh 2027 title_input.clear(allocator); 2028 tags_input.clear(allocator); 2029 description_input.clear(allocator); 2030 2031 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, .open, "", &event_id_hex) orelse return; 2032 try self.session.navigate(route); 2033 } 2034 2035 // re-emit the selected issue's event with the form's content (status 2036 // preserved), then reload the issue's page. this is the terminal path; 2037 // the web posts the form to the edit route. 2038 fn submitEditedIssue(self: *View, allocator: std.mem.Allocator) !void { 2039 if (comptime wasm) return; 2040 const io = self.session.io orelse return; 2041 const src = self.data.repo_source orelse return; 2042 const entry = self.data.selectedIssue() orelse return; 2043 const author_email = (try self.session.eventAuthorEmail()) orelse return; 2044 2045 const form = self.issueForm() orelse return; 2046 const title_input = &form.children.values()[title_field_index].widget.text_input; 2047 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 2048 const description_input = &form.children.values()[description_field_index].widget.text_input; 2049 2050 const title = try title_input.text(allocator); 2051 defer allocator.free(title); 2052 const tags = try tags_input.text(allocator); 2053 defer allocator.free(tags); 2054 const description = try description_input.text(allocator); 2055 defer allocator.free(description); 2056 2057 if (!evt.Issue.fieldsValid(title, tags)) return; 2058 2059 var id_bytes: [evt.event_id_size]u8 = undefined; 2060 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2061 2062 switch (src.repo_kind) { 2063 inline else => |repo_kind| { 2064 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 2065 defer any_repo.deinit(io, allocator); 2066 switch (any_repo) { 2067 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2068 .title = title, 2069 .tags = tags, 2070 .description = description, 2071 } }, author_email), 2072 } 2073 }, 2074 } 2075 2076 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, entry.issue.event.status, "", entry.id) orelse return; 2077 try self.session.navigate(route); 2078 } 2079 2080 // flip the shown issue's status by re-emitting its event, then reload the 2081 // page rooted at the issue so the view reflects the change. this is the 2082 // terminal path; the web posts the button's form to the status route. 2083 fn toggleIssueStatus(self: *View, allocator: std.mem.Allocator, index: usize) !void { 2084 if (comptime wasm) return; 2085 const io = self.session.io orelse return; 2086 const src = self.data.repo_source orelse return; 2087 const sel = self.detailed_index[index] orelse return; 2088 const entry = self.window(index).issues[sel]; 2089 const author_email = (try self.session.eventAuthorEmail()) orelse return; 2090 2091 const status: evt.Issue.Status = switch (entry.issue.event.status) { 2092 .open => .closed, 2093 .closed => .open, 2094 }; 2095 2096 var id_bytes: [evt.event_id_size]u8 = undefined; 2097 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2098 2099 switch (src.repo_kind) { 2100 inline else => |repo_kind| { 2101 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 2102 defer any_repo.deinit(io, allocator); 2103 switch (any_repo) { 2104 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author_email), 2105 } 2106 }, 2107 } 2108 2109 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, status, "", entry.id) orelse return; 2110 try self.session.navigate(route); 2111 } 2112 2113 // arrow keys move the tag selection; at the flow's edges focus crosses to 2114 // the neighboring widgets. 2115 fn tagsInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 2116 const tf = self.tagFlow(index) orelse return; 2117 const cid = tf.focus.child_id orelse return; 2118 const cur = tf.indexOfFocusId(cid) orelse return; 2119 const count = tf.text_boxes.items.len; 2120 switch (key) { 2121 .arrow_left => if (cur > 0) self.focusTag(index, tf, root_focus, cur - 1) else try self.focusList(index, root_focus), 2122 .arrow_right => if (cur + 1 < count) self.focusTag(index, tf, root_focus, cur + 1), 2123 .arrow_up => if (tf.rowStep(cur, false)) |i| self.focusTag(index, tf, root_focus, i) else self.focusAuthor(index, root_focus), 2124 .arrow_down => if (tf.rowStep(cur, true)) |i| self.focusTag(index, tf, root_focus, i) else try self.focusDescription(index, root_focus), 2125 .home => self.focusTag(index, tf, root_focus, 0), 2126 .end => self.focusTag(index, tf, root_focus, count - 1), 2127 else => {}, 2128 } 2129 } 2130 2131 const button_in_row_index: usize = 1; 2132 const title_child_index: usize = 0; 2133 const tags_child_index: usize = 2; 2134 2135 fn tagFlow(self: *View, index: usize) ?*ui.TagFlow { 2136 const inner = self.detailInner(index); 2137 if (inner.children.count() <= tags_child_index) return null; 2138 return switch (inner.children.values()[tags_child_index].widget) { 2139 .tag_flow => |*tf| tf, 2140 else => null, 2141 }; 2142 } 2143 2144 fn tagsFocused(self: *View, index: usize) bool { 2145 const inner = self.detailInner(index); 2146 const cid = inner.getFocus().child_id orelse return false; 2147 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null; 2148 } 2149 2150 // the open/close button inside the detail frame's tool row, identified 2151 // by its posting kind; a logged-out session's or conflicted issue's row 2152 // has none. 2153 fn statusButton(self: *View, index: usize) ?*wgt.TextBox(ui.Widget) { 2154 const row = self.toolRow(index); 2155 if (row.children.count() <= button_in_row_index) return null; 2156 switch (row.children.values()[button_in_row_index].widget) { 2157 .text_box => |*tb| switch (tb.box.focus.kind) { 2158 .custom => |custom| if (std.mem.eql(u8, custom, "submit")) return tb, 2159 else => {}, 2160 }, 2161 else => {}, 2162 } 2163 return null; 2164 } 2165 2166 fn toolRowFocused(self: *View, index: usize) bool { 2167 const outer = self.detailOuter(index); 2168 const cid = outer.getFocus().child_id orelse return false; 2169 return outer.children.getIndex(cid) == tool_row_index; 2170 } 2171 2172 fn focusTag(self: *View, index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2173 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2174 // keep the tag visible on the terminal: its rect offset by the flow's 2175 // position in the pane. 2176 if (self.session.is_terminal and item < tf.rects.items.len) { 2177 if (self.detailInner(index).children.values()[tags_child_index].rect) |flow_rect| { 2178 var rect = tf.rects.items[item]; 2179 rect.x += flow_rect.x; 2180 rect.y += flow_rect.y; 2181 self.detailScroll(index).scrollToRect(rect); 2182 } 2183 } 2184 } 2185 2186 fn titleFocused(self: *View, index: usize) bool { 2187 const inner = self.detailInner(index); 2188 const cid = inner.getFocus().child_id orelse return false; 2189 return inner.children.getIndex(cid) == title_child_index; 2190 } 2191 2192 fn authorPresent(self: *View, index: usize) bool { 2193 return self.author_id[index] != null; 2194 } 2195 2196 fn authorFocused(self: *View, index: usize) bool { 2197 const inner = self.detailInner(index); 2198 const cid = inner.getFocus().child_id orelse return false; 2199 return cid == self.author_id[index]; 2200 } 2201 2202 fn descriptionFocused(self: *View, index: usize) bool { 2203 const cid = self.detailInner(index).getFocus().child_id orelse return false; 2204 return cid == self.description_id[index]; 2205 } 2206 2207 // the author sits right under the title at the top of the pane, so 2208 // focusing it scrolls there. 2209 fn focusAuthor(self: *View, index: usize, root_focus: *Focus) void { 2210 const id = self.author_id[index] orelse return; 2211 root_focus.setFocus(id); 2212 self.detailScroll(index).y = 0; 2213 } 2214 2215 // the title sits at the top of the pane, so focusing it scrolls there. 2216 fn focusTitle(self: *View, index: usize, root_focus: *Focus) void { 2217 const inner = self.detailInner(index); 2218 if (inner.children.count() == 0) return; 2219 root_focus.setFocus(inner.children.keys()[title_child_index]); 2220 self.detailScroll(index).y = 0; 2221 } 2222 2223 fn focusTags(self: *View, index: usize, root_focus: *Focus) !void { 2224 const tf = self.tagFlow(index) orelse return; 2225 if (tf.text_boxes.items.len == 0) return; 2226 const cid = tf.focus.child_id orelse tf.text_boxes.items[0].getFocus().id; 2227 const item = tf.indexOfFocusId(cid) orelse 0; 2228 self.focusTag(index, tf, root_focus, item); 2229 } 2230 2231 fn focusDescription(self: *View, index: usize, root_focus: *Focus) !void { 2232 if (self.description_id[index]) |id| root_focus.setFocus(id); 2233 } 2234 2235 // return to the tool row's last-focused button (the header when the 2236 // description page shows no row). 2237 fn focusToolRow(self: *View, index: usize, root_focus: *Focus) void { 2238 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2239 root_focus.setFocus(cid); 2240 } 2241 2242 // enter the detail pane. an empty pane (no issues) can't be entered. 2243 fn focusDetail(self: *View, index: usize, root_focus: *Focus) !void { 2244 if (self.detailInner(index).children.count() == 0) return; 2245 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2246 } 2247 2248 // return to the list. 2249 fn focusList(self: *View, index: usize, root_focus: *Focus) !void { 2250 root_focus.setFocus(self.listScroll(index).getFocus().id); 2251 } 2252 2253 // cross to the header tabs above the stack. 2254 fn focusHeader(self: *View, root_focus: *Focus) void { 2255 root_focus.setFocus(self.box.children.keys()[header_index]); 2256 } 2257 2258 pub fn clearGrid(self: *View) void { 2259 self.box.clearGrid(); 2260 } 2261 2262 pub fn getGrid(self: View) ?Grid { 2263 return self.box.getGrid(); 2264 } 2265 2266 pub fn getFocus(self: *View) *Focus { 2267 return self.box.getFocus(); 2268 } 2269 2270 // for the parent's "scroll up at the top jumps to the header" check: at the 2271 // top only while the header tabs hold focus, so up from the split 2272 // crosses into the tabs first. 2273 pub fn getSelectedIndex(self: *View) ?usize { 2274 return if (self.headerActive()) 0 else 1; 2275 } 2276 }; 2277 2278 // the "a:" navigation link for `status`'s issues page filtered to the 2279 // url-encoded `tag` and rooted at issue `id` within `identity` ("owner/name"). 2280 // a rooted url ignores `status` (it derives its view from the issue's own); 2281 // with an empty `id` this is the bare list link. 2282 fn issuesLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8, id: []const u8) ![]const u8 { 2283 const route = ui.RoutablePage.repoIssuesRoute(identity, status, tag, id) orelse return error.RouteTooLong; 2284 const url = try route.toUrl(page_arena); 2285 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2286 } 2287 2288 // the in-page "ai:" anchor for selecting issue `id` in `identity`'s list; the 2289 // href is only followed with js off. 2290 fn issueRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 2291 const route = ui.RoutablePage.repoIssuesRoute(identity, .open, "", id) orelse return error.RouteTooLong; 2292 const url = try route.toUrl(page_arena); 2293 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 2294 } 2295 2296 // the "a:" link to the window `status_maybe` names, keeping the tag filter, 2297 // or the conflicts window when null, rooted at issue `id`. 2298 fn windowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, status_maybe: ?evt.Issue.Status, id: []const u8) ![]const u8 { 2299 if (status_maybe) |status| return issuesLink(page_arena, data.identity, status, data.tag, id); 2300 return conflictsLink(page_arena, data.identity, id); 2301 } 2302 2303 // the "a:" link to the conflicts list rooted at issue `start` ("" = the 2304 // first window). 2305 fn conflictsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, start: []const u8) ![]const u8 { 2306 const route = ui.RoutablePage.repoIssuesConflictsRoute(identity, start) orelse return error.RouteTooLong; 2307 const url = try route.toUrl(page_arena); 2308 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2309 } 2310 2311 // the "a:" link to the whole-description page of issue `id` within `identity`. 2312 fn descriptionLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 2313 const route = ui.RoutablePage.repoIssuesDescriptionRoute(identity, id) orelse return error.RouteTooLong; 2314 const url = try route.toUrl(page_arena); 2315 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2316 } 2317 2318 // the "a:" link to `status`'s issues list filtered to `tag` (raw; encoded here). 2319 fn tagLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8) ![]const u8 { 2320 const encoded = try ui.urlEncodeRef(page_arena.allocator(), tag); 2321 const route = ui.RoutablePage.repoIssuesRoute(identity, status, encoded, "") orelse return error.RouteTooLong; 2322 const url = try route.toUrl(page_arena); 2323 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2324 } 2325 2326 // tabs switching between the issues page's views. 2327 pub const Header = struct { 2328 box: wgt.Box(ui.Widget), 2329 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 2330 2331 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 2332 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 2333 errdefer box.deinit(allocator); 2334 2335 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 2336 errdefer tab_ids.deinit(allocator); 2337 2338 const aa = session.page_arena.allocator(); 2339 2340 // a list tab per status, labeled with its listing's issue count 2341 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 2342 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 2343 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2344 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 2345 try addTab(allocator, &box, &tab_ids, label, link); 2346 } 2347 2348 // tags tab, labeled with the active tag filter 2349 { 2350 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 2351 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 2352 const label = if (data.tag.len == 0) "tags" else blk: { 2353 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 2354 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 2355 }; 2356 try addTab(allocator, &box, &tab_ids, label, tags_link); 2357 } 2358 2359 // new-issue tab; an edit or resolve url shows its tab in this place 2360 { 2361 const route = switch (data.view) { 2362 .edit => ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 2363 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 2364 else => ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong, 2365 }; 2366 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2367 const label: []const u8 = switch (data.view) { 2368 .edit => "edit", 2369 .resolve => "resolve", 2370 else => "new", 2371 }; 2372 try addTab(allocator, &box, &tab_ids, label, link); 2373 } 2374 2375 // conflicts tab, labeled with the conflict count 2376 if (data.conflicts.count > 0) { 2377 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 2378 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2379 const label = try std.fmt.allocPrint(aa, "conflicts ({d})", .{data.conflicts.count}); 2380 try addTab(allocator, &box, &tab_ids, label, link); 2381 } 2382 2383 var self = Header{ .box = box, .tab_ids = tab_ids }; 2384 // the tab matching the page's view is selected initially. 2385 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 2386 return self; 2387 } 2388 2389 fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void { 2390 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 2391 errdefer text_box.deinit(allocator); 2392 text_box.getFocus().focusable = true; 2393 text_box.getFocus().kind = .{ .custom = link }; 2394 try tab_ids.put(allocator, text_box.getFocus().id, {}); 2395 try box.children.put(allocator, text_box.getFocus().id, .{ 2396 .widget = .{ .text_box = text_box }, 2397 .rect = null, 2398 .min_size = .{ .width = label.len + 2, .height = null }, 2399 }); 2400 } 2401 2402 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 2403 self.box.deinit(allocator); 2404 self.tab_ids.deinit(allocator); 2405 } 2406 2407 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2408 self.clearGrid(); 2409 // only the selected tab shows its border 2410 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 2411 switch (child.widget) { 2412 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 2413 else => {}, 2414 } 2415 } 2416 try self.box.build(allocator, constraint, root_focus); 2417 } 2418 2419 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2420 _ = allocator; 2421 const current_tab = self.currentTabIndex() orelse return; 2422 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 2423 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 2424 } 2425 } 2426 2427 pub fn clearGrid(self: *Header) void { 2428 self.box.clearGrid(); 2429 } 2430 2431 pub fn getGrid(self: Header) ?Grid { 2432 return self.box.getGrid(); 2433 } 2434 2435 pub fn getFocus(self: *Header) *Focus { 2436 return self.box.getFocus(); 2437 } 2438 2439 pub fn getSelectedIndex(self: Header) ?usize { 2440 return self.currentTabIndex(); 2441 } 2442 2443 fn currentTabIndex(self: Header) ?usize { 2444 const child_id = self.box.focus.child_id orelse return null; 2445 return self.tab_ids.getIndex(child_id); 2446 } 2447 }; 2448