1234module history56import os7import time8import src.storage910const log_marker = '<!-- Koh maintains this file. Do not edit. Read before starting work. -->'11const log_shown = 2012131415pub fn write_log_md(store &storage.Store) ! {16 path := os.join_path(store.root, 'LOG.md')17 if os.is_file(path) {18 existing := os.read_file(path)!19 if !existing.starts_with(log_marker) {20 21 return22 }23 }24 saves := line(store)!25 shown := if saves.len < log_shown { saves.len } else { log_shown }26 mut text := '${log_marker}\n\n# Koh Log\n\n'27 for save in saves[..shown] {28 text += '✦ [${save.id}] ${save.message} · ${clock(save.created_at)}\n'29 }30 if saves.len > shown {31 text += '\n… ${saves.len - shown} older saves\n'32 }33 text += '\n*full history: koh log*\n'34 os.write_file(path, text)!35}3637fn clock(unix_seconds i64) string {38 return time.unix(unix_seconds).local().format_ss()39}