Begin the process of replying. ^R is the reply command. So far just clears the edit window if no article is selected.

Also began creation of the object-mother.
This commit is contained in:
Robert C. Martin 2022-04-18 16:03:11 -05:00
parent 5fde839565
commit 6cbeceb035
6 changed files with 110 additions and 4 deletions

View File

@ -0,0 +1,19 @@
(ns more-speech.ui.article-window-spec
(:require [speclj.core :refer :all]
[more-speech.ui.article-window :refer :all]
[more-speech.ui.object-mother :as mom]))
(describe "Reply"
(let [state (mom/make-test-state)
article-window (get-in state [:application :article-window])
article-frame (get article-window :text-frame)]
(it "will not create reply if no article is being displayed"
(let [article-frame (assoc article-frame :displayed-article nil)
state (assoc-in state (:path article-frame) article-frame)
state (reply-to-article state article-frame)
edit-frame (get-in state [:application :edit-window :text-frame])]
(should= [""] (get edit-frame :text))
(should= [0 0] (get edit-frame :insertion-point))
))
)
)

View File

@ -0,0 +1,63 @@
(ns more-speech.ui.object-mother
(:require
[more-speech.ui.graphics :refer [graphics]]
[more-speech.ui.widget :as w]
[more-speech.ui.application :as app])
)
(defrecord graphics-dummy []
graphics
(screen_height [this]
1)
(screen_width [this]
)
(text_align [this alignment]
)
(text_color [this color]
)
(stroke [this color]
)
(no_stroke [this]
)
(stroke_weight [this weight]
)
(fill [this color]
)
(no_fill [this]
)
(rect_mode [this mode]
)
(rect [this rect]
)
(line [this line]
)
(polygon [this points]
)
(with_translation [this translation f]
)
(text_font [this font]
)
(line_height [this]
1)
(pos_width [this pos]
1)
(text_width [this s]
)
(text [this text-spec]
)
(get_mouse [this]
)
(cursor [this mode]
)
(get_time [this]
))
(defn make-test-state []
(let [graphics (->graphics-dummy)
application (app/map->application {:path [:application] :graphics graphics})
application (w/setup-widget application {})
state {:application application}
state (w/setup-child-widgets application state)]
state))

View File

@ -1,4 +1,5 @@
;;Stories
;; - Clean up java schnorr library.
;; - Threading does not work quite right. Do some diagnosis.
;; - Reply
;; - Mark read and highlight properly.

View File

@ -8,11 +8,13 @@
[more-speech.ui.formatters :as f]
[more-speech.ui.cursor :as cursor]
[more-speech.ui.config :as config]
[more-speech.ui.app-util :as app-util]))
[more-speech.ui.app-util :as app-util]
[more-speech.ui.edit-window :as edit]))
(declare get-article-line-height
draw-article
update-article)
update-article
process-key)
(defrecord article-window-controls []
text-window-controls
@ -22,8 +24,8 @@
(draw-article state frame))
(update-elements [_c state frame]
(update-article state frame))
(key-pressed [_c state _frame _key]
state)
(key-pressed [_c state frame key]
(process-key state frame key))
)
(defn make-article [id name time body]
@ -86,3 +88,17 @@
(assoc frame :displayed-article marked-up-article
:total-elements 2)))]
(assoc-in state (:path frame) frame)))
(declare reply-to-article)
(defn process-key [state frame {:keys [_key raw-key]}]
(condp = (int raw-key)
config/ctrl-r (reply-to-article state frame)
state)
)
(defn reply-to-article [state frame]
(if (nil? (:displayed-article frame))
(edit/clear-edit-window state)
state))

View File

@ -1,6 +1,7 @@
(ns more-speech.ui.config)
(def ctrl-s 19)
(def ctrl-r 18)
(def no-fill [nil])
(def black [0 0 0])

View File

@ -148,3 +148,9 @@
state (assoc-in state (:path frame) frame)]
(async/>!! send-chan [:event event])
state))
(defn clear-edit-window [state]
(let [edit-frame (get-in state [:application :edit-window :text-frame])
edit-frame (assoc edit-frame :text [""] :insertion-point [0 0])]
(assoc-in state (:path edit-frame) edit-frame)))