atto

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 11 Imported by: 0

README

                         db
                        d88b       ,d      ,d
                       d8'`8b      88      88
                      d8'  `8b   MM88MMM MM88MMM ,adPPYba,
                     d8YaaaaY8b    88      88   a8"     "8a
                    d8""""""""8b   88      88   8b       d8
                   d8'        `8b  88,     88,  "8a,   ,a8"
                  d8'          `8b "Y888   "Y888 `"YbbdP"'

+------------------------------------------------------------------------------+

// ----------------------------------------------
// this fork is an mostly unmodified copy of 
// https://github.com/jonpalmisc/atto
// the only modifications are to make the program
// compatable with the gosh shell arguments
// and a few minor modifications to fix the
// program not exiting properly for gosh
// ----------------------------------------------

1.  About

    Atto is a lightweight, opinionated text editor written in Go. The current
    feature set is quite limited, but Atto is being actively developed. Many
    features and improvements should be added in the coming weeks.

2.  Features

    The following features are currently available in Atto:

      - Core editor functionality (text viewing & editing)
      - Multiple simultaneous buffers
      - Simple syntax highlighting (Go & C)
      - User configuration files (options limited)

    In addition to the features above, the following features are planned:

      - Copy/cut/paste functionality
      - Smarter syntax highlighting with user-definable language syntax files

    WARNING: Atto currently compiles on macOS, Linux, and Windows, but is only
    being actively developed and tested on macOS at this time. Atto may be
    unstable on other platforms at this time.

3.  Installation

    Just build and place the binary somewhere in your PATH.

4.  Usage

    $ atto <file>

5.  Configuration

    When you start Atto for the first time, a configuration folder will be
    created for you at '~/.atto'. Inside you will find a config.yml file which
    you can edit to change the editor's exposed preferences.

6.  License

    Atto is licensed under the MIT License. See LICENSE.txt for more info.

Documentation

Index

Constants

View Source
const (
	ProgramName    string = "Atto"
	ProgramVersion string = "0.4.0"
	ProgramAuthor  string = "Jon Palmisciano <jonpalmisc@gmail.com>"
)

Variables

This section is empty.

Functions

func AttoFolderPath

func AttoFolderPath() (string, error)

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the path of Atto's config file on the current platform.

func HighlightLine

func HighlightLine(l *BufferLine, s *Syntax)

func IsInsertable

func IsInsertable(c rune) bool

func IsSeparator

func IsSeparator(c rune) bool

func Start

func Start(args []string)

Types

type Buffer

type Buffer struct {
	Editor *Editor

	// The name and type of the file currently being edited.
	FileName string
	FileType FileType

	Lines   []BufferLine
	IsDirty bool

	// The cursor's position. The Y value must always be decremented by one when
	// accessing buffer elements since the editor's title bar occupies the first
	// row of the screen. CursorDX is the cursor's X position, with compensation
	// for extra space introduced by rendering tabs.
	CursorX  int
	CursorDX int
	CursorY  int

	// The viewport's column and row offsets.
	OffsetX int
	OffsetY int
}

func CreateBuffer

func CreateBuffer(editor *Editor, path string) (Buffer, error)

CreateBuffer creates a new buffer for a given path.

func (*Buffer) BreakLine

func (b *Buffer) BreakLine()

BreakLine inserts a newline character and breaks the line at the cursor.

func (*Buffer) DeleteChar

func (b *Buffer) DeleteChar()

DeleteChar deletes the character to the left of the cursor.

func (*Buffer) FocusedRow

func (b *Buffer) FocusedRow() *BufferLine

FocusedRow returns the buffer's focused row.

func (*Buffer) InsertChar

func (b *Buffer) InsertChar(c rune)

InsertChar inserts a character at the cursor's position.

func (*Buffer) InsertLine

func (b *Buffer) InsertLine(i int, text string)

InsertLine inserts a new line to the buffer at the given index.

func (*Buffer) Length

func (b *Buffer) Length() int

Length returns the buffer's length (number of lines).

func (*Buffer) RemoveLine

func (b *Buffer) RemoveLine(i int)

RemoveLine removes the line at the given index from the buffer.

type BufferLine

type BufferLine struct {
	Buffer       *Buffer
	Text         string
	DisplayText  string
	Highlighting []HighlightType
}

BufferLine represents a single line in a buffer.

func MakeBufferLine

func MakeBufferLine(buffer *Buffer, text string) (bl BufferLine)

MakeBufferLine creates a new BufferLine with the given text.

func (*BufferLine) AdjustX

func (l *BufferLine) AdjustX(x int) int

AdjustX corrects the cursor's X position to compensate for rendering effects.

func (*BufferLine) AppendString

func (l *BufferLine) AppendString(s string)

AppendString appends a string to the line.

func (*BufferLine) DeleteChar

func (l *BufferLine) DeleteChar(i int)

DeleteChar deletes a character from the line at the given index.

func (*BufferLine) IndentLength

func (l *BufferLine) IndentLength() (indent int)

IndentLength gets the line's level of indentation in columns.

func (*BufferLine) InsertChar

func (l *BufferLine) InsertChar(i int, c rune)

InsertChar inserts a character into the line at the given index.

func (*BufferLine) Update

func (l *BufferLine) Update()

Update refreshes the DisplayText field.

type Config

type Config struct {
	TabSize         int
	SoftTabs        bool
	UseHighlighting bool
}

Config holds the editor's configuration and settings.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default configuration.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig attempts to load the user's config

type CursorMove

type CursorMove int

CursorMove is a type of cursor movement.

const (
	// CursorMoveUp moves the cursor up one row.
	CursorMoveUp CursorMove = 0

	// CursorMoveDown moves the cursor down one row.
	CursorMoveDown CursorMove = 1

	// CursorMoveLeft moves the cursor left one column.
	CursorMoveLeft CursorMove = 2

	// CursorMoveRight moves the cursor right one column.
	CursorMoveRight CursorMove = 3

	// CursorMoveLineStart moves the cursor to the first non-whitespace
	// character of the line, or the first character of the line if the cursor
	// is already on the first non-whitespace character.
	CursorMoveLineStart CursorMove = 4

	// CursorMoveLineEnd moves the cursor to the end of the line.
	CursorMoveLineEnd CursorMove = 5

	// CursorMovePageUp moves the cursor up by the  height of the screen.
	CursorMovePageUp CursorMove = 6

	// CursorMovePageDown moves the cursor down by the  height of the screen.
	CursorMovePageDown CursorMove = 7
)

type Editor

type Editor struct {

	// The editor's buffers and the index of the focused buffer.
	Buffers    []Buffer
	FocusIndex int

	// The editor's height and width measured in rows and columns, respectively.
	Width  int
	Height int

	// The current status message and the time it was set.
	StatusMessage     string
	StatusMessageTime time.Time

	// The prompt question, answer, and whether it is active or not.
	PromptQuestion string
	PromptAnswer   string
	PromptIsActive bool

	// The user's editor configuration.
	Config Config
}

Editor is the editor instance and manages the UI.

func CreateEditor

func CreateEditor() (editor Editor)

CreateEditor creates a new Editor instance.

func (*Editor) Ask

func (e *Editor) Ask(q, a string) (string, error)

Ask prompts the user to answer a question and assumes control over all input until the question is answered or the request is cancelled.

func (*Editor) AskChar

func (e *Editor) AskChar(q string, choices []rune) (rune, error)

func (*Editor) BufferCount

func (e *Editor) BufferCount() int

BufferCount is a shorthand for getting the number of open buffers.

func (*Editor) Close

func (e *Editor) Close(i int)

Close closes the focused buffer.

func (*Editor) DeletePromptChar

func (e *Editor) DeletePromptChar()

DeletePromptChar removes a character from the current prompt answer.

func (*Editor) DirtyBufferCount

func (e *Editor) DirtyBufferCount() (count int)

DirtyBufferCount returns the number of dirty buffers.

func (*Editor) Draw

func (e *Editor) Draw()

Draw draws the entire editor - UI, buffer, etc. - to the screen & updates the cursor's position.

func (*Editor) DrawBuffer

func (e *Editor) DrawBuffer()

DrawBuffer draws the editor's focused buffer.

func (*Editor) DrawStatusBar

func (e *Editor) DrawStatusBar()

DrawStatusBar draws the editor's status bar on the bottom of the screen.

func (*Editor) DrawTitleBar

func (e *Editor) DrawTitleBar()

DrawTitleBar draws the editor's title bar at the top of the screen.

func (*Editor) FB

func (e *Editor) FB() *Buffer

FB returns the focused buffer.

func (*Editor) HandleEvent

func (e *Editor) HandleEvent(event termbox.Event)

HandleEvent executes the appropriate code in response to an event.

func (*Editor) InsertPromptChar

func (e *Editor) InsertPromptChar(c rune)

InsertPromptChar inserts a character into the current prompt answer.

func (*Editor) MoveCursor

func (e *Editor) MoveCursor(move CursorMove)

MoveCursor moves the cursor according to the operation provided.

func (*Editor) MovePromptCursor

func (e *Editor) MovePromptCursor(move CursorMove)

MovePromptCursor moves the cursor inside of the current prompt.

func (*Editor) Open

func (e *Editor) Open()

Open prompts the user for a path and creates a new buffer for it.

func (*Editor) Read

func (e *Editor) Read(path string)

Read reads a file into a new buffer.

func (*Editor) Run

func (e *Editor) Run(args []string)

Run starts the editor.

func (*Editor) Save

func (e *Editor) Save()

Save writes the current buffer back to the file it was read from.

func (*Editor) ScrollView

func (e *Editor) ScrollView()

ScrollView recalculates the offsets for the view window.

func (*Editor) SetStatusMessage

func (e *Editor) SetStatusMessage(format string, args ...interface{})

SetStatusMessage sets the status message and the time it was set at.

func (*Editor) Shutdown

func (e *Editor) Shutdown()

Shutdown tears down the terminal screen and ends the process.

type FileType

type FileType string

FileType represents a type of file.

const (
	FileTypeMakefile FileType = "Makefile"
	FileTypeCMake    FileType = "CMake"

	FileTypeGo       FileType = "Go"
	FileTypeGoModule FileType = "Go Module"

	// -- C/C++ --
	FileTypeC   FileType = "C"
	FileTypeCPP FileType = "C++"

	// -- Text Files --
	FileTypeMarkdown  FileType = "Markdown"
	FileTypePlaintext FileType = "Plaintext"

	FileTypeUnknown FileType = "Unknown"
)

func GuessFileType

func GuessFileType(name string) FileType

GuessFileType attempts to deduce a file's type from its name and extension.

type HighlightType

type HighlightType int
const (
	HighlightTypeNormal HighlightType = iota
	HighlightTypePrimaryKeyword
	HighlightTypeSecondaryKeyword
	HighlightTypeNumber
	HighlightTypeString
	HighlightTypeComment
)

func (HighlightType) Color

func (t HighlightType) Color() termbox.Attribute

type Syntax

type Syntax struct {
	Keywords []string
	Patterns SyntaxPatterns
}

Syntax represent's a language syntax for highlighting purposes.

var SyntaxC Syntax = Syntax{
	Keywords: []string{
		"#define", "#include", "NULL", "auto", "break", "case", "char", "const",
		"continue", "default", "do", "double", "else", "enum", "extern", "float",
		"for", "goto", "if", "int", "long", "register", "return", "short",
		"signed", "sizeof", "static", "struct", "switch", "typedef", "union",
		"unsigned", "void", "volatile", "while",
	},
	Patterns: SyntaxPatterns{
		SingleLineCommentStart: "//",
		MultiLineCommendStart:  "/*",
		MultiLineCommentEnd:    "*/",
	},
}

SyntaxC defines the syntax of the C language.

var SyntaxGo Syntax = Syntax{
	Keywords: []string{
		"append", "bool", "break", "byte", "cap", "case", "chan", "close",
		"complex", "complex128", "complex64", "const", "continue", "copy",
		"default", "defer", "delete", "else", "error", "fallthrough", "false",
		"float32", "float64", "for", "func", "go", "goto", "if", "imag",
		"import", "int", "int16", "int32", "int64", "int8", "interface", "len",
		"make", "map", "new", "nil", "package", "panic", "range", "real",
		"recover", "return", "rune", "select", "string", "struct", "switch",
		"true", "type", "uint", "uint16", "uint32", "uint64", "uint8", "uintptr",
		"var",
	},
	Patterns: SyntaxPatterns{
		SingleLineCommentStart: "//",
		MultiLineCommendStart:  "/*",
		MultiLineCommentEnd:    "*/",
	},
}

SyntaxGo defines the syntax of the Go language.

type SyntaxPatterns

type SyntaxPatterns struct {
	SingleLineCommentStart string
	MultiLineCommendStart  string
	MultiLineCommentEnd    string
}

SyntaxPatterns is used to define syntax patterns for the highlighter.

Jump to

Keyboard shortcuts

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