From 2db131839db95047f57069f8ef01deecf55f3567 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Wed, 21 Jan 2026 22:39:21 +0800 Subject: [PATCH] 011-logseq-cli-search-optimization.md (2) --- docs/cli/logseq-cli.md | 2 +- src/main/logseq/cli/format.cljs | 23 ++++++++++++++++++----- src/test/logseq/cli/format_test.cljs | 5 +++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/cli/logseq-cli.md b/docs/cli/logseq-cli.md index 32188fae58..53245724d6 100644 --- a/docs/cli/logseq-cli.md +++ b/docs/cli/logseq-cli.md @@ -97,7 +97,7 @@ Options grouping: Output formats: - Global `--output ` (also accepted per subcommand) - For `graph export`, `--output` refers to the destination file path. Output formatting is controlled via `:output-format` in config or `LOGSEQ_CLI_OUTPUT`. -- Human output is plain text. List/search commands render tables with a final `Count: N` line. For list and search subcommands, the ID column uses `:db/id` (not UUID). If `:db/ident` exists, an `IDENT` column is included. Search table columns are `ID` and `TITLE`. Times such as list `UPDATED-AT`/`CREATED-AT` and `graph info` `Created at` are shown in human-friendly relative form. Errors include error codes and may include a `Hint:` line. Use `--output json|edn` for structured output. +- Human output is plain text. List/search commands render tables with a final `Count: N` line. For list and search subcommands, the ID column uses `:db/id` (not UUID). If `:db/ident` exists, an `IDENT` column is included. Search table columns are `ID` and `TITLE`. Block titles can include multiple lines; multi-line rows align additional lines under the `TITLE` column. Times such as list `UPDATED-AT`/`CREATED-AT` and `graph info` `Created at` are shown in human-friendly relative form. Errors include error codes and may include a `Hint:` line. Use `--output json|edn` for structured output. - Show and search outputs resolve block reference UUIDs inside text, replacing `[[]]` with the referenced block content. Nested references are resolved recursively up to 10 levels to avoid excessive expansion. For example: `[[]]` → `[[some text [[]]]]` and then `` is also replaced. - `show` human output prints the `:db/id` as the first column followed by a tree: diff --git a/src/main/logseq/cli/format.cljs b/src/main/logseq/cli/format.cljs index 13b1cddc99..957f5c15de 100644 --- a/src/main/logseq/cli/format.cljs +++ b/src/main/logseq/cli/format.cljs @@ -40,22 +40,35 @@ (defn- render-table [headers rows] - (let [normalized-rows (mapv (fn [row] - (mapv normalize-cell row)) + (let [split-lines (fn [value] + (string/split (normalize-cell value) #"\n" -1)) + normalized-rows (mapv (fn [row] + (mapv split-lines row)) rows) trim-right (fn [value] (string/replace value #"\s+$" "")) widths (mapv (fn [idx header] - (apply max (count header) - (map #(count (nth % idx)) normalized-rows))) + (reduce max + (count header) + (mapcat #(map count (nth % idx)) normalized-rows))) (range (count headers)) headers) render-row (fn [row] (->> (map pad-right row widths) (string/join " ") (trim-right))) + render-multiline-row (fn [row] + (let [line-count (reduce max 1 (map count row))] + (mapv (fn [line-idx] + (->> (map-indexed (fn [col-idx lines] + (pad-right (get lines line-idx "") + (nth widths col-idx))) + row) + (string/join " ") + (trim-right))) + (range line-count)))) lines (cons (render-row headers) - (map render-row normalized-rows))] + (mapcat render-multiline-row normalized-rows))] (string/join "\n" lines))) (defn- format-counted-table diff --git a/src/test/logseq/cli/format_test.cljs b/src/test/logseq/cli/format_test.cljs index 49e1ba19b1..657b9810d7 100644 --- a/src/test/logseq/cli/format_test.cljs +++ b/src/test/logseq/cli/format_test.cljs @@ -171,7 +171,7 @@ :created-at 1} {:type "block" :db/id 102 - :content "Note" + :content "Note line 1\nNote line 2" :uuid "u2" :updated-at 4 :created-at 2} @@ -186,7 +186,8 @@ {:output-format nil})] (is (= (str "ID TITLE\n" "101 Alpha\n" - "102 Note\n" + "102 Note line 1\n" + " Note line 2\n" "103 Taggy\n" "104 Prop\n" "Count: 4")