core

package
v0.0.0-...-a7e8193 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2017 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

CountLines does a quick (buffered) line(\n) count of a file.

package core contains the core data structures and functionality leveraged y the other other Goed packages.

Index

Constants

View Source
const (
	Plain uint16 = 1 << (8 + iota)
	Bold
	Underlined
)
View Source
const (
	CursorMvmtRight      CursorMvmt = 0
	CursorMvmtLeft                  = 1
	CursorMvmtUp                    = 2
	CursorMvmtDown                  = 3
	CursorMvmtPgDown                = 4
	CursorMvmtPgUp                  = 5
	CursorMvmtHome                  = 6
	CursorMvmtEnd                   = 7
	CursorMvmtTop                   = 8
	CursorMvmtBottom                = 9
	CursorMvmtScrollDown            = 10
	CursorMvmtScrollUp              = 11
)
View Source
const (
	ViewTypeStandard   ViewType = 0 // editable file
	ViewTypeShell               = 1 // interactive shell
	ViewTypeCmdOutput           = 2 // static command output
	ViewTypeDirListing          = 3 // similar to 3 but specific to a dir listing
)
View Source
const ApiVersion = "v1"
View Source
const Version = "0.1.2"

Variables

View Source
var ApiPort int
View Source
var Colors int

Colors is the number of colors to use in the terminal

View Source
var ConfFile string

ConfigFile holds the path to the config file currently in use.

View Source
var Home string

Home represent the goed "home" folder.

View Source
var InstanceId int64 // instance ID
View Source
var LineSep = []byte{'\n'}
View Source
var LogFile *os.File

LogFile holds the path of the log file currently in use.

View Source
var OsLsArgs []string
View Source
var ShowEvents = false
View Source
var Socket string // instance RPC socket
View Source
var Terminal string

terminal as defined by $SHELL

View Source
var Testing bool

testing : whether we are in "unit test" mode.

View Source
var Trace = false

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func BomEncoding

func BomEncoding(from string) encoding.Encoding

Check if the file starts with a bom and if so return the encoding Returns nil if no BOM or unsupported encoding

func Cleanup

func Cleanup()

func CleanupDotGoed

func CleanupDotGoed()

func ClipboardRead

func ClipboardRead() (string, error)

func ClipboardWrite

func ClipboardWrite(s string) error

func CopyFile

func CopyFile(from, to string) error

func CopyFromUTF8

func CopyFromUTF8(from, to string, dstEnc encoding.Encoding) error

func CopyToUTF8

func CopyToUTF8(from, to string, srcEnc encoding.Encoding) error

func CountLines

func CountLines(r io.Reader) (int, error)

func DetectColors

func DetectColors() int

func EnvWith

func EnvWith(custom []string) []string

func FindResource

func FindResource(relPath string) (absPath string)

GetResource finds a GOED resource either from - GOED_HOME/<path> or - GOED/HOME/standard/<path>

func GoedHome

func GoedHome() string

func GoedSocket

func GoedSocket(id int64) string

func InitHome

func InitHome(id int64)

InitHome initializes the ~/.goed directory structure

func Instances

func Instances() (ids []int64)

Instances returns a list of known Goed Instances

func IsDir

func IsDir(loc string) bool

func LookupLocation

func LookupLocation(dir, loc string) (string, bool)

LookupLocation will try to locate the given location if not found relative to dir, then try up the directory tree this works great to open GO import path for example

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func MvFile

func MvFile(from, to string) error

Mv file moves a file by copy, then delete because os.Rename does not always work

func RandString

func RandString(n int) string

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func RunesLen

func RunesLen(runes []rune) int

func RunesToString

func RunesToString(runes [][]rune) string

RunesToString transforms a rune matrix as a string.

func StringToRunes

func StringToRunes(s string) [][]rune

StringToRunes transforms a string into a rune matrix.

func SyntaxHighlighting

func SyntaxHighlighting() bool

func TermColors

func TermColors()

Print colors to terminal to try it.

func UpdateResources

func UpdateResources()

UpdateResource creates or updates the bundled resources into GOED_HOME

func UsesCrLf

func UsesCrLf(file string) bool

Check if the file appears to use CRLF line breaks by looking for line breaks in the first 1000 bytes.

Types

type Action

type Action interface {
	Run()
}

type ActionDispatcher

type ActionDispatcher interface {
	Dispatch(action Action)
	Flush()
	Shutdown()
	Start()
}

type AddCrLfTransformer

type AddCrLfTransformer struct{}

Replace "\n" with "\r\n" windows combos

func (AddCrLfTransformer) Reset

func (t AddCrLfTransformer) Reset()

func (AddCrLfTransformer) Transform

func (t AddCrLfTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

type Backend

type Backend interface {
	// SrcLoc returns the location of the original data.
	SrcLoc() string
	// BufferLoc is the location of the "copy" the backend works directly on.
	BufferLoc() string

	Insert(line, col int, text string) error
	Append(text string) error
	Remove(line1, col1, line2, col2 int) error

	LineCount() int

	// Save saves the edited data (BufferLoc) into the original (SrcLoc)
	Save(loc string) error

	SendBytes(data []byte)

	// Slice gets a region of text ("rectangle") as a runes matrix
	Slice(line1, col, line2, col2 int) *Slice

	// Close closes the backend resources.
	Close() error

	// ViewId returns the "unique" viewid given to this buffer.
	ViewId() int64

	// Completely clears the buffer text (empty document)
	Wipe()

	// Reloads the text (from SrcLoc to BufferLoc)
	Reload() error

	// return the color style at a specific location (mem backends)
	ColorAt(ln, col int) (fg, bg Style)

	//SourceMd5 or ts?
	//BufferMd5 or ts?
	SetVtCols(cols int)
	OnActivate()

	OffsetAt(ln, col int) int64
}

Backend represent the backend(data operations) of a View. Backend implements the low level data handling.

type Commander

type Commander interface {
	Backspace()
	Clear()
	CursorMvmt(mvmt CursorMvmt)
	Delete()
	Insert(text string)
	NewLine()
}

interafce for the command bar

type Config

type Config struct {
	SyntaxHighlighting bool
	Theme              string // ie: theme1.toml
	MaxCmdBufferLines  int    // Max # of lines to keep in buffer when running a command
	GuiFont            string // full path to a monospace TTF font
	GuiFontSize        int
	GuiFontDpi         int
	MinViewWidth       int // preferred minimum view width (in characters)
	LineWidthIndicator int // line width indicator (ie: 80 cols)
}

Config represents the Goed configuration data.

func LoadConfig

func LoadConfig(file string) *Config

type CrLfEncoding

type CrLfEncoding struct {
	ChainWith encoding.Encoding
}

CrLfEncoding encode / decodes '\r\n' to '\n'

func (CrLfEncoding) NewDecoder

func (c CrLfEncoding) NewDecoder() *encoding.Decoder

func (CrLfEncoding) NewEncoder

func (c CrLfEncoding) NewEncoder() *encoding.Encoder

type CursorMvmt

type CursorMvmt byte

type DropCrLfTransformer

type DropCrLfTransformer struct{}

Drop Windows "\r\n" combos (in favor of plain "\n")

func (DropCrLfTransformer) Reset

func (t DropCrLfTransformer) Reset()

func (DropCrLfTransformer) Transform

func (t DropCrLfTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

type Editable

type Editable interface {
	Commandbar() Commander
	CmdbarToggle()
	Config() Config
	CurViewId() int64
	DelColByIndex(col int, check bool)
	DelView(viewId int64, terminate bool)
	DelViewCheck(viewId int64, terminate bool)
	Dispatch(action Action)
	FileEvent(op FileOp, loc string)
	// CmdOn indicates whether the CommandBar is currently active
	CmdOn() bool
	// Open opens a file in the given view (new view if viewid<0)
	// create -> create file at loc if does not exist yet
	Open(loc string, viewId int64, rel string, create bool) (int64, error)
	Quit()
	QuitCheck() bool
	// Render updates the whole editor UI
	Render()
	Resize(h, w int)
	// SetStatusErr displays an error message in the status bar
	SetStatusErr(err string)
	// SetStatusErr displays a message in the status bar
	SetStatus(status string)
	SetCursor(y, x int)
	// SetCmdOn activates or desactives the CommandBar
	SetCmdOn(v bool)
	Size() (h, w int)
	StartTermView(args []string) int64
	SwapViews(v1, v2 int64)
	Start(locs []string)
	TermChar(y, x int, c rune)
	TermFB(fg, bg Style)
	TermFill(c rune, y1, x1, y2, x2 int)
	TermFlush()
	TermStr(y, x int, s string)
	TermStrv(y, x int, s string)
	Theme() *Theme
	ViewActivate(v int64)
	ViewAt(ln, col int) int64
	// ViewByLoc finds if there is an existing view for the given file (loc)
	ViewById(id int64) Viewable
	ViewsByLoc(loc string) []int64
	ViewIndex(id int64) (row, col int) // column, row **index** in the editor UI
	// Move a view
	ViewMove(y1, x1, y2, x2 int)
	// Navigate from a view to another
	ViewNavigate(mvmt CursorMvmt)
	Views() []int64 // list of all opened views
}

Editable provides editor features entry poins.

var Ed Editable

Ed is thew editor singleton

type FileOp

type FileOp uint32
const (
	OpCreate FileOp = 1 << iota
	OpWrite
	OpRemove
	OpRename
	OpChmod
)

type Highlighter

type Highlighter interface {
	UpdateHighlights(v Viewable)
	ApplyHighlight(v Viewable, lnOffset, ln, col int)
}

type MockTerm

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

Mock Terminal implementation for testing

func NewMockTerm

func NewMockTerm() *MockTerm

func (*MockTerm) Char

func (t *MockTerm) Char(y, x int, c rune, fg, bg Style)

func (*MockTerm) CharAt

func (t *MockTerm) CharAt(y, x int) rune

for testing

func (*MockTerm) Clear

func (t *MockTerm) Clear(fg, bg Style)

func (*MockTerm) Close

func (t *MockTerm) Close()

func (*MockTerm) Flush

func (t *MockTerm) Flush()

func (*MockTerm) Init

func (t *MockTerm) Init() error

func (*MockTerm) Listen

func (t *MockTerm) Listen()

func (*MockTerm) SetCursor

func (t *MockTerm) SetCursor(y, x int)

func (*MockTerm) SetExtendedColors

func (t *MockTerm) SetExtendedColors(b bool)

func (*MockTerm) Size

func (t *MockTerm) Size() (h, w int)

type Rwsc

type Rwsc interface {
	io.Reader
	io.Writer
	io.ReaderAt
	io.WriterAt
	io.Seeker
	io.Closer
}

type Selection

type Selection struct {
	LineFrom, ColFrom int // selection start point
	LineTo, ColTo     int // selection end point (colto=-1 means whole lines)
}

Selection represents some selected text in a view

func NewSelection

func NewSelection(l1, c1, l2, c2 int) *Selection

func (*Selection) Normalize

func (s *Selection) Normalize()

Normalize the slection such as l1,c1 is "before" l2, c2

func (Selection) String

func (s Selection) String() string

String return the selection in the form "line1 col1 line2 col2"

type Slice

type Slice struct {
	sync.RWMutex

	R1, C1, R2, C2 int //bounds
	// contains filtered or unexported fields
}

Slice represents a "matrix" of text (runes) coordinates are of a rectangle (unlike a selection whihc is ptA to ptB)

func NewSlice

func NewSlice(r1, c1, r2, c2 int, text [][]rune) *Slice

func (*Slice) ContainsLine

func (s *Slice) ContainsLine(lnIndex int) bool

func (*Slice) Normalize

func (s *Slice) Normalize()

func (*Slice) Text

func (s *Slice) Text() *[][]rune

type Style

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

The format of a style as stored in a file is 4 bytes, HexaDecimal as follows: color, attr

func NewStyle

func NewStyle(s uint16) Style

func (Style) Color

func (s Style) Color() byte

func (Style) IsBold

func (s Style) IsBold() bool

func (Style) IsUnderlined

func (s Style) IsUnderlined() bool

func (Style) Uint16

func (s Style) Uint16() uint16

func (*Style) UnmarshalText

func (s *Style) UnmarshalText(text []byte) error

func (Style) WithAttr

func (s Style) WithAttr(attr uint16) Style

type StyledRune

type StyledRune struct {
	Rune rune
	Fg   Style
	Bg   Style
}

func (*StyledRune) UnmarshalText

func (s *StyledRune) UnmarshalText(text []byte) error

type Term

type Term interface {
	Close()
	Clear(fg, bg Style)
	Char(y, x int, c rune, fg, bg Style)
	Flush()
	Init() error
	Listen()
	SetExtendedColors(bool)
	SetCursor(y, x int)
	Size() (y, x int)
}

Terminal interface

type TextInfo

type TextInfo struct {
	Enc encoding.Encoding
}

func CrLfTextInfo

func CrLfTextInfo(enc encoding.Encoding, usesCrLf bool) *TextInfo

return TextInfo with extra CrLf encoding/decoding if needed

func ReadTextInfo

func ReadTextInfo(file string, usesCrLf bool) *TextInfo

ReadTextInfo checks if a file appears to be text or not(binary) Returns nil if the file appears binary or some unsupported encoding.

type Theme

type Theme struct {
	Bg       Style // default to term bg
	Fg       Style // default to term fg
	BgSelect Style // default to term bg
	FgSelect Style // default to term fg
	BgCursor Style
	FgCursor Style

	Comment                            Style
	String                             Style
	Number                             Style
	Keyword1, Keyword2, Keyword3       Style
	Symbol1, Symbol2, Symbol3          Style
	Separator1, Separator2, Separator3 Style

	FileClean        StyledRune
	FileDirty        StyledRune
	Scrollbar        StyledRune
	ScrollTab        StyledRune
	Statusbar        StyledRune
	StatusbarText    Style
	StatusbarTextErr Style
	Cmdbar           StyledRune
	CmdbarText       Style
	CmdbarTextOn     Style
	Viewbar          StyledRune
	ViewbarText      Style
	MoreTextSide     StyledRune
	MoreTextUp       StyledRune
	MoreTextDown     StyledRune
	TabChar          StyledRune
	Margin           StyledRune
	Close            StyledRune
}

Theme represents a goed theme data.

func ReadDefaultTheme

func ReadDefaultTheme() (*Theme, error)

func ReadTheme

func ReadTheme(loc string) (*Theme, error)

type ViewType

type ViewType int

type Viewable

type Viewable interface {
	Widget
	Backspace()
	Backend() Backend
	ClearSelections()
	Copy()
	CurCol() int
	CurLine() int
	CursorMvmt(mvmt CursorMvmt)
	Cut()
	Delete(row1, col1, row, col2 int, undoable bool)
	DeleteCur()
	Dirty() bool
	Id() int64
	Insert(row, col int, text string, undoable bool)
	InsertCur(text string)
	InsertNewLineCur()
	LastViewCol() int
	LastViewLine() int
	LineCount() int
	// LineRunesTo returns the number of raw runes to the given line column
	LineRunesTo(s *Slice, line, col int) int
	// MoveCursor moves the cursor by the y, x offsets (in runes)
	MoveCursor(y, x int)
	MoveCursorRoll(y, x int)
	OpenSelection(newView bool)
	Paste()
	// Reload reloads the view data from it's source (backend)
	Reload()
	// Reset reinitializes the view to it's startup state.
	Reset()
	Save() // Save from buffer to src
	ScrollPos() (ln, col int)
	SetBackend(backend Backend)
	SetDirty(bool)
	SelectAll()
	SelectWord(ln, col int)
	Selections() *[]Selection
	// SetAutoScroll is used to make the view scroll contonuously in y,x increments
	// keeps scrolling until x and y are set to 0.
	SetAutoScroll(y, x int, isSelect bool)
	SetCursorPos(y, x int)
	SetScrollPct(ypct int)
	SetScrollPos(y, x int)
	SetTitle(title string)
	SetViewType(t ViewType)
	SetVtCols(cols int)
	// Sets the view work directory, commands and "open" actions will be relative
	// to this path.
	SetWorkDir(dir string)
	// Slice returns a view's text subset (rectangle)
	Slice() *Slice
	StretchSelection(prevl, prevc, ln, c int)
	SyncSlice()
	Title() string
	Text(ln1, col1, ln2, col2 int) [][]rune
	Type() ViewType
	WorkDir() string
}

Viewable is the interface to a View

type Widget

type Widget interface {
	// Get the widget bounds (within parent)
	Bounds() (y1, x1, y2, x2 int)
	// Get parent widget or nil if none
	GetParent() Widget
	// Render forces re-rendering the view UI.
	Render()
	// Set the widget bounds (within parent)
	SetBounds(y1, x1, y2, x2 int)
	// Set the parent, typically internal use only
	SetParent(w Widget)
}

Jump to

Keyboard shortcuts

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