ui

package
v0.0.0-...-0e5c193 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2016 License: ISC Imports: 36 Imported by: 0

Documentation

Overview

Package ui contains the T user interface.

Package ui implements the T text editor UI.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound indicates that a resource is not found.

Functions

func Close

func Close(URL *url.URL) error

Close does a DELETE. The URL is expected to point at either a window path or a sheet path.

func NewColumn

func NewColumn(URL *url.URL, x float64) error

NewColumn PUTs a NewColumnRequest. If the response status code is NotFound, ErrNotFound is returned. The URL is expected to point to a window's columns list.

Types

type NewColumnRequest

type NewColumnRequest struct {
	// X is the left-side of the column
	// given as a fraction of the window width.
	// 	X	where
	// 	0 	the left side of the window
	// 	0.5 	the center of the window
	// 	1 	the right side of the window
	// A new column may be restricted to a minimum width.
	X float64 `json:"x"`
}

A NewColumnRequest requests a new column be created.

type NewSheetRequest

type NewSheetRequest struct {
	// URL is either the root URL of an editor server,
	// or the URL of an existing editor server buffer.
	//
	// If URL is an existing buffer, that buffer will be used as the sheet body.
	// Otherwise, a new buffer is created on the editor server for the body.
	URL string `json:"url"`
}

A NewSheetRequest requests a new sheet be created.

type NewWindowRequest

type NewWindowRequest struct {
	// Width is the requested width.
	Width int `json:"width"`

	// Height is the requested height.
	Height int `json:"height"`
}

A NewWindowRequest requests a new window be created.

type Server

type Server struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Server is a T user interface server

func NewServer

func NewServer(scr screen.Screen, editorURL *url.URL) *Server

NewServer returns a new Server for the given Screen. The editorURL must be the root URL of an editor server. Column and sheet tags use buffers created on this editor server.

func (*Server) Close

func (s *Server) Close() error

Close closes all windows. The server should not be used after calling Close.

func (*Server) RegisterHandlers

func (s *Server) RegisterHandlers(r *mux.Router)

RegisterHandlers registers handlers for the following paths and methods:

 /windows is the list of opened windows.

	GET returns a Window list of the opened windows.
	Returns:
	• OK on success.
	• Internal Server Error on internal error.

	PUT creates a new window with a single column and returns its Window.
	The body must be a NewWindowRequest.
	Returns:
	• OK on success.
	• Internal Server Error on internal error.
	• Bad Request if the WindowRequest is malformed.

 /window/<ID> is the window with the given ID.

	DELETE deletes the window and all of its sheets.
	The server process exits when the last window is deleted.
	Returns:
	• OK on success.
	• Internal Server Error on internal error.
	• Not Found if the buffer is not found.

 /window/<ID>/columns is the list of the window's columns.

	PUT adds a column to the window.
	The body must be a NewColumnRequest.
	Returns:
	• OK on success.
	• Internal Server Error on internal error
	  or if a new column cannot fit on the window.
	• Not Found if the window is not found.
	• Bad Request if the WindowRequest is malformed.

 /window/<ID>/sheets is the list of the window's sheets.

	PUT adds a sheet to the left-most column of the window
	and returns its Sheet.
	Returns:
	• OK on success.
	• Internal Server Error on internal error
	  or if a new sheet cannot fit in the column.
	• Not Found if the window is not found.

 /sheets is the list of opened sheets.

	GET returns a Sheet list of the opened sheets.
	Returns:
	• OK on success.
	• Internal Server Error on internal error.

 /sheet/<ID> is the sheet with the given ID.

	DELETE deletes the sheet.
	Returns:
	• OK on success.
	• Internal Server Error on internal error.
	• Not Found if the sheet is not found.

Unless otherwise stated, the body of all error responses is the error message.

func (*Server) SetDoneHandler

func (s *Server) SetDoneHandler(f func())

SetDoneHandler sets the function which is called if the last window is closed. By default, the done handler is a no-op.

type Sheet

type Sheet struct {
	// ID is the ID of the sheet.
	ID string `json:"id"`

	// Path is the path to the sheet's resource.
	Path string `json:"path"`

	// WindowPath is the path to the sheet's window's resource.
	WindowPath string `json:"windowPath"`

	// TagURL is the URL of the tag's buffer.
	TagURL string `json:"tagUrl"`

	// BodyURL is the URL of the body's buffer.
	BodyURL string `json:"bodyUrl"`
}

A Sheet describes an opened sheet.

func NewSheet

func NewSheet(uiURL *url.URL, editorOrBufferURL *url.URL) (Sheet, error)

NewSheet does a PUT and areturns a Sheet from the response body. If the response status code is NotFound, ErrNotFound is returned. The URL is expected to point to a window's sheets list.

func SheetList

func SheetList(URL *url.URL) ([]Sheet, error)

SheetList goes a GET and returns a list of Sheets from the response body. The URL is expected to point to the server's sheets list.

type Window

type Window struct {
	// ID is the ID of the window.
	ID string `json:"id"`

	// Path is the path of the window's resource.
	Path string `json:"path"`
}

A Window describes an opened window.

func NewWindow

func NewWindow(URL *url.URL, size image.Point) (Window, error)

NewWindow PUTs a NewWindowRequest with Width and Height set to size.X and size.Y respectively, and returns a Window from the response body. The URL is expected to point at the server's windows list.

func WindowList

func WindowList(URL *url.URL) ([]Window, error)

WindowList goes a GET and returns a list of Windows from the response body. The URL is expected to point to the server's windows list.

Notes

Bugs

  • column 0 still ends up as column 1.

Directories

Path Synopsis
Package text handles rich-formatted text layout and drawing.
Package text handles rich-formatted text layout and drawing.

Jump to

Keyboard shortcuts

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