The Hog GUI

The web-based GUI for Hog is a Lustre app written in Gleam. The hog.zip you downloaded for the project came with only the compiled result, gui-files/gui.js. This example provides the Gleam source code.

Setup

You'll need your hog folder from the Hog project, along with Gleam and Node.js (installed during the first Gleam lab).

Download. Click the gui-src.zip link at the top of this page, then unzip it: on Mac or Linux, double-click the downloaded file; on Windows, right-click it and choose Extract All.... (Safari on a Mac may unzip it for you.) You'll get a folder named gui-src.

Move it into your hog folder. Move the gui-src folder into your hog folder, so that it sits next to hog.py, hog_gui.py, and gui-files:

hog/
โ”œโ”€โ”€ hog.py
โ”œโ”€โ”€ hog_gui.py
โ”œโ”€โ”€ gui-files/
โ””โ”€โ”€ gui-src/           โ† the folder you just moved
    โ”œโ”€โ”€ gleam.toml
    โ”œโ”€โ”€ src/
    โ””โ”€โ”€ dev/

Build the GUI. Open your hog folder in VS Code. From the Terminal menu, select New Terminal, and type:

cd gui-src
gleam dev

This compiles the Gleam source and bundles it into one file, gui-files/gui.js, replacing the GUI that came with the project. The first time, Gleam downloads the packages that the GUI depends on, and npx downloads esbuild, the tool that does the bundling, so you'll need an internet connection.

Run it. Go back to your hog folder and start the GUI the same way as in the project:

cd ..
python3 hog_gui.py

It serves the GUI you just built and runs the game using your hog.py.

After you change the source in gui-src/src, run gleam dev again from gui-src and refresh the page. You don't need to restart python3 hog_gui.py for a change to the GUI, only for a change to hog.py or hog_gui.py.

To go back to the original GUI, replace your gui-src folder with a fresh copy from gui-src.zip and run gleam dev again. (The unchanged source builds the same gui.js that came in hog.zip.)

What can go wrong?

  • If gleam dev says to put the gui-src folder inside your hog folder, check that gui-src sits next to hog_gui.py (not inside gui-files or inside another gui-src folder) and that you ran cd gui-src first.
  • If your code doesn't compile, gleam dev prints the error and leaves gui-files/gui.js as it was.
  • If the terminal says that gleam, node, or npx is not found, repeat the Lab 8 setup, then quit and reopen VS Code.

Back to Top

Accessibility Nondiscrimination

Copyright ยฉ2026, Regents of the University of California and respective authors.

This site is built following the Berkeley Class Site template, which is generously based on the Just the Class, and Just the Docs templates.

View all course offerings