gocui

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2016 License: BSD-3-Clause Imports: 7 Imported by: 1

README

GOCUI - Go Console User Interface

GoDoc

Minimalist Go package aimed at creating Console User Interfaces.

About the fork

This fork is based on GOCUI v0.2.0. The library was modified to suit the need of Stretto editor.

Features

  • Minimalist API.
  • Views (the "windows" in the GUI) implement the interface io.ReadWriter.
  • Support for overlapping views.
  • The GUI can be modified at runtime (concurrent-safe).
  • Global and view-level keybindings.
  • Mouse support.
  • Customizable edition mode.

Installation

Execute:

$ go get github.com/jroimartin/gocui

Documentation

Execute:

$ godoc github.com/jroimartin/gocui

Or visit godoc.org to read it online.

Example

package main

import (
	"fmt"
	"log"

	"github.com/jroimartin/gocui"
)

func main() {
	g := gocui.NewGui()
	if err := g.Init(); err != nil {
		log.Panicln(err)
	}
	defer g.Close()

	g.SetLayout(layout)

	if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
		log.Panicln(err)
	}

	if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
		log.Panicln(err)
	}
}

func layout(g *gocui.Gui) error {
	maxX, maxY := g.Size()
	if v, err := g.SetView("hello", maxX/2-7, maxY/2, maxX/2+7, maxY/2+2); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
		fmt.Fprintln(v, "Hello world!")
	}
	return nil
}

func quit(g *gocui.Gui, v *gocui.View) error {
	return gocui.ErrQuit
}

Screenshots

_examples/demo.go:

_examples/demo.go

_examples/dynamic.go:

_examples/dynamic.go

Documentation

Overview

Package gocui allows to create console user interfaces.

Create a new GUI:

g := gocui.NewGui()
if err := g.Init(); err != nil {
	// handle error
}
defer g.Close()

// Set layout and key bindings
// ...

if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
	// handle error
}

Set the layout function:

g.SetLayout(fcn)

On each iteration of the GUI's main loop, the "layout function" is executed. These layout functions can be used to set-up and update the application's main views, being possible to freely switch between them. Also, it is important to mention that a main loop iteration is executed on each reported event (key-press, mouse event, window resize, etc).

GUIs are composed by Views, you can think of it as buffers. Views implement the io.ReadWriter interface, so you can just write to them if you want to modify their content. The same is valid for reading.

Create and initialize a view with absolute coordinates:

if v, err := g.SetView("viewname", 2, 2, 22, 7); err != nil {
	if err != gocui.ErrUnknownView {
		// handle error
	}
	fmt.Fprintln(v, "This is a new view")
	// ...
}

Views can also be created using relative coordinates:

maxX, maxY := g.Size()
if v, err := g.SetView("viewname", maxX/2-30, maxY/2, maxX/2+30, maxY/2+2); err != nil {
	// ...
}

Configure keybindings:

if err := g.SetKeybinding("viewname", gocui.KeyEnter, gocui.ModNone, fcn); err != nil {
	// handle error
}

gocui implements full mouse support that can be enabled with:

g.Mouse = true

Mouse events are handled like any other keybinding:

if err := g.SetKeybinding("viewname", gocui.MouseLeft, gocui.ModNone, fcn); err != nil {
	// handle error
}

IMPORTANT: Views can only be created, destroyed or updated in three ways: from layout funcions, from keybinding callbacks or via *Gui.Execute(). The reason for this is that it allows gocui to be conccurent-safe. So, if you want to update your GUI from a goroutine, you must use *Gui.Execute(). For example:

g.Execute(func(g *gocui.Gui) error {
	v, err := g.View("viewname")
	if err != nil {
		// handle error
	}
	v.Clear()
	fmt.Fprintln(v, "Writing from different goroutines")
	return nil
})

By default, gocui provides a basic edition mode. This mode can be extended and customized creating a new Editor and assigning it to *Gui.Editor:

type Editor interface {
	Edit(v *View, key Key, ch rune, mod Modifier)
}

DefaultEditor can be taken as example to create your own custom Editor:

var DefaultEditor Editor = EditorFunc(simpleEditor)

func simpleEditor(v *View, key Key, ch rune, mod Modifier) {
	switch {
	case ch != 0 && mod == 0:
		v.EditWrite(ch)
	case key == KeySpace:
		v.EditWrite(' ')
	case key == KeyBackspace || key == KeyBackspace2:
		v.EditDelete(true)
	// ...
	}
}

For more information, see the examples in folder "_examples/".

Index

Constants

View Source
const (
	ColorDefault Attribute = Attribute(termbox.ColorDefault)
	ColorBlack             = Attribute(termbox.ColorBlack)
	ColorRed               = Attribute(termbox.ColorRed)
	ColorGreen             = Attribute(termbox.ColorGreen)
	ColorYellow            = Attribute(termbox.ColorYellow)
	ColorBlue              = Attribute(termbox.ColorBlue)
	ColorMagenta           = Attribute(termbox.ColorMagenta)
	ColorCyan              = Attribute(termbox.ColorCyan)
	ColorWhite             = Attribute(termbox.ColorWhite)
)

Color attributes.

View Source
const (
	AttrBold      Attribute = Attribute(termbox.AttrBold)
	AttrUnderline           = Attribute(termbox.AttrUnderline)
	AttrReverse             = Attribute(termbox.AttrReverse)
)

Text style attributes.

View Source
const (
	KeyF1         Key = Key(termbox.KeyF1)
	KeyF2             = Key(termbox.KeyF2)
	KeyF3             = Key(termbox.KeyF3)
	KeyF4             = Key(termbox.KeyF4)
	KeyF5             = Key(termbox.KeyF5)
	KeyF6             = Key(termbox.KeyF6)
	KeyF7             = Key(termbox.KeyF7)
	KeyF8             = Key(termbox.KeyF8)
	KeyF9             = Key(termbox.KeyF9)
	KeyF10            = Key(termbox.KeyF10)
	KeyF11            = Key(termbox.KeyF11)
	KeyF12            = Key(termbox.KeyF12)
	KeyInsert         = Key(termbox.KeyInsert)
	KeyDelete         = Key(termbox.KeyDelete)
	KeyHome           = Key(termbox.KeyHome)
	KeyEnd            = Key(termbox.KeyEnd)
	KeyPgup           = Key(termbox.KeyPgup)
	KeyPgdn           = Key(termbox.KeyPgdn)
	KeyArrowUp        = Key(termbox.KeyArrowUp)
	KeyArrowDown      = Key(termbox.KeyArrowDown)
	KeyArrowLeft      = Key(termbox.KeyArrowLeft)
	KeyArrowRight     = Key(termbox.KeyArrowRight)

	MouseLeft   = Key(termbox.MouseLeft)
	MouseMiddle = Key(termbox.MouseMiddle)
	MouseRight  = Key(termbox.MouseRight)
)

Special keys.

View Source
const (
	KeyCtrlTilde      Key = Key(termbox.KeyCtrlTilde)
	KeyCtrl2              = Key(termbox.KeyCtrl2)
	KeyCtrlSpace          = Key(termbox.KeyCtrlSpace)
	KeyCtrlA              = Key(termbox.KeyCtrlA)
	KeyCtrlB              = Key(termbox.KeyCtrlB)
	KeyCtrlC              = Key(termbox.KeyCtrlC)
	KeyCtrlD              = Key(termbox.KeyCtrlD)
	KeyCtrlE              = Key(termbox.KeyCtrlE)
	KeyCtrlF              = Key(termbox.KeyCtrlF)
	KeyCtrlG              = Key(termbox.KeyCtrlG)
	KeyBackspace          = Key(termbox.KeyBackspace)
	KeyCtrlH              = Key(termbox.KeyCtrlH)
	KeyTab                = Key(termbox.KeyTab)
	KeyCtrlI              = Key(termbox.KeyCtrlI)
	KeyCtrlJ              = Key(termbox.KeyCtrlJ)
	KeyCtrlK              = Key(termbox.KeyCtrlK)
	KeyCtrlL              = Key(termbox.KeyCtrlL)
	KeyEnter              = Key(termbox.KeyEnter)
	KeyCtrlM              = Key(termbox.KeyCtrlM)
	KeyCtrlN              = Key(termbox.KeyCtrlN)
	KeyCtrlO              = Key(termbox.KeyCtrlO)
	KeyCtrlP              = Key(termbox.KeyCtrlP)
	KeyCtrlQ              = Key(termbox.KeyCtrlQ)
	KeyCtrlR              = Key(termbox.KeyCtrlR)
	KeyCtrlS              = Key(termbox.KeyCtrlS)
	KeyCtrlT              = Key(termbox.KeyCtrlT)
	KeyCtrlU              = Key(termbox.KeyCtrlU)
	KeyCtrlV              = Key(termbox.KeyCtrlV)
	KeyCtrlW              = Key(termbox.KeyCtrlW)
	KeyCtrlX              = Key(termbox.KeyCtrlX)
	KeyCtrlY              = Key(termbox.KeyCtrlY)
	KeyCtrlZ              = Key(termbox.KeyCtrlZ)
	KeyEsc                = Key(termbox.KeyEsc)
	KeyCtrlLsqBracket     = Key(termbox.KeyCtrlLsqBracket)
	KeyCtrl3              = Key(termbox.KeyCtrl3)
	KeyCtrl4              = Key(termbox.KeyCtrl4)
	KeyCtrlBackslash      = Key(termbox.KeyCtrlBackslash)
	KeyCtrl5              = Key(termbox.KeyCtrl5)
	KeyCtrlRsqBracket     = Key(termbox.KeyCtrlRsqBracket)
	KeyCtrl6              = Key(termbox.KeyCtrl6)
	KeyCtrl7              = Key(termbox.KeyCtrl7)
	KeyCtrlSlash          = Key(termbox.KeyCtrlSlash)
	KeyCtrlUnderscore     = Key(termbox.KeyCtrlUnderscore)
	KeySpace              = Key(termbox.KeySpace)
	KeyBackspace2         = Key(termbox.KeyBackspace2)
	KeyCtrl8              = Key(termbox.KeyCtrl8)
)

Keys combinations.

Variables

View Source
var (
	// ErrQuit is used to decide if the MainLoop finished successfully.
	ErrQuit = errors.New("quit")

	// ErrUnknownView allows to assert if a View must be initialized.
	ErrUnknownView = errors.New("unknown view")
	// ErrUnknownViewNode allows to assert if a View must be initialized.
	ErrUnknownViewNode = errors.New("unknown view node")

	// ErrUnknowMode checks map initialization
	ErrUnknowMode = errors.New("unknown mode")
)

Functions

This section is empty.

Types

type ActionsInterface added in v0.2.3

type ActionsInterface interface {
	Exec(c Command)
	Undo()
	Redo()
}

ActionsInterface should be implemented by our Context

type Attribute

type Attribute termbox.Attribute

Attribute represents a terminal attribute, like color, font style, etc. They can be combined using bitwise OR (|). Note that it is not possible to combine multiple color attributes.

type BackDelLineCmd added in v0.2.3

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

func NewBackDelLineCmd added in v0.2.3

func NewBackDelLineCmd(v *View, px, py int) *BackDelLineCmd

func (*BackDelLineCmd) Execute added in v0.2.3

func (c *BackDelLineCmd) Execute()

func (*BackDelLineCmd) Info added in v0.2.3

func (c *BackDelLineCmd) Info() string

func (*BackDelLineCmd) Reverse added in v0.2.3

func (c *BackDelLineCmd) Reverse()

type BackDeleteCmd added in v0.2.3

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

func NewBackDeleteCmd added in v0.2.3

func NewBackDeleteCmd(v *View, x, y int, fchar rune) *BackDeleteCmd

func (*BackDeleteCmd) Execute added in v0.2.3

func (c *BackDeleteCmd) Execute()

func (*BackDeleteCmd) Info added in v0.2.3

func (c *BackDeleteCmd) Info() string

func (*BackDeleteCmd) Reverse added in v0.2.3

func (c *BackDeleteCmd) Reverse()

type CmdStack added in v0.2.3

type CmdStack []Command

Is used as a stack of Command The required methods are implemented below

func (*CmdStack) Clear added in v0.2.3

func (s *CmdStack) Clear()

Empties the stack

func (*CmdStack) Pop added in v0.2.3

func (s *CmdStack) Pop() Command

Removes the last added command from the stack and returns it, if there is one Returns nil otherwise

func (*CmdStack) Push added in v0.2.3

func (s *CmdStack) Push(c Command)

Adds a command to the stack

type Command added in v0.2.3

type Command interface {
	Info() string
	Execute()
	Reverse()
}

Should be implemented by every command

type Container added in v0.2.3

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

Container is a geometry element to create Views hierarchy

func (*Container) HasNoChildren added in v0.2.3

func (c *Container) HasNoChildren() bool

HasNoChildren checks the length of childrens

func (*Container) LastView added in v0.2.3

func (c *Container) LastView() *View

func (*Container) Name added in v0.2.3

func (c *Container) Name() string

Name returns the name of the view.s

func (*Container) Position added in v0.2.3

func (c *Container) Position() (int, int, int, int)

Position returns coordinates

func (*Container) RoundRobinBackward added in v0.2.3

func (c *Container) RoundRobinBackward() *View

RoundRobinBackward takes the first element in c.childrens and put it at the end of the same slice

func (*Container) RoundRobinForward added in v0.2.3

func (c *Container) RoundRobinForward() *View

RoundRobinForward takes the last element in c.childrens and put it at the beginning of the same slice

func (*Container) Size added in v0.2.3

func (c *Container) Size() (x, y int)

Size returns the number of visible columns and rows in the container.

type Context added in v0.2.3

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

Implements ActionsInterface

func (*Context) Cut added in v0.2.3

func (con *Context) Cut()

Makes the last command unmergeable. Called when the user moves the cursor, for instance

func (*Context) Exec added in v0.2.3

func (con *Context) Exec(c Command)

Adds a command to the undo stack, merging it with the last command if possible. Clears the redo stack

func (*Context) Redo added in v0.2.3

func (con *Context) Redo()

Moves a command from the redo stack to the undo stack and executes it.

func (*Context) ToString added in v0.2.3

func (con *Context) ToString(w, h int) string

Returns a formatted string representation of the historic

func (*Context) Undo added in v0.2.3

func (con *Context) Undo()

Moves a command from the undo stack to the redo stack and reverses it.

type DownPermutCmd added in v0.2.3

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

func NewDownPermutCmd added in v0.2.3

func NewDownPermutCmd(v *View, x, y int, n int) *DownPermutCmd

func (*DownPermutCmd) Execute added in v0.2.3

func (c *DownPermutCmd) Execute()

func (*DownPermutCmd) Info added in v0.2.3

func (c *DownPermutCmd) Info() string

func (*DownPermutCmd) Reverse added in v0.2.3

func (c *DownPermutCmd) Reverse()

type Editor added in v0.2.0

type Editor interface {
	Edit(v *View, key Key, ch rune, mod Modifier)
}

Editor interface must be satisfied by gocui editors.

var DefaultEditor Editor = EditorFunc(simpleEditor)

DefaultEditor is the default editor.

type EditorFunc added in v0.2.0

type EditorFunc func(v *View, key Key, ch rune, mod Modifier)

The EditorFunc type is an adapter to allow the use of ordinary functions as Editors. If f is a function with the appropriate signature, EditorFunc(f) is an Editor object that calls f.

func (EditorFunc) Edit added in v0.2.0

func (f EditorFunc) Edit(v *View, key Key, ch rune, mod Modifier)

Edit calls f(v, key, ch, mod)

type FwdDelLineCmd added in v0.2.3

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

func NewFwdDelLineCmd added in v0.2.3

func NewFwdDelLineCmd(v *View, x, y int) *FwdDelLineCmd

func (*FwdDelLineCmd) Execute added in v0.2.3

func (c *FwdDelLineCmd) Execute()

func (*FwdDelLineCmd) Info added in v0.2.3

func (c *FwdDelLineCmd) Info() string

func (*FwdDelLineCmd) Reverse added in v0.2.3

func (c *FwdDelLineCmd) Reverse()

type FwdDeleteCmd added in v0.2.3

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

func NewFwdDeleteCmd added in v0.2.3

func NewFwdDeleteCmd(v *View, x, y int, fchar rune) *FwdDeleteCmd

func (*FwdDeleteCmd) Execute added in v0.2.3

func (c *FwdDeleteCmd) Execute()

func (*FwdDeleteCmd) Info added in v0.2.3

func (c *FwdDeleteCmd) Info() string

func (*FwdDeleteCmd) Reverse added in v0.2.3

func (c *FwdDeleteCmd) Reverse()

type Gui

type Gui struct {

	// BgColor and FgColor allow to configure the background and foreground
	// colors of the GUI.
	BgColor, FgColor Attribute

	// SelBgColor and SelFgColor are used to configure the background and
	// foreground colors of the selected line, when it is highlighted.
	SelBgColor, SelFgColor Attribute

	// If Cursor is true then the cursor is enabled.
	Cursor bool

	// If Mouse is true then mouse events will be enabled.
	Mouse bool

	// Editor allows to define the editor that manages the edition mode,
	// including keybindings or cursor behaviour. DefaultEditor is used by
	// default.
	Editor Editor
	// contains filtered or unexported fields
}

Gui represents the whole User Interface, including the views, layouts and keybindings.

func NewGui

func NewGui() *Gui

NewGui returns a new Gui object.

func (*Gui) AddMode added in v0.2.2

func (g *Gui) AddMode(name string, openFunc modeHandler, closeFunc modeHandler)

AddMode creates a new mode does nothing if there is already a mode for this name

func (*Gui) Close

func (g *Gui) Close()

Close finalizes the library. It should be called after a successful initialization and when gocui is not needed anymore.

func (*Gui) CurrentMode added in v0.2.1

func (g *Gui) CurrentMode() *Mode

CurrentMode returns the current mode

func (*Gui) CurrentView

func (g *Gui) CurrentView() *View

CurrentView returns the currently focused view, or nil if no view owns the focus.

func (*Gui) DeleteView

func (g *Gui) DeleteView(name string) error

DeleteView deletes a view by name.

func (*Gui) Execute added in v0.2.0

func (g *Gui) Execute(h Handler)

Execute executes the given handler. This function can be called safely from a goroutine in order to update the GUI. It is important to note that it won't be executed immediately, instead it will be added to the user events queue.

func (*Gui) Init

func (g *Gui) Init() error

Init initializes the library. This function must be called before any other functions.

func (*Gui) MainLoop

func (g *Gui) MainLoop() error

MainLoop runs the main loop until an error is returned. A successful finish should return ErrQuit.

func (*Gui) Mode added in v0.2.1

func (g *Gui) Mode(name string) (*Mode, error)

Mode returns a pointer to the Mode with the given name, or error ErrUnknownMode if a Mode with that name does not exist.

func (*Gui) Rune

func (g *Gui) Rune(x, y int) (rune, error)

Rune returns the rune contained in the cell at the given position. It checks if the position is valid.

func (*Gui) SetCurrentMode added in v0.2.1

func (g *Gui) SetCurrentMode(name string) error

SetCurrentMode switches to the Mode with the given name

func (*Gui) SetCurrentView

func (g *Gui) SetCurrentView(name string) error

SetCurrentView gives the focus to a given view.

func (*Gui) SetKeybinding

func (g *Gui) SetKeybinding(modeName string, viewName string, key interface{}, mod Modifier, h KeybindingHandler) error

SetKeybinding creates a new keybinding. If viewname equals to "" (empty string) then the keybinding will apply to all views. key must be a rune or a Key.

func (*Gui) SetLayout

func (g *Gui) SetLayout(layout Handler)

SetLayout sets the current layout. A layout is a function that will be called every time the gui is redrawn, it must contain the base views and its initializations.

func (*Gui) SetRune

func (g *Gui) SetRune(x, y int, ch rune) error

SetRune writes a rune at the given point, relative to the top-left corner of the terminal. It checks if the position is valid and applies the gui's colors.

func (*Gui) SetView

func (g *Gui) SetView(name string, father string, x0, y0, x1, y1 int) (*View, error)

SetView creates a new view with its top-left corner at (x0, y0) and the bottom-right one at (x1, y1). If a view with the same name already exists, its dimensions are updated; otherwise, the error ErrUnknownView is returned, which allows to assert if the View must be initialized. It checks if the position is valid.

func (*Gui) SetViewNode added in v0.2.3

func (g *Gui) SetViewNode(name string, father string, x0, y0, x1, y1 int) error

SetViewNode creates a new view with its top-left corner at (x0, y0) and the bottom-right one at (x1, y1). If a viewNode with the same name already exists, its dimensions are updated; otherwise, the error ErrUnknownViewNode is returned. It checks if the position is valid.

func (*Gui) SetViewOnTop added in v0.2.1

func (g *Gui) SetViewOnTop(name string) (*View, error)

SetViewOnTop sets the given view on top of the existing ones.

func (*Gui) SetWorkingView added in v0.2.3

func (g *Gui) SetWorkingView(name string) error

SetWorkingView gives the focus to a given view.

func (*Gui) Size

func (g *Gui) Size() (x, y int)

Size returns the terminal's size.

func (*Gui) UpdateHistoric added in v0.2.3

func (g *Gui) UpdateHistoric()

func (*Gui) View

func (g *Gui) View(name string) (*View, error)

View returns a pointer to the view with the given name, or error ErrUnknownView if a view with that name does not exist.

func (*Gui) ViewByPosition added in v0.2.0

func (g *Gui) ViewByPosition(x, y int) (*View, error)

ViewByPosition returns a pointer to a view matching the given position, or error ErrUnknownView if a view in that position does not exist.

func (*Gui) ViewNode added in v0.2.3

func (g *Gui) ViewNode(name string) (*Container, error)

ViewNode returns a pointer to the view with the given name, or error ErrUnknownView if a view with that name does not exist.

func (*Gui) ViewPosition added in v0.2.0

func (g *Gui) ViewPosition(name string) (x0, y0, x1, y1 int, err error)

ViewPosition returns the coordinates of the view with the given name, or error ErrUnknownView if a view with that name does not exist.

func (*Gui) Workingview added in v0.2.3

func (g *Gui) Workingview() *View

Workingview returns the currently working view, or nil if no view owns the focus.

type Handler added in v0.2.0

type Handler func(*Gui) error

Handler represents a handler that can be used to update or modify the GUI.

type Key

type Key termbox.Key

Key represents special keys or keys combinations.

type KeybindingHandler

type KeybindingHandler func(*Gui, *View) error

KeybindingHandler represents the handler linked to a specific keybindings. The handler is called when a key-press event satisfies a configured keybinding.

type Mergeable added in v0.2.3

type Mergeable interface {
	// contains filtered or unexported methods
}

It should be implemented by a command, if 2 successive commands of the same type have to merge

type Mode added in v0.2.1

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

Mode is the struct that associates to a mode name a set of keybindings and functions to execute when you switch to the mode or from the mode to another

func CreateMode added in v0.2.1

func CreateMode(name string, openMode modeHandler, closeMode modeHandler) *Mode

CreateMode create a mode with the given name, and opening and closing functions

func (*Mode) CloseMode added in v0.2.2

func (m *Mode) CloseMode(g *Gui)

CloseMode execute the file handler to execute at the closing time of the mode

func (*Mode) GetKeyBindings added in v0.2.1

func (m *Mode) GetKeyBindings() *kbSet

GetKeyBindings gives a pointer to the set of keybindings associate to the mode

func (*Mode) Name added in v0.2.1

func (m *Mode) Name() string

Name returns the name of the mode

func (*Mode) OpenMode added in v0.2.2

func (m *Mode) OpenMode(g *Gui)

OpenMode execute the file handler to execute at the opening of the mode

type Modifier

type Modifier termbox.Modifier

Modifier allows to define special keys combinations. They can be used in combination with Keys or Runes when a new keybinding is defined.

const (
	ModNone Modifier = Modifier(0)
	ModAlt           = Modifier(termbox.ModAlt)
)

Modifiers.

type NewLineCmd added in v0.2.3

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

func NewNewLineCmd added in v0.2.3

func NewNewLineCmd(v *View, x, y int) *NewLineCmd

func (*NewLineCmd) Execute added in v0.2.3

func (c *NewLineCmd) Execute()

func (*NewLineCmd) Info added in v0.2.3

func (c *NewLineCmd) Info() string

func (*NewLineCmd) Reverse added in v0.2.3

func (c *NewLineCmd) Reverse()

type SpaceCmd added in v0.2.3

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

func NewSpaceCmd added in v0.2.3

func NewSpaceCmd(v *View, x, y int) *SpaceCmd

func (*SpaceCmd) Execute added in v0.2.3

func (c *SpaceCmd) Execute()

func (*SpaceCmd) Info added in v0.2.3

func (c *SpaceCmd) Info() string

func (*SpaceCmd) Reverse added in v0.2.3

func (c *SpaceCmd) Reverse()

type UpPermutCmd added in v0.2.3

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

func NewUpPermutCmd added in v0.2.3

func NewUpPermutCmd(v *View, x, y int, n int) *UpPermutCmd

func (*UpPermutCmd) Execute added in v0.2.3

func (c *UpPermutCmd) Execute()

func (*UpPermutCmd) Info added in v0.2.3

func (c *UpPermutCmd) Info() string

func (*UpPermutCmd) Reverse added in v0.2.3

func (c *UpPermutCmd) Reverse()

type View

type View struct {
	Actions Context

	Hidden bool // if true the view will not be drawn

	// BgColor and FgColor allow to configure the background and foreground
	// colors of the View.
	BgColor, FgColor Attribute

	// SelBgColor and SelFgColor are used to configure the background and
	// foreground colors of the selected line, when it is highlighted.
	SelBgColor, SelFgColor Attribute

	// If Editable is true, keystrokes will be added to the view's internal
	// buffer at the cursor position.
	Editable bool

	// Overwrite enables or disables the overwrite mode of the view.
	Overwrite bool

	// If Highlight is true, Sel{Bg,Fg}Colors will be used
	// for the line under the cursor position.
	Highlight bool

	// If Frame is true, a border will be drawn around the view.
	Frame bool

	// If Wrap is true, the content that is written to this View is
	// automatically wrapped when it is longer than its width. If true the
	// view's x-origin will be ignored.
	Wrap bool

	// If Autoscroll is true, the View will automatically scroll down when the
	// text overflows. If true the view's y-origin will be ignored.
	Autoscroll bool

	// If Frame is true, Title allows to configure a title for the view.
	// Title will be placed on the top-left corner
	Title string

	// If Frame is true, Footer allows to configure a footer for the view.
	// Title will be placed on the bottom-right corner
	Footer string

	// If Mask is true, the View will display the mask instead of the real
	// content
	Mask rune
	// contains filtered or unexported fields
}

A View is a window. It maintains its own internal buffer and cursor position.

func (*View) AbsMoveCursor added in v0.2.3

func (v *View) AbsMoveCursor(x, y int, overWrite bool)

Moves the cursor from the beginning taking into account the width of the line/view, displacing the origin if necessary.

func (*View) Buffer added in v0.2.0

func (v *View) Buffer() string

Buffer returns a string with the contents of the view's internal buffer.

func (*View) BufferSize added in v0.2.1

func (v *View) BufferSize() int

Size returns the number of lines contained in the buffer

func (*View) Clear

func (v *View) Clear()

Clear empties the view's internal buffer.

func (*View) Cursor

func (v *View) Cursor() (x, y int)

Cursor returns the cursor position of the view.

func (*View) EditDelete added in v0.2.0

func (v *View) EditDelete(back bool)

EditDelete deletes a rune at the cursor position. back determines the direction.

func (*View) EditNewLine added in v0.2.0

func (v *View) EditNewLine()

EditNewLine inserts a new line under the cursor.

func (*View) EditPermutLines added in v0.2.3

func (v *View) EditPermutLines(up bool)

EditPermutLines permuts the line at the cursor position with the upper or the lower one, given the boolean value

func (*View) EditWrite added in v0.2.0

func (v *View) EditWrite(ch rune)

EditWrite writes a rune at the cursor position.

func (*View) IsEditable added in v0.2.2

func (v *View) IsEditable() bool

func (*View) Line

func (v *View) Line(y int) (string, error)

Line returns a string with the line of the view's internal buffer at the position corresponding to the point (x, y).

func (*View) MoveCursor added in v0.2.0

func (v *View) MoveCursor(dx, dy int, writeMode bool)

MoveCursor moves the cursor taking into account the width of the line/view, displacing the origin if necessary.

func (*View) Name

func (v *View) Name() string

Name returns the name of the view.

func (*View) Origin

func (v *View) Origin() (x, y int)

Origin returns the origin position of the view.

func (*View) Position added in v0.2.3

func (v *View) Position() (int, int, int, int)

Position returns coordinates

func (*View) Read added in v0.2.0

func (v *View) Read(p []byte) (n int, err error)

Read reads data into p. It returns the number of bytes read into p. At EOF, err will be io.EOF. Calling Read() after Rewind() makes the cache to be refreshed with the contents of the view.

func (*View) Rewind added in v0.2.0

func (v *View) Rewind()

Rewind sets the offset for the next Read to 0, which also refresh the read cache.

func (*View) SearchForward added in v0.2.3

func (v *View) SearchForward(pattern string) (bool, int, int)

func (*View) SetCursor

func (v *View) SetCursor(x, y int) error

SetCursor sets the cursor position of the view at the given point, relative to the view. It checks if the position is valid.

func (*View) SetEditable added in v0.2.2

func (v *View) SetEditable(b bool)

func (*View) SetOrigin

func (v *View) SetOrigin(x, y int) error

SetOrigin sets the origin position of the view's internal buffer, so the buffer starts to be printed from this point, which means that it is linked with the origin point of view. It can be used to implement Horizontal and Vertical scrolling with just incrementing or decrementing ox and oy.

func (*View) Size

func (v *View) Size() (x, y int)

Size returns the number of visible columns and rows in the View.

func (*View) ViewBuffer added in v0.2.0

func (v *View) ViewBuffer() string

ViewBuffer returns a string with the contents of the view's buffer that is shown to the user.

func (*View) Word

func (v *View) Word(x, y int) (string, error)

Word returns a string with the word of the view's internal buffer at the position corresponding to the point (x, y).

func (*View) Write

func (v *View) Write(p []byte) (n int, err error)

Write appends a byte slice into the view's internal buffer. Because View implements the io.Writer interface, it can be passed as parameter of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must be called to clear the view's buffer.

type WriteCmd added in v0.2.3

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

func NewWriteCmd added in v0.2.3

func NewWriteCmd(v *View, x, y int, fchar rune) *WriteCmd

func (*WriteCmd) Execute added in v0.2.3

func (c *WriteCmd) Execute()

func (*WriteCmd) Info added in v0.2.3

func (c *WriteCmd) Info() string

func (*WriteCmd) Reverse added in v0.2.3

func (c *WriteCmd) Reverse()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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