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