clingon

package module
Version: v0.0.0-...-30df196 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2012 License: MIT Imports: 7 Imported by: 0

README

What's that?

Clingon (Command Line INterface for GO Nuts) is a Go library that helps in creating command-line interfaces à la Quake. Can't wait to see how does it look? Watch this video (early version) and see if it is worth reading below.

Clingon exploits a parallel and (hopefully) clean design. Basically, there are four parts running in parallel:

  • The console: it runs (almost) in the same goroutine of the client-code and it exposes console functionalities to it. The client modifies the console state through a simple API. When a new console instance is created, a goroutine is spawned. This goroutine simply triggers the "blink cursor" event to the renderer at regular time's interval.

  • The renderer: it responds to the events triggered by the console in order to render a graphical representation of the console state. A renderer object should implement the Renderer interface.

  • The animation service: it provides a stream of changing values used for animations. For example, this service provides the changing Y coordinate as a function of time in order to achieve the console sliding effect.

  • The evaluator: it evaluates the commands sent to the console providing back a result. It implements the Evaluator interface.

Because of its design, clingon could be a neat choice for adding console functionalities to games and graphical applications. For example, it is used in gospeccy to provide a non-blocking CLI which runs in parallel with the emulator.

Moreover, the fact that console operations are isolated from the rendering backend allows for non-blocking graphical effects.

Clingon tries to emulate a part of readline functionalities for line editing. At the moment, only a very small subset of the whole readline commands are available. However, clingon will never offer a complete readline emulation as it's simply not needed in games. See the Features section for more details.

Clingon is completely renderer-agnostic. Currently, only an SDL renderer is being shipped with the package but it should not be difficult to add more backends (e.g. opengl, draw/x11, etc.)

Features

  • Concurrent design
  • Graphical backend agnostic (currently an SDL renderer is included)
  • Console scrolling
  • Readline-like commands
    • left/right cursor movements
    • up/down history browsing

Installation

go get -v github.com/remogatto/clingon

After installing the package try the sample code in example/ folder:

cd $GOPATH/github.com/remogatto/clingon/example
make run

TODO

  • Improve readline emulation by adding more commands
  • Add new rendering backends
  • Add more graphical effects
  • Experimenting with clingon + exp/eval + draw2d

Video

Credits

Thanks to the following people for the contribute they give to this project:

License

Copyright (c) 2010 Andrea Fazzi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	CARRIAGE_RETURN = 0x000d
	BACKSPACE       = 0x0008
	DELETE          = 0x007f

	CURSOR_BLINK_TIME = 5e8

	HISTORY_NEXT = iota
	HISTORY_PREV
	CURSOR_LEFT
	CURSOR_RIGHT
)
View Source
const (
	SCROLL_UP = iota
	SCROLL_DOWN
	SCROLL_UP_ANIMATION
	SCROLL_DOWN_ANIMATION
)
View Source
const DEFAULT_ANIMATION_FPS = 30
View Source
const (
	MAX_INTERNAL_SIZE_FACTOR = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

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

func NewAnimation

func NewAnimation(f func(t float64) float64, length float64) *Animation

Creates a new animation. The values of 't' and 'length' are in seconds. Call 'Animation.Start' to start the animation.

func NewSliderAnimation

func NewSliderAnimation(length float64, distance float64) *Animation

Convenience function that creates a new animation going from 0.0 to 'distance'. The length is specified in seconds.

func (*Animation) FinishedCh

func (animation *Animation) FinishedCh() <-chan bool

This channel will receive a single value [when the animation ends] or [after the animation has been terminated] This channel is never closed.

func (*Animation) Start

func (animation *Animation) Start()

Starts the animation. This method can be called at most once per an Animation object.

func (*Animation) Terminate

func (animation *Animation) Terminate()

Tells the animation that it should terminate. This method returns immediately. It is safe to call this method even if the animation has ended on its own.

func (*Animation) ValueCh

func (animation *Animation) ValueCh() <-chan float64

The channel through which the animation delivers its consequetive values. This channel is never closed.

type Cmd_Scroll

type Cmd_Scroll struct {
	// SCROLL_UP or SCROLL_DOWN
	Direction int
}

Tell the renderer to scroll the console text up/down

type Cmd_StopScroll

type Cmd_StopScroll struct{}

Tell the renderer to stop scrolling the console text. It is safe to send this event even if no scrolling is running.

type Cmd_Terminate

type Cmd_Terminate struct {
	Done chan bool
}

type Cmd_UpdateCommandLine

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

type Cmd_UpdateConsole

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

type Cmd_UpdateCursor

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

type Console

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

func NewConsole

func NewConsole(evaluator_orNil Evaluator) *Console

Initialize a new console object passing to it an evaluator

func (*Console) ClearCommandline

func (console *Console) ClearCommandline()

Clear the commandline.

func (*Console) Commandline

func (console *Console) Commandline() string

Get the current command line as string.

func (*Console) Print

func (console *Console) Print(str string)

Print a string on the console and go to the next line. This function can handle strings containing '\n'.

func (*Console) PrintLines

func (console *Console) PrintLines(strings []string)

Print a slice of strings on the console. The strings should not contain '\n'.

func (*Console) PutCommand

func (console *Console) PutCommand(command string)

Put a command and execute it

func (*Console) PutReadline

func (console *Console) PutReadline(command int)

Put a readline-like command on the commandline (e.g. history browsing, cursor movements, etc.). Readline's commands emulation is incomplete.

func (*Console) PutString

func (console *Console) PutString(str string)

Put the given string on the command line at the current cursor position.

func (*Console) PutUnicode

func (console *Console) PutUnicode(value uint16)

Put an unicode value on the command-line at the current cursor position.

func (*Console) RendererOrNil

func (console *Console) RendererOrNil() Renderer

Return the current renderer.

func (*Console) SetPrompt

func (console *Console) SetPrompt(prompt string)

Set the prompt string

func (*Console) SetRenderer

func (console *Console) SetRenderer(renderer_orNil Renderer)

Replace the current renderer with a new one

func (*Console) String

func (console *Console) String() string

Dump the console content as a string.

type Evaluator

type Evaluator interface {
	Run(console *Console, command string) error
}

type Renderer

type Renderer interface {
	// Receive Cmd_* objects from the console
	EventCh() chan<- interface{}
}

type SDLRenderer

type SDLRenderer struct {
	// Activate/deactivate blended text rendering. By default use
	// solid text rendering
	Blended bool
	// Set the foreground color of the font (white by default)
	Color sdl.Color
	// Set the font family
	Font *ttf.Font
	// contains filtered or unexported fields
}

func NewSDLRenderer

func NewSDLRenderer(surface *sdl.Surface, font *ttf.Font) *SDLRenderer

func (*SDLRenderer) EventCh

func (renderer *SDLRenderer) EventCh() chan<- interface{}

Receive the events triggered by the console.

func (*SDLRenderer) GetSurface

func (renderer *SDLRenderer) GetSurface() *sdl.Surface

Return the visible SDL surface

func (*SDLRenderer) UpdatedRectsCh

func (renderer *SDLRenderer) UpdatedRectsCh() <-chan []sdl.Rect

From this channel, the client receives the rects representing the updated surface regions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL