clojurecember

My attempt to learn at least a little bit of Clojure each day in December
git clone https://git.sr.ht/~jbauer/clojurecember
Log | Files | Refs | README | LICENSE

commit 742ba448cc08b7088d6021540c5776f025a4d700
parent d823792ff47ce64aff36a14ff5dbc20be8d6930d
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Thu, 22 Dec 2022 21:44:51 -0500

DEC21+22

Diffstat:
MREADME.md | 8++++++++
Mtext-editor/src/text_editor/core.clj | 28+++++++++++++++++++++++-----
2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md @@ -45,3 +45,11 @@ Improved the save features of the text editor: added a Save As and made the New option make an entirely new file, instead of just blanking the text area. Also added some labels for the current file and some feedback when a file was saved, opened, etc. + +## DEC21 + +Played around with trying to get a line count side-bar thing (like vim's `numbers`). + +## DEC22 + +Made progress on the line count functionality, decided that it was not really possible or would be too awkward with (how I understand this) GUI framework. What kind of text editor needs a line count anyways? diff --git a/text-editor/src/text_editor/core.clj b/text-editor/src/text_editor/core.clj @@ -26,6 +26,20 @@ (editor-pane :id "editor" :text (slurp @current-file)) (editor-pane :id "editor" :text ""))) +(defn calculate-linecount [] + (if (.exists @current-file) + (->> (slurp @current-file) + (re-seq #"\n") + count) + 1)) + +(defn format-linecount [count] + (vec (map str (range 1 (inc count))))) + +(def linecount + (vertical-panel + :items (format-linecount (calculate-linecount)))) + (defn set-current-file [f] (swap! current-file (constantly f))) @@ -129,9 +143,10 @@ (mig-panel :constraints ["fill, ins 0"] :items [[(scrollable editor) "grow"] - [current-file-label "dock south"] - [(separator) "dock south"] - [status-label "dock south"]])) + [linecount "west, grow"] + [current-file-label "south"] + [(separator) "south"] + [status-label "south"]])) (defn filemenu [] (value (select menubar [:file]) @@ -142,12 +157,15 @@ (add-watch current-file nil - (fn [key ref old new] (text! current-file-label (str new)))) + (fn [key ref old new] + (do + (text! current-file-label (str new)) + (replace! main-panel linecount (vertical-panel :items (format-linecount (calculate-linecount))))))) (invoke-later (-> (frame :title "Text Editor", :menubar topbar :content main-panel - :minimum-size [640 :by 480] + :minimum-size [800 :by 600] :on-close :exit) pack! show!)))