Shoes: small windows, little code
Shoes is why the lucky stiff's GUI toolkit – the same pen that gave us “Chunky Bacon”. The idea: a window with some text and a button should cost a few lines, not a few hundred.
Scarpe is today's revival, and it is cut in two:
- Lacci (the
laccigem) knows only the language:stack,para,button. It knows nothing about pixels. - A display service then actually paints that tree – with Webview, with libui, or with something else entirely.
That is exactly why Shoes runs here: this page brings its own display service, which draws the tree into the page's HTML. The gem underneath is the real one, unchanged.
install_gem "lacci"
require "shoes"
show_shoes do
para "Hello from a Shoes app!"
endThe box above is a running Shoes app. Here show_shoes plays the part of Shoes.app.
Layout uses two containers – Shoes needs no more than that:
stackpiles its contents on top of each other,flowlines them up side by side.
Everything else is a drawable: title, para, button, edit_line and so on.
show_shoes do
stack do
title "Chunky's Diner"
para "Bacon, egg and coffee."
flow do
button "Bacon"
button "Egg"
button "Coffee"
end
end
endThose buttons do nothing yet. In Shoes you hang a block on a button, and any drawable you keep in a variable can be changed later – a para with replace, for instance:
show_shoes do
stack do
@strips = 0
@display = para "No bacon yet."
button "Order bacon" do
@strips += 1
@display.replace("#{@strips} strips of bacon! 🥓")
end
end
endPress the button – the text above it changes. And this is where the split gets interesting: your block runs in Lacci, which only announces “this property changed”. The display service listens and touches the matching DOM node. In Scarpe on the desktop, Webview or libui listens instead – same code, different window.
Input works the same way, just backwards: edit_line reports every change back to Lacci.
show_shoes do
stack do
@greeting = para "What's your name?"
edit_line "" do |text|
@greeting.replace(text.empty? ? "What's your name?" : "Hello, #{text}!")
end
end
endOn your own machine you install scarpe instead of lacci, write Shoes.app do … end in a file and start it with scarpe my_app.rb – and a real window opens. The app itself stays the same, line for line.
The display service drawing here is not a special case of this site either, but an ordinary one: about 250 lines of Ruby in shoes_dom.rb. Clogs, a Shoes on libui, is built to the same pattern.
title, an edit_line, a button and one more para that greets the name from the field when clicked. Keep the field in a variable – @field.text gives you what is in it.show_shoes do
stack do
# title "..."
# @field = edit_line ""
# @greeting = para "..."
# button "Greet me" do
# ...
# end
end
end