tcell_ebiten

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 8 Imported by: 0

README

tcell Screen wrapper for ebiten

Easily add text components to your Ebiten game, leveraging the tcell library and its add-ons.

This library provides a ebiten/v2.Game interface that can be used as the entirety of the game loop for ebiten, or a sub-panel.

Usage

Convert tcell Application to ebiten Application

In your tcell program, add the following imports:

import (
    "github.com/ezrec/tcell_ebiten"
    "github.com/hajimehoshi/ebiten/v2"
)

|  // Define a nominal window size.
|  const window_width = 640
|  const window_height = 480

func main() {
    app := &views.Application{}
    window = ... // your existing tcell program here..
    app.SetRootWidget(window)

|  // Define our ebiten window size, and enable resizes.
|  ebiten.SetWindowSize(window_width, window_height)
|  ebiten.SetWindowTitle("hbox demo")
|  ebiten.SetWindowResizeable(true)
|
|  // Select an ebiten/v2/text/v2 font to use.
|  bm_face := text.NewGoXFace(bitmapfont.Face)
|  font_face, _ := font.NewMonoFont(bm_face)
|
|  // Create a proxy between the ebiten and tcell engines.
|  et := &etcell.ETCell{}
|  et.SetFont(font)
|
|  err := et.Run(func (screen tcell.Screen) error {
|      app.SetScreen(screen)
       err := app.Run()
       return err;
|  })
   if err != nil {
       panic(err)
   }
}

Documentation

Overview

Package etcell provides an github.com/hajimehoshi/ebiten/v2 to github.com/gdamore/tcell/v2 translation layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ETCell added in v1.0.0

type ETCell struct {
	ETCellScreen
}

ETCell is the ebiten to tcell manager. An empty ETCell is valid, and ready to use. An ETCell should not be copied.

func (*ETCell) Exit added in v1.0.0

func (et *ETCell) Exit(err error)

Exit the tcell application.

func (*ETCell) GetGameSize added in v1.0.0

func (et *ETCell) GetGameSize() (width, height int)

GetGameSize() returns the size of the image to draw (without GeoM scaling)

func (*ETCell) NewGame added in v1.0.0

func (et *ETCell) NewGame() *ETCellGame

Game returns the a new ebiten.Game interface for this ETCell wrapper.

func (*ETCell) Run added in v1.0.0

func (et *ETCell) Run(runner func(screen tcell.Screen) error) error

Run a tcell application

func (*ETCell) Screen added in v1.0.0

func (et *ETCell) Screen() *ETCellScreen

Screen returns the singleton tcell.Screen interface for this ETCell wrapper.

func (*ETCell) SetFont added in v1.0.0

func (et *ETCell) SetFont(face font.Face) *ETCell

SetFont sets the font for the text cells.

func (*ETCell) SetScreenCursorColor added in v1.0.0

func (et *ETCell) SetScreenCursorColor(color tcell.Color) *ETCell

SetScreenCursorColor sets the color of the text 'hardware' cursor.

func (*ETCell) SetScreenSize added in v1.0.0

func (et *ETCell) SetScreenSize(cols int, rows int) *ETCell

SetScreenSize resizes the text grid layout.

type ETCellGame added in v1.0.0

type ETCellGame struct {
	*ETCell

	GeoM ebiten.GeoM // This should only be set initially, or modified in Draw(), Update(), or Layout() overrides.
	// contains filtered or unexported fields
}

func (*ETCellGame) Draw added in v1.0.0

func (et *ETCellGame) Draw(dst *ebiten.Image)

Draw handles drawing in the game context. Used to implement a custom override for ETCellGame.

func (*ETCellGame) Layout added in v1.0.0

func (et *ETCellGame) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

Layout returns the integer layout.

func (*ETCellGame) LayoutF added in v1.0.0

func (et *ETCellGame) LayoutF(outsideWidth, outsideHeight float64) (screenWidth, screenHeight float64)

LayoutF returns the floating point layout.

func (*ETCellGame) Update added in v1.0.0

func (et *ETCellGame) Update() (err error)

Update processes ebiten.Game events. If Screen.Suspend() has been called, does nothing.

type ETCellScreen added in v1.0.0

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

func (*ETCellScreen) Beep added in v1.0.0

func (et *ETCellScreen) Beep() (err error)

Beep attempts to sound an OS-dependent audible alert and returns an error when unsuccessful.

func (*ETCellScreen) CanDisplay added in v1.0.0

func (et *ETCellScreen) CanDisplay(r rune, checkFallbacks bool) (can bool)

CanDisplay returns true if the given rune can be displayed on this screen. Note that this is a best-guess effort -- whether your fonts support the character or not may be questionable. Mostly this is for folks who work outside of Unicode.

If checkFallbacks is true, then if any (possibly imperfect) fallbacks are registered, this will return true. This will also return true if the terminal can replace the glyph with one that is visually indistinguishable from the one requested.

func (*ETCellScreen) ChannelEvents added in v1.0.0

func (et *ETCellScreen) ChannelEvents(ch chan<- tcell.Event, quit <-chan struct{})

ChannelEvents is an infinite loop that waits for an event and channels it into the user provided channel ch. Closing the quit channel and calling the Fini method are cancellation signals. When a cancellation signal is received the method returns after closing ch.

This method should be used as a goroutine.

NOTE: PollEvent should not be called while this method is running.

func (*ETCellScreen) CharacterSet added in v1.0.0

func (et *ETCellScreen) CharacterSet() (charset string)

CharacterSet returns information about the character set. This isn't the full locale, but it does give us the input/output character set. Note that this is just for diagnostic purposes, we normally translate input/output to/from UTF-8, regardless of what the user's environment is.

func (*ETCellScreen) Clear added in v1.0.0

func (et *ETCellScreen) Clear()

Clear logically erases the screen. This is effectively a short-cut for Fill(' ', StyleDefault).

func (*ETCellScreen) Colors added in v1.0.0

func (et *ETCellScreen) Colors() (ncolors int)

Colors returns the number of colors. All colors are assumed to use the ANSI color map. If a terminal is monochrome, it will return 0.

func (*ETCellScreen) DisableFocus added in v1.0.0

func (et *ETCellScreen) DisableFocus()

DisableFocus disables reporting of focus events.

func (*ETCellScreen) DisableMouse added in v1.0.0

func (et *ETCellScreen) DisableMouse()

DisableMouse disables the mouse.

func (*ETCellScreen) DisablePaste added in v1.0.0

func (et *ETCellScreen) DisablePaste()

DisablePaste disables bracketed paste mode.

func (*ETCellScreen) EnableFocus added in v1.0.0

func (et *ETCellScreen) EnableFocus()

EnableFocus enables reporting of focus events, if your terminal supports it.

func (*ETCellScreen) EnableMouse added in v1.0.0

func (et *ETCellScreen) EnableMouse(flags ...tcell.MouseFlags)

EnableMouse enables the mouse. (If your terminal supports it.) If no flags are specified, then all events are reported, if the terminal supports them.

func (*ETCellScreen) EnablePaste added in v1.0.0

func (et *ETCellScreen) EnablePaste()

EnablePaste enables bracketed paste mode, if supported.

func (*ETCellScreen) Fill added in v1.0.0

func (et *ETCellScreen) Fill(r rune, style tcell.Style)

Fill fills the screen with the given character and style. The effect of filling the screen is not visible until Show is called (or Sync).

func (*ETCellScreen) Fini added in v1.0.0

func (et *ETCellScreen) Fini()

Fini finalizes the screen also releasing resources.

func (*ETCellScreen) GetContent added in v1.0.0

func (et *ETCellScreen) GetContent(x, y int) (primary rune, combining []rune, style tcell.Style, width int)

GetContent returns the contents at the given location. If the coordinates are out of range, then the values will be 0, nil, StyleDefault. Note that the contents returned are logical contents and may not actually be what is displayed, but rather are what will be displayed if Show() or Sync() is called. The width is the width in screen cells; most often this will be 1, but some East Asian characters and emoji require two cells.

func (*ETCellScreen) HasKey added in v1.0.0

func (et *ETCellScreen) HasKey(key tcell.Key) (has bool)

HasKey returns true if the keyboard is believed to have the key. In some cases a keyboard may have keys with this name but no support for them, while in others a key may be reported as supported but not actually be usable (such as some emulators that hijack certain keys). Its best not to depend to strictly on this function, but it can be used for hinting when building menus, displayed hot-keys, etc. Note that KeyRune (literal runes) is always true.

func (*ETCellScreen) HasMouse added in v1.0.0

func (et *ETCellScreen) HasMouse() (has bool)

HasMouse returns true if the terminal (apparently) supports a mouse. Note that the return value of true doesn't guarantee that a mouse/pointing device is present; a false return definitely indicates no mouse support is available.

func (*ETCellScreen) HasPendingEvent added in v1.0.0

func (et *ETCellScreen) HasPendingEvent() (has bool)

HasPendingEvent returns true if PollEvent would return an event without blocking. If the screen is stopped and PollEvent would return nil, then the return value from this function is unspecified. The purpose of this function is to allow multiple events to be collected at once, to minimize screen redraws.

func (*ETCellScreen) HideCursor added in v1.0.0

func (et *ETCellScreen) HideCursor()

HideCursor is used to hide the cursor. It's an alias for ShowCursor(-1, -1).sim

func (*ETCellScreen) Init added in v1.0.0

func (et *ETCellScreen) Init() (err error)

Init initializes the screen for use.

func (*ETCellScreen) LockRegion added in v1.0.0

func (et *ETCellScreen) LockRegion(x, y, width, height int, lock bool)

LockRegion sets or unsets a lock on a region of cells. A lock on a cell prevents the cell from being redrawn.

func (*ETCellScreen) PollEvent added in v1.0.0

func (et *ETCellScreen) PollEvent() (ev tcell.Event)

PollEvent waits for events to arrive. Main application loops must spin on this to prevent the application from stalling. Furthermore, this will return nil if the Screen is finalized.

func (*ETCellScreen) PostEvent added in v1.0.0

func (et *ETCellScreen) PostEvent(ev tcell.Event) (err error)

PostEvent tries to post an event into the event stream. This can fail if the event queue is full. In that case, the event is dropped, and ErrEventQFull is returned.

func (*ETCellScreen) PostEventWait deprecated added in v1.0.0

func (et *ETCellScreen) PostEventWait(ev tcell.Event)

Deprecated: PostEventWait is unsafe, and will be removed in the future.

PostEventWait is like PostEvent, but if the queue is full, it blocks until there is space in the queue, making delivery reliable. However, it is VERY important that this function never be called from within whatever event loop is polling with PollEvent(), otherwise a deadlock may arise.

For this reason, when using this function, the use of a Goroutine is recommended to ensure no deadlock can occur.

func (*ETCellScreen) RegisterRuneFallback added in v1.0.0

func (et *ETCellScreen) RegisterRuneFallback(r rune, subst string)

RegisterRuneFallback adds a fallback for runes that are not part of the character set -- for example one could register o as a fallback for ø. This should be done cautiously for characters that might be displayed ordinarily in language specific text -- characters that could change the meaning of written text would be dangerous. The intention here is to facilitate fallback characters in pseudo-graphical applications.

If the terminal has fallbacks already in place via an alternate character set, those are used in preference. Also, standard fallbacks for graphical characters in the alternate character set terminfo string are registered implicitly.

The display string should be the same width as original rune. This makes it possible to register two character replacements for full width East Asian characters, for example.

It is recommended that replacement strings consist only of 7-bit ASCII, since other characters may not display everywhere.

func (*ETCellScreen) Resize added in v1.0.0

func (et *ETCellScreen) Resize(int, int, int, int)

Resize does nothing, since it's generally not possible to ask a screen to resize, but it allows the Screen to implement the View interface.

func (*ETCellScreen) Resume added in v1.0.0

func (et *ETCellScreen) Resume() (err error)

Resume resumes after Suspend().

func (*ETCellScreen) SetCell added in v1.0.0

func (et *ETCellScreen) SetCell(x int, y int, style tcell.Style, ch ...rune)

SetCell is an older API, and will be removed. Please use SetContent instead; SetCell is implemented in terms of SetContent.

func (*ETCellScreen) SetContent added in v1.0.0

func (et *ETCellScreen) SetContent(x int, y int, primary rune, combining []rune, style tcell.Style)

SetContent sets the contents of the given cell location. If the coordinates are out of range, then the operation is ignored.

The first rune is the primary non-zero width rune. The array that follows is a possible list of combining characters to append, and will usually be nil (no combining characters.)

The results are not displayed until Show() or Sync() is called.

Note that wide (East Asian full width and emoji) runes occupy two cells, and attempts to place character at next cell to the right will have undefined effects. Wide runes that are printed in the last column will be replaced with a single width space on output.

func (*ETCellScreen) SetCursorStyle added in v1.0.0

func (et *ETCellScreen) SetCursorStyle(cs tcell.CursorStyle)

SetCursorStyle is used to set the cursor style. If the style is not supported (or cursor styles are not supported at all), then this will have no effect.

func (*ETCellScreen) SetSize added in v1.0.0

func (et *ETCellScreen) SetSize(int, int)

SetSize attempts to resize the window. It also invalidates the cells and calls the resize function. Note that if the window size is changed, it will not be restored upon application exit.

Many terminals cannot support this. Perversely, the "modern" Windows Terminal does not support application-initiated resizing, whereas the legacy terminal does. Also, some emulators can support this but may have it disabled by default.

func (*ETCellScreen) SetStyle added in v1.0.0

func (et *ETCellScreen) SetStyle(style tcell.Style)

SetStyle sets the default style to use when clearing the screen or when StyleDefault is specified. If it is also StyleDefault, then whatever system/terminal default is relevant will be used.

func (*ETCellScreen) Show added in v1.0.0

func (et *ETCellScreen) Show()

Show makes all the content changes made using SetContent() visible on the display.

It does so in the most efficient and least visually disruptive manner possible.

func (*ETCellScreen) ShowCursor added in v1.0.0

func (et *ETCellScreen) ShowCursor(x int, y int)

ShowCursor is used to display the cursor at a given location. If the coordinates -1, -1 are given or are otherwise outside the dimensions of the screen, the cursor will be hidden.

func (*ETCellScreen) Size added in v1.0.0

func (et *ETCellScreen) Size() (width, height int)

Size returns the screen size as width, height. This changes in response to a call to Clear or Flush.

func (*ETCellScreen) Suspend added in v1.0.0

func (et *ETCellScreen) Suspend() (err error)

Suspend pauses input and output processing. It also restores the terminal settings to what they were when the application started. This can be used to, for example, run a sub-shell.

func (*ETCellScreen) Sync added in v1.0.0

func (et *ETCellScreen) Sync()

Sync works like Show(), but it updates every visible cell on the physical display, assuming that it is not synchronized with any internal model. This may be both expensive and visually jarring, so it should only be used when believed to actually be necessary.

Typically, this is called as a result of a user-requested redraw (e.g. to clear up on-screen corruption caused by some other program), or during a resize event.

func (*ETCellScreen) Tty added in v1.0.0

func (et *ETCellScreen) Tty() (tty tcell.Tty, is_tty bool)

Tty returns the underlying Tty. If the screen is not a terminal, the returned bool will be false

func (*ETCellScreen) UnregisterRuneFallback added in v1.0.0

func (et *ETCellScreen) UnregisterRuneFallback(r rune)

UnregisterRuneFallback unmaps a replacement. It will unmap the implicit ASCII replacements for alternate characters as well. When an unmapped char needs to be displayed, but no suitable glyph is available, '?' is emitted instead. It is not possible to "disable" the use of alternate characters that are supported by your terminal except by changing the terminal database.

Directories

Path Synopsis
examples
Package font supplies font face wrappers for monospaced fonts, for use with github.com/ezrec/ebiten_tcell.
Package font supplies font face wrappers for monospaced fonts, for use with github.com/ezrec/ebiten_tcell.

Jump to

Keyboard shortcuts

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