navid/veins / commit

061a2e5987e8

Navid M <navidmomtahen@gmail.com> · 2026-11-26

parents: 04a6f304c4a4

Browse files at this commit · Download source

all: colored logs output
--- a/docs/SPECIFICATION_V1.adoc+++ b/docs/SPECIFICATION_V1.adoc@@ -1060,7 +1060,7 @@ | `vn init [path] [-git-import:<gitdir>]` | Create a repository, optionally importing an existing git repo. | `vn clone <url> [-blobs head\|none\|all]` | Clone via the native protocol. | `vn status` | Working-copy changes, conflicts, files needing regeneration.-| `vn log [-rev <revset>]` | Show history, flagging conflicted and divergent changes.+| `vn log [-rev <revset>] [-no-col-titles]` | Show history, newest first, flagging conflicted and divergent changes. | `vn show <rev>`, `vn diff [-rev <rev>]` | Display a commit or a diff. | `vn new [<rev>...]`, `vn describe [-message <message>]`, `vn commit -message <message>` | Create and describe changes. `vn commit` does nothing when the working copy has no changes. | `vn mv`, `vn rm` | Move or remove tracked files, recording renames.@@ -1082,6 +1082,8 @@ | `vn config` | Read and write configuration. | `vn help [<command>]`, `vn -help`, `vn version`, `vn -version` | Show usage or version information. |===++`vn log` prints commits newest first in aligned columns with no borders. Column titles are shown by default and can be omitted with `-no-col-titles`. Output is colored when standard output is a terminal; setting `NO_COLOR` disables color.  All commands that change state MUST be atomic with respect to the operation log: they either produce one operation or leave the repository unchanged. --- a/src/src/cli/help_cmd.sx+++ b/src/src/cli/help_cmd.sx@@ -113,9 +113,13 @@ }  fn show_log() void = trust {-    stdio.puts("usage: vn log [-rev <revset>]")+    stdio.puts("usage: vn log [-rev <revset>] [-no-col-titles]")     stdio.puts("")-    stdio.puts("show commit history")+    stdio.puts("show commit history, newest first")+    stdio.puts("")+    stdio.puts("options:")+    stdio.puts("  -rev <revset>             show only the given revision set")+    stdio.puts("  -no-col-titles            omit column titles") }  fn show_diff() void = trust {--- a/src/src/cli/log_cmd.sx+++ b/src/src/cli/log_cmd.sx@@ -1,7 +1,8 @@-/// `vn log [-r <revset>]`: show commit history.+/// `vn log [-rev <revset>]`: show commit history, newest first.  val str       = use("std/string") val stdio     = use("std/stdio")+val terminal  = use("std/terminal") val bytes     = use("../core/bytes.sx") val lists     = use("../core/lists.sx") val objid     = use("../object/id.sx")@@ -117,6 +118,30 @@         i++     }     return msg+}++fn print_cell(+    text: str.StringView,+    width: usize,+    color: terminal.Color,+    dim: bool+) void = trust {+    if dim {+        terminal.print_styled(text, color, terminal.Color.Default, terminal.Style.Dim)+    } elif color == terminal.Color.Default {+        stdio.print("{s}", {text})+    } else {+        terminal.print(text, color)+    }+    val pad: mut i64 = width as i64 - text.len+    for pad > 0 {+        stdio.print(" ", {})+        pad--+    }+}++fn print_gap() void = trust {+    stdio.print("  ", {}) }  fn short_cid(rs: list[ref LogRec], idx: usize) bytes.Bytes = trust {@@ -150,7 +175,7 @@     return bytes.Bytes.dup(bytes.Bytes.slice(target.cid, 0, len)) } -pub fn run(repo: layout.Repo, rev: bytes.Bytes) i32 = trust {+pub fn run(repo: layout.Repo, rev: bytes.Bytes, col_titles: bool) i32 = trust {     val snap: i32 = snapshot.run(repo)     if snap != 0 {         return snap@@ -201,6 +226,36 @@         }     }     sort_recs(recs)+    val w_commit: usize = 12+    val w_change: mut usize = 6+    val w_date: usize = 19+    val w_author: mut usize = 6+    val k: mut usize = 0+    for k < @len(recs) {+        val r: ref LogRec = rec_at(recs, k)+        val cid: bytes.Bytes = short_cid(recs, k)+        if cid.len > w_change {+            w_change = cid.len+        }+        changeid.free(cid)+        if r.author.len > w_author {+            w_author = r.author.len+        }+        k+++    }+    if col_titles {+        print_cell(str.from_cstr(c""), 1, terminal.Color.Default, false)+        stdio.print(" ", {})+        print_cell(str.from_cstr(c"Commit"), w_commit, terminal.Color.Default, false)+        print_gap()+        print_cell(str.from_cstr(c"Change"), w_change, terminal.Color.Default, false)+        print_gap()+        print_cell(str.from_cstr(c"Date"), w_date, terminal.Color.Default, false)+        print_gap()+        print_cell(str.from_cstr(c"Author"), w_author, terminal.Color.Default, false)+        print_gap()+        stdio.print("Message\n", {})+    }     val i: mut usize = 0     for i < @len(recs) {         val r: ref LogRec = rec_at(recs, i)@@ -214,17 +269,29 @@         val stamp: bytes.Bytes = datetime.format_utc(r.seconds)         val msg_view = str.view(r.message.ptr, r.message.len as i64)         val author_view = str.view(r.author.ptr, r.author.len as i64)-        stdio.print(-            "{s} {s} {s} {s} {s} {s}",-            {-                marker,-                short,-                str.view(cid.ptr, cid.len as i64),-                str.view(stamp.ptr, stamp.len as i64),-                author_view,-                msg_view-            }+        print_cell(marker, 1, terminal.Color.Default, false)+        stdio.print(" ", {})+        print_cell(short, w_commit, terminal.Color.Red, false)+        print_gap()+        print_cell(+            str.view(cid.ptr, cid.len as i64),+            w_change,+            terminal.Color.Red,+            false+        )+        print_gap()+        print_cell(+            str.view(stamp.ptr, stamp.len as i64),+            w_date,+            terminal.Color.Cyan,+            true         )+        print_gap()+        print_cell(author_view, w_author, terminal.Color.Cyan, false)+        print_gap()+        if msg_view.len > 0 {+            terminal.print(msg_view, terminal.Color.Green)+        }         val names = viewops.bookmark_names(v, r.id)         for name in names {             stdio.print(" [{s}]", {str.view(name.ptr, name.len as i64)})--- a/src/src/main.sx+++ b/src/src/main.sx@@ -120,6 +120,7 @@  fn run_log(args: list[ref u8], start: usize) i32 = trust {     val rev: mut bytes.Bytes = bytes.empty()+    val col_titles: mut bool = true     val end_flags: mut bool = false     val i: mut usize = start     for i < @len(args) {@@ -138,6 +139,8 @@                     stdio.eprint("vn: {s} requires a revision\n", {str.from_cstr(a)})                     return 1                 }+            } elif !end_flags && cmd_is(a, c"-no-col-titles", 14) {+                col_titles = false             } elif !end_flags && is_flag(a) {                 stdio.eprint("vn: unknown flag: {s}\n", {str.from_cstr(a)})                 return 1@@ -150,7 +153,7 @@     val repo_opt = open_repo_or_error(str.from_cstr(c"."))     match repo_opt {         some repo => {-            val status: i32 = log_cmd.run(repo, rev)+            val status: i32 = log_cmd.run(repo, rev, col_titles)             layout.free_repo(repo)             return status         }