summaryrefslogtreecommitdiff
path: root/fnl
diff options
context:
space:
mode:
authorMike Vink <>2023-04-08 17:18:41 +0200
committerMike Vink <>2023-04-08 17:18:57 +0200
commit741f3405e712f13b55aafd8730b61dca4248b4ae (patch)
tree656343b5b64878cd074f860b5df1bcfd56a5e94f /fnl
parent29d3285f7fee248b518e170214795d772d1105ef (diff)
play around with pict
Diffstat (limited to 'fnl')
-rw-r--r--fnl/conf/cmd.fnl3
-rw-r--r--fnl/conf/exctl/frames/frame.fnl64
-rw-r--r--fnl/conf/exctl/frames/vec.fnl28
-rw-r--r--fnl/conf/exctl/init.fnl16
-rw-r--r--fnl/conf/exctl/painters.fnl50
-rw-r--r--fnl/conf/exctl/painters/buf.fnl25
-rw-r--r--fnl/conf/exctl/spec.fnl42
7 files changed, 227 insertions, 1 deletions
diff --git a/fnl/conf/cmd.fnl b/fnl/conf/cmd.fnl
index b7e96ae..6b89ff6 100644
--- a/fnl/conf/cmd.fnl
+++ b/fnl/conf/cmd.fnl
@@ -17,7 +17,8 @@
(vim.api.nvim_win_close w false)))
(fn visible? [b]
- (if (or (= nil b) (not (vim.api.nvim_buf_is_valid b))) false)
+ (if (or (= nil b) (not (vim.api.nvim_buf_is_valid b)))
+ false)
(local wlist (vim.fn.win_findbuf b))
(print (vim.inspect wlist))
(< 0 (length wlist)))
diff --git a/fnl/conf/exctl/frames/frame.fnl b/fnl/conf/exctl/frames/frame.fnl
new file mode 100644
index 0000000..f74e88d
--- /dev/null
+++ b/fnl/conf/exctl/frames/frame.fnl
@@ -0,0 +1,64 @@
+(local vec (require :conf.exctl.frames.vec))
+(local m {})
+(local frame {})
+
+;; frame is interpreted as matrix coords
+;; origin ------------------> ne-edge
+;; |
+;; |
+;; |
+;; |
+;; |
+;; |
+;;\ /
+;; .
+;; sw-edge
+(fn frame.make [self ori width height]
+ (local f {: ori : width : height})
+ (setmetatable f self)
+ (set self.__index self)
+ f)
+
+(fn frame.origin [f]
+ f.ori)
+
+(fn frame.width-edge [f]
+ f.width)
+
+(fn frame.height-edge [f]
+ f.height)
+
+(fn m.frame->coord [f]
+ (fn [v]
+ (P :a (vec.scale (v:x-coord) (f:width-edge)))
+ (P :b (vec.scale (v:y-coord) (f:height-edge)))
+ (P :added (vec.add (vec.scale (v:x-coord) (f:width-edge))
+ (vec.scale (v:y-coord) (f:height-edge))))
+ (vec.add (f:origin)
+ (vec.add (vec.scale (v:x-coord) (f:width-edge))
+ (vec.scale (v:y-coord) (f:height-edge))))))
+
+(fn m.width [f]
+ (let [width-edge (f:width-edge)]
+ (width-edge:x-coord)))
+
+(fn m.height [f]
+ (let [height-edge (f:height-edge)]
+ (height-edge:y-coord)))
+
+(fn m.frame->open-win-options [f anchor]
+ (local coord (m.frame->coord f))
+ (local ori (f:origin))
+ (local width-edge (f:width-edge))
+ (local height-edge (f:height-edge))
+ {:width (width-edge:x-coord)
+ :height (height-edge:y-coord)
+ :col (ori:x-coord)
+ :row (ori:y-coord)
+ :anchor :NW
+ :relative :editor})
+
+(setmetatable m {:__call (fn [self ...]
+ (frame:make ...))})
+
+m
diff --git a/fnl/conf/exctl/frames/vec.fnl b/fnl/conf/exctl/frames/vec.fnl
new file mode 100644
index 0000000..4a9515d
--- /dev/null
+++ b/fnl/conf/exctl/frames/vec.fnl
@@ -0,0 +1,28 @@
+(local m {})
+(local vec {})
+
+(fn vec.make [self x y]
+ (local v {: x : y})
+ (setmetatable v self)
+ (set self.__index self)
+ v)
+
+(fn vec.x-coord [v]
+ v.x)
+
+(fn vec.y-coord [v]
+ v.y)
+
+(fn m.add [v1 v2]
+ (vec:make (+ (v1:x-coord) (v2:x-coord)) (+ (v1:y-coord) (v2:y-coord))))
+
+(fn m.sub [v1 v2]
+ (vec:make (- (v1:x-coord) (v2:x-coord)) (- (v1:y-coord) (v2:y-coord))))
+
+(fn m.scale [a v]
+ (vec:make (math.floor (* a (v:x-coord))) (math.floor (* a (v:y-coord)))))
+
+(fn m.vec [...]
+ (vec:make ...))
+
+m
diff --git a/fnl/conf/exctl/init.fnl b/fnl/conf/exctl/init.fnl
new file mode 100644
index 0000000..5248707
--- /dev/null
+++ b/fnl/conf/exctl/init.fnl
@@ -0,0 +1,16 @@
+(local vec (require :conf.exctl.frames.vec))
+(local frame (require :conf.exctl.frames.frame))
+(tset package.loaded :conf.exctl.painters.buf nil)
+(local buf-painter (require :conf.exctl.painters.buf))
+(tset package.loaded :conf.exctl.painters nil)
+(local painter (require :conf.exctl.painters))
+
+(local root-frame (frame (vec.vec 0 0)
+ (vec.vec vim.o.columns 0)
+ (vec.vec 0 vim.o.lines)))
+
+(local output (buf-painter (fn [] [0])))
+(local padded-output (painter.pad output 5))
+(local b (painter.beside padded-output padded-output))
+
+(b:paint root-frame)
diff --git a/fnl/conf/exctl/painters.fnl b/fnl/conf/exctl/painters.fnl
new file mode 100644
index 0000000..95fe644
--- /dev/null
+++ b/fnl/conf/exctl/painters.fnl
@@ -0,0 +1,50 @@
+(local vec (require :conf.exctl.frames.vec))
+(local exctl-frame (require :conf.exctl.frames.frame))
+(local m {})
+
+;; Creates a new painter that wraps the paint and close methods of a painter
+(fn m.transform-painter [painter ori width height]
+ (painter:transform (fn [self frame]
+ (local coord (exctl-frame.frame->coord frame))
+ (local new-ori (coord ori))
+ (P :new-ori new-ori)
+ (local new-frame
+ (exctl-frame new-ori
+ (vec.sub (coord width) new-ori)
+ (vec.sub (coord height) new-ori)))
+ (P new-frame)
+ (painter.paint self new-frame))
+ painter.close))
+
+(fn m.pad [painter pad-size]
+ (painter:transform (fn [self frame]
+ (local pad-width (/ pad-size (exctl-frame.width frame)))
+ (local pad-height
+ (/ pad-size (exctl-frame.height frame)))
+ (P :width pad-width)
+ (P :height pad-height)
+ (local transformed
+ (m.transform-painter painter
+ (vec.vec pad-width
+ pad-height)
+ (vec.vec (- 1 pad-width)
+ pad-height)
+ (vec.vec pad-width
+ (- 1 pad-height))))
+ (transformed.paint self frame))))
+
+(fn m.beside [p1 p2]
+ {:paint (fn [self frame]
+ (local new-p1
+ (m.transform-painter p1 (vec.vec 0 0) (vec.vec 0.5 0)
+ (vec.vec 0 1)))
+ (local new-p2
+ (m.transform-painter p2 (vec.vec 0.5 0) (vec.vec 1 0)
+ (vec.vec 0.5 1)))
+ (new-p1:paint frame)
+ (new-p2:paint frame))
+ :close (fn []
+ (p1:close)
+ (p2:close))})
+
+m
diff --git a/fnl/conf/exctl/painters/buf.fnl b/fnl/conf/exctl/painters/buf.fnl
new file mode 100644
index 0000000..07694c6
--- /dev/null
+++ b/fnl/conf/exctl/painters/buf.fnl
@@ -0,0 +1,25 @@
+(local {: frame->open-win-options} (require :conf.exctl.frames.frame))
+(local buf {})
+
+;; Paint procedure takes a frame to create a neovim window and populate the winbar and buffer of the window
+;; frame is max height and width the painter can use
+;; { height = number, width = number }
+(fn buf.paint [self frame]
+ (local open (or self.window false))
+ (assert (not open)
+ "Expect window not open, because i need to implement the closed paint case first")
+ (vim.api.nvim_open_win 0 true (frame->open-win-options frame)))
+
+(fn buf.transform [self paint]
+ (buf.new {: self.fetch-buffers : paint}))
+
+;; Buffer painters paints the window that is used to manage buffers where jobs put their output
+;; (fn fetch-buffers [] ...) -> [buffers...]
+(fn buf.new [self painter]
+ (setmetatable painter self)
+ (set self.__index self)
+ painter)
+
+;; Fancy lua way to create a new instance of the buf painter obj
+(fn [fetch-buffers]
+ (buf:new {: fetch-buffers :frames []}))
diff --git a/fnl/conf/exctl/spec.fnl b/fnl/conf/exctl/spec.fnl
new file mode 100644
index 0000000..71e18d0
--- /dev/null
+++ b/fnl/conf/exctl/spec.fnl
@@ -0,0 +1,42 @@
+;; (local a (require :plenary.async))
+;;
+;; (local back2vim (a.wrap vim.schedule 1))
+;;
+;; (fn read_file [path]
+;; (local fd (a.uv.fs_open path :r 438))
+;; (back2vim)
+;; (vim.notify (vim.inspect fd)))
+;;
+;; (local f (.. (os.getenv :HOME) :/test))
+;;
+;; (a.run (fn []
+;; (read_file f)))
+(tset package.loaded :conf.exctl.frames.vec nil)
+(local vec (require :conf.exctl.frames.vec))
+(local test-vec (vec.vec 0 1))
+(test-vec:x-coord)
+(test-vec:y-coord)
+(vec.sub test-vec (vec.vec 1 0))
+(vec.add test-vec (vec.vec 1 0))
+(vec.scale 3 test-vec)
+
+(tset package.loaded :conf.exctl.frames.frame nil)
+(local frame (require :conf.exctl.frames.frame))
+(local root-frame (frame (vec.vec 0 0) (vec.vec vim.o.columns 0)
+ (vec.vec 0 vim.o.lines)))
+
+(root-frame:origin)
+(root-frame:height-edge)
+(root-frame:width-edge)
+(frame.frame->open-win-options root-frame)
+
+(tset package.loaded :conf.exctl.painters.buf nil)
+(local buf-painter (require :conf.exctl.painters.buf))
+(local test (buf-painter (fn [] [0])))
+
+;; {: height
+;; : width
+;; :relative :editor
+;; :anchor :NW
+;; :row (math.floor (* vim.o.lines 0.7))
+;; :col 0.2])))