1234module history56import os7import time8import src.fmt9import src.storage1011const log_marker = '<!-- Koh maintains this file. Do not edit. Read before starting work. -->'12const log_shown = 20131415161718pub fn refresh_log_md(store &storage.Store) {19 write_log_md(store) or { eprintln(' ! LOG.md was not updated: ${err.msg()}') }20}21222324fn write_log_md(store &storage.Store) ! {25 path := os.join_path(store.root, 'LOG.md')26 if os.is_file(path) {27 existing := os.read_file(path)!28 if !existing.starts_with(log_marker) {29 30 return31 }32 }33 saves := line(store)!34 shown := if saves.len < log_shown { saves.len } else { log_shown }35 mut text := '${log_marker}\n\n# Koh Log\n\n'36 for save in saves[..shown] {37 text += '✦ [${save.id}] ${fmt.safe_text(save.message)} · ${clock(save.created_at)}\n'38 }39 if saves.len > shown {40 text += '\n… ${saves.len - shown} older saves\n'41 }42 text += '\n*full history: koh view*\n'43 os.write_file(path, text)!44}4546fn clock(unix_seconds i64) string {47 return time.unix(unix_seconds).local().format_ss()48}