Skip to content

Commit a3ef9c8

Browse files
authored
Merge pull request #9 from vision-05/dev
Dev
2 parents 42c3eda + b65c3e5 commit a3ef9c8

File tree

16 files changed

+326
-79
lines changed

16 files changed

+326
-79
lines changed

bettercode/.calva/output-window/output.calva-repl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
; Happy coding! ♥️
66

77
; Jacking in...
8-
; Starting Jack-in Terminal: lein update-in :dependencies conj '[nrepl,"0.8.3"]' -- update-in :plugins conj '[cider/cider-nrepl,"0.25.8"]' -- update-in '[:repl-options,:nrepl-middleware]' conj '["cider.nrepl/cider-middleware"]' -- with-profile +uberjar repl :headless
8+
; Starting Jack-in Terminal: lein update-in :dependencies conj '[nrepl,"0.8.3"]' -- update-in :plugins conj '[cider/cider-nrepl,"0.26.0"]' -- update-in '[:repl-options,:nrepl-middleware]' conj '["cider.nrepl/cider-middleware"]' -- with-profile +uberjar repl :headless
99
; Hooking up nREPL sessions...
1010
; Connected session: clj
1111
; TIPS:
@@ -15,10 +15,6 @@
1515
; - `alt+up` and `alt+down` traverse up and down the REPL command history
1616
; when the cursor is after the last contents at the prompt
1717
; - Clojure lines in stack traces are peekable and clickable.
18-
clj꞉bettercode.core꞉> 
18+
clj꞉bettercode.core꞉>  ; Use `alt+enter` to evaluate
1919
; Jack-in done.
2020
clj꞉bettercode.core꞉> 
21-
(println "this is based on CIDER")
22-
this is based on CIDER
23-
nil
24-
clj꞉bettercode.core꞉> 

bettercode/.lsp/sqlite.db

4.63 MB
Binary file not shown.

bettercode/src/bettercode/core.clj

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
[clojure.edn :as edn]
1212
[bettercode.elements]
1313
[bettercode.css]
14-
[bettercode.events])
14+
[bettercode.events]
15+
[bettercode.utilelements])
1516
(:import [javafx.application Platform]))
1617

1718
(def protocol
@@ -33,36 +34,73 @@
3334
(d/chain (tcp/client {:host host :port port})
3435
#(wrap-duplex-stream protocol %)))
3536

36-
(def *context
37-
(atom
38-
(fx/create-context {:title ""
39-
:file-path "/home/tim/foo.txt"
40-
:text-editor ""
41-
:anchor-pos 0
42-
:caret-pos 0
43-
:dir-contents {:dir-path ""
44-
:directories []
45-
:files []}}
46-
#(cache/lru-cache-factory % :threshold 4096))))
37+
(defn app [{:keys [fx/context tclient]}]
38+
{:fx/type fx/ext-many
39+
:desc [{:fx/type :stage
40+
:title "BetterCode"
41+
:showing true
42+
:width 768
43+
:height 1080
44+
:min-width 768
45+
:min-height 1080
46+
:resizable true
47+
:scene {:fx/type :scene
48+
:fill "#23282D"
49+
:stylesheets [(::css/url bettercode.css/style)]
50+
:root {:fx/type :v-box
51+
:children [{:fx/type :menu-bar
52+
:max-height 10 ;somehow make the height actually work
53+
:style-class "root-menu-bar"
54+
:menus [{:fx/type :menu
55+
:text "file"
56+
:style-class "root-menu-bar-item"
57+
:items [{:fx/type :menu-item
58+
:style-class "root-menu-bar-item-sub-item"
59+
:text "open"
60+
:on-action {:event/type :bettercode.events/openfex
61+
:tclient tclient}}
62+
{:fx/type :menu-item
63+
:text "save"
64+
:on-action {:event/type :bettercode.events/saveevent
65+
:tclient tclient}}]}]}
66+
{:fx/type bettercode.elements/editor-pane
67+
:tclient tclient
68+
:text ""
69+
:file-path "BetterCode"
70+
:style-class "root"}]}}}
71+
{:fx/type :stage
72+
:title "Files"
73+
:showing (fx/sub context :file-explorer-show)
74+
:width 500
75+
:height 350
76+
:resizable false
77+
:always-on-top true
78+
:modality :application-modal
79+
:scene {:fx/type :scene
80+
:fill "#23282D"
81+
:stylesheets [(::css/url bettercode.css/style)]
82+
:root {:fx/type bettercode.utilelements/file-window
83+
:tclient tclient}}}]})
4784

4885
;create file opening screen
49-
(defn -main []
86+
(defn -main [hostname & args]
5087
(Platform/setImplicitExit true)
51-
(let [c @(client "localhost" 8080)]
88+
(println "started")
89+
(let [c @(client (if hostname hostname "localhost") 8080)
90+
msg @(s/put! c ["get-dir"])
91+
dirs @(s/take! c)
92+
*context
93+
(atom
94+
(fx/create-context {:title "BetterCode"
95+
:file-path "/home/tim/foo.txt"
96+
:text-editor ""
97+
:dir-contents dirs
98+
:cur-path "/home/tim/foo.txt"
99+
:file-explorer-show true
100+
:file-name-entered ""}
101+
#(cache/lru-cache-factory % :threshold 4096)))]
52102
(fx/create-app *context
53103
:event-handler bettercode.events/handle-event
54104
:desc-fn (fn [_]
55-
{:fx/type :stage
56-
:title "BetterCode"
57-
:showing true
58-
:width 768
59-
:height 1080
60-
:min-width 768
61-
:min-height 1080
62-
:resizable true
63-
:scene {:fx/type :scene
64-
:fill "#23282D"
65-
:stylesheets [(::css/url bettercode.css/style)]
66-
:root {:fx/type bettercode.elements/editor-pane
67-
:tclient c
68-
:style-class "root"}}}))))
105+
{:fx/type app
106+
:tclient c}))))

bettercode/src/bettercode/css.clj

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,48 @@
44
(def style
55
(css/register ::style
66
(let [back-background-color "#2E3440"
7-
status-background-color "#434C5E"
7+
status-background-color "#6183AE"
88
text-color "#ECEFF4"
9-
border-color "#4C566A"
9+
border-color "#5E81AC"
1010
background-color "#2E3440"
1111
scroll-color "#434C5E22"
1212
thumb-color "#4C566A44"
13-
highlight-color "#4C566ACC"]
13+
highlight-color "#5E81AC"]
1414
{".root" {:-fx-background-color back-background-color
15+
:-fx-text-fill text-color
16+
"-menu-bar" {:-fx-background-color highlight-color
17+
:-fx-text-fill text-color
18+
:-fx-padding 0
19+
:-fx-margin 0
20+
" .label" {:-fx-font-size 12
21+
:-fx-text-fill text-color}
22+
"-item" {:-fx-text-fill text-color
23+
:-fx-background-color highlight-color
24+
:-fx-padding 0
25+
:-fx-margin 0
26+
" .label" {:-fx-font-size 10
27+
:-fx-text-fill text-color}
28+
"-sub-item" {:-fx-text-fill text-color
29+
:-fx-padding 0
30+
:-fx-margin 0
31+
:-fx-background-color highlight-color
32+
:-fx-control-inner-background highlight-color}}}
33+
"-fsview" {:-fx-control-inner-background back-background-color
34+
"-button" {:-fx-background-color back-background-color
35+
:-fx-border-color border-color
36+
:-fx-text-fill text-color
37+
:-fx-border-radius 5
38+
:-fx-padding [4 4 4 4]
39+
":hover" {:-fx-background-color border-color
40+
:-fx-background-radius 5}}
41+
"> .virtual-flow" {:-fx-background-color background-color
42+
:-fx-hbar-policy :as-needed
43+
:-fx-vbar-policy :as-needed
44+
"> .corner" {:fx-background-color scroll-color}
45+
"> .scroll-bar" {":horizontal" {:-fx-background-color scroll-color
46+
" .thumb" {:-fx-background-color thumb-color}}
47+
":vertical" {:-fx-background-color scroll-color
48+
" .thumb" {:-fx-background-color thumb-color}}}}}
1549
"-text-area" {"-status" {:-fx-background-color status-background-color
1650
:-fx-text-fill text-color
1751
:-fx-highlight-fill status-background-color}

bettercode/src/bettercode/elements.clj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
[bettercode.css]
44
[bettercode.events]))
55

6-
(defn status-bar [{:keys [fx/context]}]
6+
(defn status-bar [{:keys [fx/context file-path]}]
77
{:fx/type :text-field
88
:min-height 32
99
:max-height 32
1010
:min-width 740
1111
:editable false
1212
:alignment :center
13-
:text (fx/sub-val context :file-name)
13+
:text file-path
1414
:style-class "root-text-area-status"})
1515

1616
(defn text-edit [{:keys [fx/context tclient]}]
@@ -19,11 +19,11 @@
1919
:pref-height 896
2020
:font "Roboto Mono"
2121
:cursor :text
22-
:text (fx/sub-val context :text-editor)
22+
:text (fx/sub context :text-editor)
2323
:style-class "root-text-area-editor"
2424
:on-key-typed {:event/type :bettercode.events/type-text
25-
:fx/sync true
26-
:tclient tclient}
25+
:fx/sync true
26+
:tclient tclient}
2727
:on-mouse-clicked {:event/type :bettercode.events/mouse-click
2828
:fx/sync true
2929
:tclient tclient}})
@@ -41,6 +41,7 @@
4141
:min-width 768
4242
:padding 14
4343
:children [{:fx/type status-bar
44+
:file-path (fx/sub context :file-path)
4445
:h-box/hgrow :always}]})
4546

4647
(defn editor-row [{:keys [fx/context tclient]}]

bettercode/src/bettercode/events.clj

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,87 @@
88
(defmethod handle-event :default [e]
99
(println "non event"))
1010

11+
(defn fex-back [context tclient]
12+
(let [cur-dir (fx/sub-val context :cur-path)
13+
prev-dir (clojure.string/join "/" (drop-last (clojure.string/split cur-dir #"/")))
14+
msg @(s/put! tclient ["get-dir" prev-dir]) ;get parent from :cur-path
15+
dir-contents @(s/take! tclient)]
16+
{:context (fx/swap-context context
17+
assoc
18+
:dir-contents dir-contents
19+
:cur-path prev-dir)}))
20+
21+
;TODO: send event for replacing highlighted text, send event for inserting text
22+
23+
(defmethod handle-event ::type-filename [{:keys [fx/event fx/context]}]
24+
{:context (fx/swap-context context
25+
assoc
26+
:file-name-entered (.getCharacters (.getSource event)))})
27+
28+
(defmethod handle-event ::newclick [{:keys [fx/event fx/context tclient]}]
29+
(let [file-name (fx/sub-val context :file-name-entered)
30+
file-path-new (str (fx/sub-val context :cur-path) "/" (.toString file-name))
31+
msg @(s/put! tclient ["open-file" file-path-new])]
32+
(println "CUR-PATH: " (fx/sub-val context :cur-path))
33+
{:context (fx/swap-context context ;how the fuck do I do this
34+
assoc
35+
:file-path file-path-new
36+
:text-editor ""
37+
:file-explorer-show false)}))
38+
39+
(defmethod handle-event ::openfex [{:keys [fx/event fx/context]}]
40+
{:context (fx/swap-context context
41+
assoc
42+
:file-explorer-show true)})
43+
44+
(defmethod handle-event ::saveevent [{:keys [fx/event fx/context tclient]}]
45+
@(s/put! tclient ["save-file" (fx/sub-val context :file-path)])
46+
{:context context})
47+
48+
(defmethod handle-event ::backclick [{:keys [fx/event fx/context tclient]}]
49+
(fex-back context tclient))
50+
51+
(defmethod handle-event ::fexclick [{:keys [fx/event fx/context tclient]}]
52+
(let [entry (.getText (.getTarget event))
53+
entry-info (subs entry 0 5)
54+
entry-name (subs entry 5)]
55+
(cond
56+
(= entry-info "DIR: ") (do @(s/put! tclient ["get-dir" entry-name])
57+
(let [dir-contents @(s/take! tclient)]
58+
(println dir-contents)
59+
{:context (fx/swap-context context
60+
assoc
61+
:dir-contents dir-contents
62+
:cur-path entry-name)}))
63+
(= entry-info "FIL: ") (do @(s/put! tclient ["open-file" entry-name])
64+
(let [file-contents @(s/take! tclient)]
65+
(println file-contents)
66+
{:context (fx/swap-context context
67+
assoc
68+
:file-path entry-name
69+
:text-editor file-contents
70+
:file-explorer-show false)})))))
71+
1172
(defmethod handle-event ::type-text [{:keys [fx/event fx/context tclient]}]
12-
@(s/put! tclient ["text-edit" (fx/sub-val context :file-path) (fx/sub-val context :caret-pos) (.getCharacter event)])
73+
(println event) ;get soruce of event, prefereably
74+
(let [message ["text-edit" (fx/sub-val context :file-path) (.getCharacter event) (.getCaretPosition (.getSource event))]
75+
length (- (fx/sub-val context :anchor-pos) (fx/sub-val context :caret-pos))]
76+
(println length (conj message length))
77+
@(s/put! tclient (if (> length 0) (assoc (conj message length) 3 (.getAnchor (.getSource event))) message)))
1378
(println @(s/take! tclient))
1479
{:context (fx/swap-context context
1580
assoc
1681
:anchor-pos (.getAnchor (.getSource event))
1782
:caret-pos (.getCaretPosition (.getSource event)))})
1883

19-
20-
;similar event must be made for arrow key press
2184
(defmethod handle-event ::mouse-click [{:keys [fx/event fx/context tclient]}]
22-
(println "click")
85+
(println (:fx/event event))
2386
(println (.getSource event))
2487
{:context (fx/swap-context context
2588
assoc
2689
:anchor-pos (.getAnchor (.getSource event))
2790
:caret-pos (.getCaretPosition (.getSource event)))})
2891

29-
(defmethod handle-event ::open-file [{:keys [fx/event fx/context tclient]}]
30-
(println "getting file")
31-
@(s/put! tclient ["open-file" (fx/sub-val context :file-path)])
32-
{:context (fx/swap-context context
33-
assoc
34-
:text-editor
35-
@(s/take! tclient))})
36-
3792
(defmethod handle-event ::close-file [{:keys [fx/event fx/context tclient]}]
3893
(println "requesting close file")
3994
@(s/put! tclient ["close-file" (fx/sub-val context :file-path)]))
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(ns bettercode.utilelements
2+
(:require [cljfx.api :as fx]
3+
[manifold.stream :as s]
4+
[bettercode.events]))
5+
6+
(defn back-button [{:keys [fx/context tclient]}]
7+
{:fx/type :button
8+
:style-class "root-fsview-button"
9+
:on-mouse-clicked {:event/type :bettercode.events/backclick
10+
:tclient tclient}
11+
:text "Back"})
12+
13+
(defn new-button [{:keys [fx/context tclient]}]
14+
{:fx/type :button
15+
:style-class "root-fsview-button"
16+
:on-mouse-clicked {:event/type :bettercode.events/newclick
17+
:fx/sync true
18+
:tclient tclient}
19+
:text "New"})
20+
21+
(defn button-layout [{:keys [fx/context tclient]}]
22+
{:fx/type :h-box
23+
:alignment :center-right
24+
:padding 5
25+
:spacing 10
26+
:children [{:fx/type back-button
27+
:tclient tclient}
28+
{:fx/type new-button
29+
:tclient tclient}]})
30+
31+
(defn file-view [{:keys [fx/context tclient]}]
32+
{:fx/type :list-view
33+
:items (fx/sub context :dir-contents)
34+
:style-class "root-fsview"
35+
:on-mouse-clicked {:event/type :bettercode.events/fexclick
36+
:fx/sync true
37+
:tclient tclient}})
38+
39+
(defn file-window [{:keys [fx/context tclient]}]
40+
{:fx/type :v-box
41+
:children [{:fx/type file-view
42+
:tclient tclient}
43+
{:fx/type :text-field
44+
:on-key-typed {:event/type :bettercode.events/type-filename
45+
:fx/sync true}}
46+
{:fx/type button-layout
47+
:tclient tclient}]})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; This is the Calva evaluation results output window.
2+
; TIPS: The keyboard shortcut `ctrl+alt+c o` shows and focuses this window
3+
; when connected to a REPL session.
4+
; Please see https://calva.io/output/ for more info.
5+
; Happy coding! ♥️
6+
7+
; Jacking in...
8+
; Starting Jack-in Terminal: lein update-in :dependencies conj '[nrepl,"0.8.3"]' -- update-in :plugins conj '[cider/cider-nrepl,"0.25.10"]' -- update-in '[:repl-options,:nrepl-middleware]' conj '["cider.nrepl/cider-middleware"]' -- with-profile +uberjar repl :headless
9+
; Hooking up nREPL sessions...
10+
; Connected session: clj
11+
; TIPS:
12+
; - You can edit the contents here. Use it as a REPL if you like.
13+
; - `alt+enter` evaluates the current top level form.
14+
; - `ctrl+enter` evaluates the current form.
15+
; - `alt+up` and `alt+down` traverse up and down the REPL command history
16+
; when the cursor is after the last contents at the prompt
17+
; - Clojure lines in stack traces are peekable and clickable.
18+
clj꞉bettercodeserver.core꞉>  ; Use `alt+enter` to evaluate
19+
; Jack-in done.
20+
clj꞉bettercodeserver.core꞉> 

0 commit comments

Comments
 (0)