Skip to content

Commit

Permalink
Display shorter paths to avoid lines breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
mogenslund committed Jun 6, 2021
1 parent 371f2b5 commit b112608
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/liq/editor.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,23 @@
([nameid]
(when (@state ::output-handler)
(apply-to-buffer nameid buffer/update-tow)
(let [buf (get-buffer nameid)]
(let [buf (get-buffer nameid)
cols (((-> @state ::output-handler :dimensions)) :cols)
namepart (util/shorten-path (or (buf ::buffer/filename) (buf ::buffer/name)) (max 10 (- cols 36)))
spaces (format (str "%-" (max 1 (- cols (count namepart) 36)) "s") "")
pct (int (/ (* 100.0 (-> buf ::buffer/cursor ::buffer/row)) (-> buf ::buffer/lines count)))]
(apply-to-buffer "*status-line*"
#(-> %
buffer/clear
(buffer/insert-string
(str (or (buf ::buffer/filename) (buf ::buffer/name)) " "
(str namepart ; (or (buf ::buffer/filename) (buf ::buffer/name)) " "
(if (buffer/dirty? buf) " [+] " " ")
(cond (= (buf ::buffer/mode) :insert) "-- INSERT -- "
(= (buf ::buffer/mode) :visual) "-- VISUAL -- "
true " ")
(-> buf ::buffer/cursor ::buffer/row) "," (-> buf ::buffer/cursor ::buffer/col)))
spaces
(-> buf ::buffer/cursor ::buffer/row) "," (-> buf ::buffer/cursor ::buffer/col)
" " pct "%"))
buffer/beginning-of-buffer
buffer/update-tow))
;((@state ::output-handler) (get-buffer "*status-line*"))
Expand Down
14 changes: 8 additions & 6 deletions src/liq/modes/buffer_chooser_mode.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

(defn load-content
[buf]
(-> buf
buffer/clear
(buffer/insert-string (str/join "\n"
(map #(str (% ::buffer/name) (if (buffer/dirty? %) " [+]" " "))
(rest (editor/all-buffers)))))
buffer/beginning-of-buffer))
(let [cols (((-> @editor/state ::editor/output-handler :dimensions)) :cols)]
(-> buf
buffer/clear
(buffer/insert-string (str/join "\n"
(map #(str (util/shorten-path (% ::buffer/name) (max 10 (- cols 8)))
(if (buffer/dirty? %) " [+]" " "))
(rest (editor/all-buffers)))))
buffer/beginning-of-buffer)))

(defn run
[]
Expand Down
18 changes: 18 additions & 0 deletions src/liq/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,21 @@
(str/join "\n" filtered) "\n"
(str/join "\n" stacklines))))

(defn shorten-path
"Display shorter version of path"
[path width]
(if (<= (count path) width)
path
(let [slashes (count (re-seq #"[/\\]" path))
p1 (loop [n 0]
(let [p (str/replace-first
path
(re-pattern (str "(?<=[^/\\\\][/\\\\])([^/\\\\]*[/\\\\]){" n "}[^/\\\\]*"))
"...")]
(if (or (<= (count p) width) (>= n (- slashes 3)))
p
(recur (inc n)))))
p2 (str/replace-first path #".*(?=[/\\])" "...")]
(if (<= (count p1) width)
p1
p2))))

0 comments on commit b112608

Please sign in to comment.