Skip to content

Instantly share code, notes, and snippets.

(import freja/new_gap_buffer :as gb)
(import freja/state)
# will contain the parsers for each line
(def cache @[])
(def gap-buffer (get-in state/editor-state [:left-state :editor :gb]))
(var buf "")
@saikyun
saikyun / eoau
Created September 13, 2021 10:00
(use freja-jaylib)
(import freja/frp)
(import freja/state)
(comment
(do
(var cp 0)
(frp/subscribe! (get-in state/editor-state [:left-state :editor])
(fn [state]
(def chan (ev/thread-chan))
(defn run-process
[args]
(ev/spawn-thread
(def p (os/spawn args :p {:in :pipe :out :pipe}))
(ev/give chan (:read (p :out) :all))
(:wait p)))
(run-process ["ls"])
@saikyun
saikyun / why-freja.md
Last active September 13, 2021 08:33

FAQ for Freja

Why Freja?

Freja is a code, pixel and music editor. It is also a GUI library, which means you can create native graphical applications.

Compared to a browser, you get:

  • Easy interop with C
  • Easier access to the underlying system, including:
  • File system
@saikyun
saikyun / hiccup-compilation-example.clj
Last active July 7, 2021 11:18
example of compilation steps of hiccup (it's in janet but using .clj for highlighting)
# step 1: define hiccup
(def hiccup [:block {} [:text {:size 20} "Hello sogaiu"]])
#=> (:block {} (:text {:size 20} "Hello sogaiu"))
# step 2: compile hiccup into an element (a table)
(def element (with-dyns [# tags map e.g. :text to relevant rendering function
:tags tags
# default font
:text/font "Poppins"]
(ch/compile hiccup)))

Today I've worked on the layouting of Freja.

Specifically, using tuples and structs, you can now create fabulous designs.

I'm getting ahead of myself though. I should start with the problem, the reason why I started making this very nice system that I will soon tell you about.

Freja has a menu, like any old program. This is how it looks.

The problem, originally, is that when my dear friend sogaiu wanted to add some menu items, the code looked like this:

@saikyun
saikyun / janet_stepping_poc.janet
Created April 24, 2021 08:24
poc for step debugging janet
(defmacro line-number
[]
(def [l c] (tuple/sourcemap (dyn :macro-form ())))
l)
(defn add []
(def a 10)
(+ a a))
#=> turns into
(def click-queue (ev/chan 4))
(defn ev/check
[chan]
(when (pos? (ev/count chan))
(ev/take chan)))
(defn ev/push
[chan v]
(when (ev/full chan)
@saikyun
saikyun / list_of_ways_to_deal_with_gui.md
Last active April 19, 2021 17:23
Different ways to handle interaction and rendering

Different ways to handle interaction and rendering

A list of different ways to deal with interactions (mouse clicks, keyboard input, network events) and rendering of graphics (gui elements, games).

All example code is written in janet.

FRP (old elm style)

Description

Inspired by how elm used to do FRP (https://youtu.be/Ju4ICobPNfw)

(defmacro timeit2
```
Time the execution of `form` using `os/clock` before and after,
and print the result to stdout. returns: result of executing `form`.
Uses `tag` (default "Elapsed time:") to tag the printout.
```
[form &opt tag]
(default tag "Elapsed time:")
(with-syms [start result end]
~(do