js

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2026 License: ISC Imports: 9 Imported by: 0

README

gruid-js

pkg.go.dev godocs.io

The gruid-js module provides a gruid Driver for making wasm gruid applications that run in the browser. The module's package is called js.

To build a browser application, you have to build it with the following variables:

GOOS=js GOARCH=wasm go build -o app.wasm /path/to/your/application

Then, you have to serve using an http server a directory containing the app.wasm file along with an index.html file such as the basic example one in files/index.html (the html page containing the canvas of your application). You also need to copy the wasm_exec.js support file corresponding to your Go version, as explained in Go Wiki: WebAssembly.

Documentation

Rendered for js/wasm

Overview

Package js provides a Driver for making browser apps using wasm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TileManager TileManager // for retrieving tiles (required)
	Width       int         // initial screen width in cells (default: 80)
	Height      int         // initial screen height in cells (default: 24)
	AppCanvasId string      // application's canvas id (default: appcanvas)
}

Config contains configurations options for the driver.

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver implements gruid.Driver using the syscall/js interface for the browser using javascript and wasm.

func NewDriver

func NewDriver(cfg Config) *Driver

NewDriver returns a new driver with given configuration options.

func (*Driver) ClearCache

func (dr *Driver) ClearCache()

ClearCache clears the tiles internal cache.

func (*Driver) Close

func (dr *Driver) Close()

Close implements gruid.Driver.Close.

func (*Driver) Flush

func (dr *Driver) Flush(frame gruid.Frame)

Flush implements gruid.Driver.Flush.

func (*Driver) Init

func (dr *Driver) Init() error

Init implements gruid.Driver.Init.

func (*Driver) PollMsgs

func (dr *Driver) PollMsgs(ctx context.Context, msgs chan<- gruid.Msg) error

PollMsgs implements gruid.Driver.PollMsgs. To avoid conflicts with browser or OS shortcuts, keydown events with modifier keys other than shift are not reported.

func (*Driver) SetTileManager

func (dr *Driver) SetTileManager(tm TileManager)

SetTileManager allows to change the used tile manager.

type TileManager

type TileManager interface {
	// GetImage returns the image to be used for a given cell style.
	GetImage(gruid.Cell) image.Image

	// TileSize returns the (width, height) in pixels of the tiles. Both
	// should be positive and non-zero.
	TileSize() gruid.Point
}

TileManager manages tiles fetching.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL