Files
breeze/apps/lumi/updates.zi
T

56 lines
1.7 KiB
Ziran

// A short update message from the installed root package's core Breeze notes,
// filtered by scripts/release_notes.py before packaging, with no link.
#import "json_scan"
#import "byte_text_linux"
#import "std/format"
#import "vec"
#import, file "../../src/apps/lumi_types.zi";
// The most changelog entries an update message shows.
LUMI_UPDATE_NOTES_MAX :: 3
LumiUpdateVersion :: (document: string, output: []u8) -> string {
count := ReadStringText(document, FieldAt(document, 0, "version"), output)
if count <= 0 || count >= output.count {
return ""
}
parts: s32 = 1
digits: s32 = 0
for byte: output[:count] {
if byte == cast(u8)46 && digits > 0 {
parts += 1
digits = 0
} else if byte >= cast(u8)48 && byte <= cast(u8)57 {
digits += 1
} else {
return ""
}
}
if parts != 3 || digits == 0 {
return ""
}
return TextFromBytes(output[:count])
}
LumiUpdateMessage :: (document: string, introduction: string) -> string {
out: Vec(u8)
BuilderPrint(*out, "%", introduction)
notes := FieldAt(document, 0, "notes")
bytes: [LUMI_INPUT_MAX]u8
count := ArrayCount(document, notes)
if count > LUMI_UPDATE_NOTES_MAX {
count = LUMI_UPDATE_NOTES_MAX
}
for index: cast(s32)0..count - 1 {
length := ReadStringText(document, ElementAt(document, notes, index), bytes[:])
// Keep whole changelog entries and UTF-8 characters within the chat's
// existing size.
if length <= 0 || length >= bytes.count ||
out.count + length + 4 >= LUMI_INPUT_MAX {
break
}
BuilderPrint(*out, "\n\n- %", TextFromBytes(bytes[:length]))
}
return BuilderFinish(out)
}