Skip to content

A peer-to-peer stack for code collaboration

Show diff list in a table format (#446)

Merle Breitkreuz55b3e1d47cf8
diff --git a/bin/rad-diff b/bin/rad-diff
index af3d9b6..eb36420 100755
--- a/bin/rad-diff
+++ b/bin/rad-diff
@@ -155,6 +155,38 @@
(fn [state]
(drop 1 (show state))))
+(def cells
+ {:state 10
+ :number 10
+ :title 50
+ :author 20
+ :modified-at 20})
+
+(def pad-to
+ (fn [l x]
+ (if (< l 1)
+ ""
+ (do
+ (def pad (string/intercalate "" (map (fn [x] " ") (range 1 l))))
+ (def x-length (length x))
+ (if (> x-length (- l 1))
+ (take l x)
+ (string-append x (take (- l x-length) pad)))))))
+
+(def wrap-cell
+ (fn [phrase cell-key]
+ (def c-length (lookup cell-key cells))
+ (string-append (pad-to c-length phrase) " ")))
+
+(def pretty-table-header
+ (fn []
+ (string-append
+ (wrap-cell "state" :state)
+ (wrap-cell "#" :number)
+ (wrap-cell "commit" :title)
+ (wrap-cell "author" :author)
+ (wrap-cell "updated" :modified-at))))
+
(def pretty-headline
(fn [i]
(match i
@@ -162,9 +194,28 @@
:title tit
:state s
:author-name an
- :short-hash sh}
+ :modified-at m-a}
(string-append
- "(" (pretty-state s) ") [" an "] " sh " - " tit " | DIFF " (show n)))))
+ (pretty-state s) " "
+ (show n) " "
+ tit " "
+ an " "
+ m-a " "))))
+
+(def pretty-row
+ (fn [i]
+ (match i
+ '{:number n
+ :title tit
+ :state s
+ :author-name an
+ :modified-at m-a}
+ (string-append
+ (wrap-cell (pretty-state s) :state)
+ (wrap-cell (show n) :number)
+ (wrap-cell tit :title)
+ (wrap-cell an :author)
+ (wrap-cell m-a :modified-at)))))
(def pretty-comment
(fn [c]
@@ -182,7 +233,6 @@
:comments cs}
(string-append
(pretty-headline i) "\n\n"
- "created at " c-a "\n\n"
p "\n\n"
"Comments\n"
"--------\n\n"
@@ -204,7 +254,10 @@
(fn [machine options]
(def mk-key
- (fn [diff] [(pretty-headline diff) diff]))
+ (fn [diff]
+ (if (lookup :fancy options)
+ [(pretty-headline diff) diff]
+ [(pretty-row diff) diff])))
(def filt
(match (map (fn [opt] (read (string-append ":" opt))) (lookup :state options))
@@ -240,7 +293,9 @@
(do (simple-add-comment! machine diff-number added-comment (get-git-username!))
(string-append "Sent comment: " added-comment)))))
_ (put-str! "No selection made."))
- (map (fn [d] (put-str! (first d))) items)))))
+ (do
+ (put-str! (pretty-table-header))
+ (map (fn [d] (put-str! (first d))) items))))))
(def show-diff!
"Shows a single DIFF `n`"
@@ -316,4 +371,3 @@
["--help"] (put-str! help)
(/cons 'cmd _) (cmd-parse-failure (string-append "Unknown command: " cmd))
[] (put-str! help))))
-
diff --git a/test/e2e/DiffAppTest.hs b/test/e2e/DiffAppTest.hs
index 1eebb54..bda2bd4 100644
--- a/test/e2e/DiffAppTest.hs
+++ b/test/e2e/DiffAppTest.hs
@@ -14,15 +14,19 @@ test_diff_propose = testCaseSteps "diff propose" $ \step -> do
_ <- runTestCommand "git" ["config", "--global", "user.name", "Alice"]
_ <- runTestCommand "git" ["config", "--global", "user.email", "[email protected]"]
_ <- runTestCommand' "rad-project" ["init"] ["project-name", "project desc", "1"]
- _ <- runTestCommand "git" ["commit", "--allow-empty", "--message", "first commit"]
+ _ <- runTestCommand "touch" ["test"]
+ _ <- runTestCommand "git" ["add", "test"]
+ _ <- runTestCommand "git" ["commit", "--message", "first commit"]
commitSha <- runTestCommand "git" ["rev-parse", "--short", "HEAD"]
step "rad diff propose"
_ <- runTestCommand "rad-diff" ["propose", "HEAD"]
listOutput <- runTestCommand "rad-diff" ["list"]
- assertContains listOutput $ "(pending) [Alice] " <> commitSha <> " - first commit | DIFF 0"
+ assertContains listOutput $ "state #"
+ assertContains listOutput $ "pending 0"
showOutput <- runTestCommand "rad-diff" ["show", "0"]
- assertContains showOutput $ "(pending) [Alice] " <> commitSha <> " - first commit | DIFF 0"
+ assertContains showOutput $ "pending 0"
+ assertContains showOutput $ "From " <> commitSha
assertContains showOutput $ "Comments\n---"