summaryrefslogtreecommitdiff
path: root/lua/sample.lua
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-05-19 02:39:53 +0200
committerAylur <[email protected]>2024-05-19 02:39:53 +0200
commit1425b396b08f0e91d45bbd0f92b1309115c7c870 (patch)
tree8af1a899a14d8a01a9ef50e248c077b48aed25bc /lua/sample.lua
init 0.1.0
Diffstat (limited to 'lua/sample.lua')
-rwxr-xr-xlua/sample.lua81
1 files changed, 81 insertions, 0 deletions
diff --git a/lua/sample.lua b/lua/sample.lua
new file mode 100755
index 0000000..2c76af6
--- /dev/null
+++ b/lua/sample.lua
@@ -0,0 +1,81 @@
+#!/usr/bin/env lua
+-- imports
+local astal = require("astal.init")
+local Widget, Variable, App, bind = astal.Widget, astal.Variable, astal.App, astal.bind
+
+-- state
+local player = astal.require("Playerctl").Player.new("spotify")
+
+local title = Variable(player:get_title()):observe(player, "metadata", function()
+ return player:get_title()
+end)
+
+local rnd = Variable(1):poll(1000, function()
+ return math.random(1, 10)
+end)
+
+-- ui
+local Bar = function(monitor)
+ return Widget.Window({
+ application = App,
+ id = "bar",
+ name = "bar",
+ monitor = monitor,
+ anchor = astal.Astal.WindowAnchor.BOTTOM
+ + astal.Astal.WindowAnchor.LEFT
+ + astal.Astal.WindowAnchor.RIGHT,
+ exclusivity = "EXCLUSIVE",
+
+ Widget.CenterBox({
+ class_name = "bar",
+ start_widget = Widget.Label({
+ valign = "CENTER",
+ label = "Welcome to Astal.lua",
+ }),
+ center_widget = Widget.Box({
+ children = bind(rnd):as(function(n)
+ local children = {}
+ for i = 1, n, 1 do
+ table.insert(
+ children,
+ Widget.Button({
+ label = tostring(i),
+ on_clicked = function()
+ print(i)
+ end,
+ })
+ )
+ end
+ return children
+ end),
+ }),
+ end_widget = Widget.Label({
+ valign = "CENTER",
+ label = bind(title),
+ }),
+ }),
+ })
+end
+
+-- css
+local css = [[
+.bar button {
+ color: blue;
+}
+]]
+
+-- main
+App:start({
+ request_handler = function(msg, res)
+ if msg == "quit" then
+ os.exit(0)
+ end
+ if msg == "inspector" then
+ res(App:inspector())
+ end
+ res("hi")
+ end,
+ css = css,
+}, function()
+ Bar(0)
+end)