2
6
Fork
You've already forked gruid
0
Cross-platform grid-based UI and game framework.
  • Go 100%
Find a file
2025年09月18日 09:03:57 +00:00
paths make other packages use the new iterators in tests 2025年07月19日 10:31:54 +00:00
rl simplify rand initialization in tests & instructions 2025年08月10日 07:55:23 +00:00
tiles migrating to codeberg 2023年08月23日 07:17:49 +00:00
ui pager: don't show line numbers in just-fits edge-case 2025年08月27日 18:14:32 +00:00
.gitignore new All and Points methods returning iterators 2025年07月19日 10:24:34 +00:00
CHANGELOG.md update CHANGELOG for release 2025年09月18日 09:03:57 +00:00
example_grid_test.go migrating to codeberg 2023年08月23日 07:17:49 +00:00
go.mod update golang.org/x/image and require go 1.23 2025年07月17日 14:52:15 +00:00
go.sum update golang.org/x/image and require go 1.23 2025年07月17日 14:52:15 +00:00
grid.go new All and Points methods returning iterators 2025年07月19日 10:24:34 +00:00
grid_test.go new All and Points methods returning iterators 2025年07月19日 10:24:34 +00:00
LICENSE move bubbletea license mension into the right file 2020年12月24日 14:44:07 +00:00
messages.go update comment 2021年01月22日 09:22:19 +00:00
messages_test.go add tests for frame decoder 2021年01月01日 15:01:36 +00:00
README.md reorder examples 2025年08月11日 10:33:56 +00:00
recording.go remove extra pointer indirection in Decode 2025年09月10日 08:51:15 +00:00
ui.go simplify handling of nil effects 2022年10月23日 15:28:14 +00:00
ui_test.go make FrameDecoder.Decode signature more Decoder-like, allowing control over allocations 2021年01月19日 10:00:14 +00:00

Gruid

pkg.go.dev godocs.io

The gruid module provides packages for easily building grid-based applications in Go. The library abstracts rendering and input for different platforms. There are drivers available for terminal apps (gruid-tcell), native graphical apps (gruid-sdl) and browser apps (gruid-js). The original application for the library was creating grid-based games, but it's also well-suited for any grid-based application.

The core gruid package uses a convenient and flexible architecture of updating a model in response to messages strongly inspired by the bubbletea module for building terminal apps, which in turn is based on the functional Elm Architecture. The architecture has been adapted to be more idiomatic in Go in the context of grid-based applications: less functional and more efficient.

You can find examples below in the Examples section.

Overview of packages

The full documentation is linked at the top of this README. We provide here a quick overview.

The gruid package defines the Model and Driver interfaces and allows to start the "update on message then draw" main loop of an application. It also defines a convenient and efficient slice grid structure to represent the logical contents of the screen and manipulate them.

The ui package defines common UI widgets and utilities: menu/table widget, pager, text input, label, styled text drawing facilities and replay functionality.

The tiles package contains helpers for drawing fonts on images, which can be used to manage character tiles using a Driver from either gruid-sdl or gruid-js.

The paths package provides efficient implementations of some common pathfinding algorithms that are often used in grid-based games, such as roguelikes. You will find implementations of the A* and JPS algorithms, as well as Dijkstra, breadth first, and connected components maps computations. See move.go in the movement example in gruid-examples for an annotated example using JPS and the mouse.

The rl package provides some additional utilities commonly needed in grid-based games such as roguelikes. The package provides an event priority queue, two complementary field of view algorithms, map generation algorithms, as well as vault parsing and manipulation utilities.

Drivers

The tcell, sdl, and js packages in the (gruid-tcell), (gruid-sdl) and (gruid-js) modules provide specific rendering and input implementations satisfying gruid's package Driver interface. The provided terminal driver only handles full-window applications. See the README.md files in the respective repositories for specific build and deployment instructions (gruid-sdl will require SDL2, and gruid-js will require a bit of HTML and js).

Examples

The gruid-examples module offers some simple annotated examples of gruid usage.

You may want to look also into some real world examples of gruid programs:

See also

If you need to handle wide-characters, that is characters that take two cells in the terminal, you may want to look into go-runewidth.

The clipboard module may be of interest for some applications too, as copying and pasting is not handled by gruid. Note that, at this time, the clipboard module does not support the js platform, but there's at least one fork that does.

As gruid only provides a few map generation algorithms, you may be interested in the dngn module, which provides map generation algorithms too, though its representation of maps is different.