Skip to content

Commit

Permalink
Some minor termed/TermApp improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Melchizedek6809 committed Apr 25, 2024
1 parent dd29875 commit 83c8eee
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
10 changes: 9 additions & 1 deletion stdlib_modules/app/termed.nuj
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,16 @@
(- (inc self.cur-buffer.pos-y)
self.cur-buffer.scroll-y)))

(defn stop (self)
(:stop self.term))

(defn quit (self)
(:stop self.term)
(:quit self.term)
(exit 0))

(defn set-parent! (self parent)
(set! self.term parent))

(defn scroll-into-view (self)
(def buf self.cur-buffer)
(def frame-height (- self.screen-height 3))
Expand Down Expand Up @@ -137,6 +143,7 @@
(defn handle-event (self event)
(case event.T
(:blur (set! self.focus? #f))
(:reparent (set! self.term event.parent))
(:focus (set! self.focus? #t))
(:draw (:scroll-into-view self) (:draw-screen self))
(:resize (:resize self event.width event.height))
Expand Down Expand Up @@ -212,6 +219,7 @@
(set! key-down-handler :ret :insert-newline)
(set! cx-key-down-handler :h :mark-whole-buffer)
(set! cx-key-down-handler :3 (fn () (:split-window-right self)))
(set! cx-key-down-handler :0 (fn () (:stop self)))
(set! cx-key-down-handler :C-c (fn () (:quit self)))))

(defn main (args)
Expand Down
16 changes: 15 additions & 1 deletion stdlib_modules/term/TermApp.nuj
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@
:prototype* self })
(:resize ret))

(defn handle-event (self event)
(:handle-event self.child event))

(defn split-window-right (self right-child)
(def new (:new TermAppVerticalSplit self self.child right-child))
(set! self.child new)
(:handle-event new {:T :resize :width self.width :height self.height}))

(defn run (self child)
(when self.child
(set! self.child child)
(let ((s (:get-size self)))
(:handle-event child {:T :resize :width s.width :height s.height})
(:handle-event child {:T :focus})
(:handle-event child {:T :draw}))
(return))
(try (fn (e) (:stop self)
(efmtln "{e:?}")
(exit 0))
Expand All @@ -54,7 +64,11 @@

(defn stop (self)
(:stop self.term)
self)
(exit 0))

(defn quit (self)
(:stop self.term)
(exit 0))

(defn windmove-left (self) #f)
(defn windmove-right (self) #f)
Expand Down
32 changes: 22 additions & 10 deletions stdlib_modules/term/TermAppVerticalSplit.nuj
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,27 @@
(if self.right-child-active?
(set! self.right-child child)
(set! self.left-child child))
(child {:T :resize :width (:child-width self) :height s.height})
(child {:T :resize :width (:child-width self) :height self.height})
(child {:T :draw}))

(defn stop (self) (:stop self.parent))
(defn active-child (self)
(if self.right-child-active?
self.right-child
self.left-child))

(defn inactive-child (self)
(if self.right-child-active?
self.left-child
self.right-child))

(defn stop (self)
(def child (:inactive-child self))
(child {:T :reparent :parent self.parent})
(:run self.parent child))

(defn quit (self)
(:quit self.parent))

(defn flip (self) (:flip self.parent))
(defn draw-char (self char x y color)
(when (or (>= x (:child-width self))
Expand All @@ -88,17 +105,9 @@
(set! h (min (- self.height y) (- h 1)))
(:draw-text self.parent text (+ x (:child-offset self)) y w h color))

(defn stop (self)
(:stop self.parent))

(defn set-parent! (self parent)
(set! self.parent parent))

(defn run (self child)
(if self.right-child-active?
(set! self.right-child child)
(set! self.left-child child)))

(defn clear-screen (self)
(:clear-screen self.parent))

Expand All @@ -109,6 +118,9 @@
(set! self.right-child-active? #t)
(:handle-event self.right-child {:T :resize :width (:child-width self) :height self.height})
(return))
(when (= :reparent event.T)
(set! self.parent event.parent)
(return))
(when (= :draw event.T)
(set! self.right-child-active? #f)
(:handle-event self.left-child event)
Expand Down

0 comments on commit 83c8eee

Please sign in to comment.