noter

package module
v0.0.0-...-21352b2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 11 Imported by: 0

README

📝 noter

My blog posts:


A text editor for macOS. Built using the Ebitengine game engine.

It's a little bit like nano.

A screenshot of the editor running. It looks like nano. It has a text file called 'A Bird, came down the Walk' opened.

Shortcuts

Highlight with (shift + arrow key).

Swap lines with option + (up)/(down).

Command +

  • (z) undo
  • (f) search
  • (a) select all
  • (c) copy
  • (x) cut
  • (v) paste
  • (x) save
  • (q) quit without saving
  • (left)/(right) skips to start/end of line
  • (up)/(down) skip to start/end of document

Development

Run the editor go run github.com/healeycodes/noter/cmd/noter -- "A Bird, came down the Walk.txt"

Build

Build go build ./cmd/noter

Run the editor ./noter "A Bird, came down the Walk.txt"

Tests

go test .

Roadmap

  • More tests
  • Implement redo?

Documentation

Index

Constants

View Source
const (
	EDITOR_DEFAULT_ROWS = 25
	EDITOR_DEFAULT_COLS = 80
)
View Source
const (
	EDIT_MODE = iota
	SEARCH_MODE
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content interface {
	ReadText() []byte // Read the entire content of the text clipboard.
	WriteText([]byte) // Write replaces the entire content of the text clipboard.
}

Content is an interface to a clipboard or file to read/write data. We use this instead of io.ReadWriter as we do not want to handle errors or buffered reads in the Editor; we force that to the caller of the editor.

type Editor

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

Editor is a simple text editor, compliant to the ebiten.Game interface.

The Meta or Control key can be used with the following command keys:

| Keystroke  | Action |
| ---        | ---    |
| COMMAND-S  | Save the content. |
| COMMAND-L  | Load the content. |
| COMMAND-C  | Copy the selection to clipboard. |
| COMMAND-V  | Paste clipboard into the selection/current cursor. |
| COMMAND-X  | Cut the selection, saving a copy into the clipboard. |
| COMMAND-F  | Find text in the content. |
| COMMAND-Q  | Quit the editor. |

func NewEditor

func NewEditor(options ...EditorOption) (e *Editor)

NewEditor creates a new editor. See the EditorOption type for available options that can be passed to change its defaults.

If neither the WithHeight nor WithRows options are set, the editor defaults to 25 rows. The resulting image width is `rows * font.Face.Metrics().Height`

If neither the WithWidth nor the WithCols options are set, the editor defaults to 80 columns. The resulting image width is `cols * font.Face.GlyphAdvance('0')`

func (*Editor) Content

func (e *Editor) Content() Content

Content() returns the current content manager.

func (*Editor) ContentName

func (e *Editor) ContentName() string

ContentName() returns the current content name.

func (*Editor) Cursor

func (e *Editor) Cursor() (row int, col int)

Cursor returns the current cursor position.

func (*Editor) Draw

func (e *Editor) Draw(screen *ebiten.Image)

Draw the editor onto the screen, scaled to full size.

func (*Editor) Image

func (e *Editor) Image() (img *ebiten.Image)

Return the internal image of the editor.

func (*Editor) IsModified

func (e *Editor) IsModified() bool

IsModified returns true if the editor is in modified state.

func (*Editor) Layout

func (e *Editor) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

func (*Editor) Load

func (e *Editor) Load()

Load loads the text from the Content assigned to the editor.

func (*Editor) MoveCursor

func (e *Editor) MoveCursor(row int, col int)

MoveCursor moves the cursor to the specified location. If `row` is `-1` then the cursor will be on the final row. If `col` is `-1` then the cursor is moved to the final rune in the row.

func (*Editor) ReadText

func (e *Editor) ReadText() []byte

ReadText returns all of the text in the editor. Note that this does not clear the 'modified' state of the editor.

func (*Editor) Save

func (e *Editor) Save()

Save saves the text to the Content assigned to the editor. This clears the 'modified' bit also.

func (*Editor) SetContent

func (e *Editor) SetContent(content Content)

SetContent() sets the content manager. NOTE: This does _not_ modify the editor until a Load()

func (*Editor) SetContentName

func (e *Editor) SetContentName(content_name string)

SetContentName updates the top bar's content name.

func (*Editor) Size

func (e *Editor) Size() (width, height int)

Return the size in pixels of the editor.

func (*Editor) Update

func (e *Editor) Update() error

Update the editor state.

func (*Editor) WriteText

func (e *Editor) WriteText(text []byte)

WriteText replaces all of the text in the editor. Note that this clears the 'modified' state of the editor, and disables all selection highlighting.

type EditorOption

type EditorOption func(e *Editor)

EditorOption is an option that can be sent to NewEditor()

func WithBackgroundColor

func WithBackgroundColor(opt color.Color) EditorOption

WithBackgroundColor sets the color of the background.

func WithBackgroundImage

func WithBackgroundImage(opt *ebiten.Image) EditorOption

WithBackgroundImage sets the ebiten.Image in the background. It will be scaled to fit the entire background of the editor.

func WithBottomBar

func WithBottomBar(enabled bool) EditorOption

WithBottomBar enables the display of the last row as a help display.

func WithClipboard

func WithClipboard(opt Content) EditorOption

WithClipboard sets the clipboard accessor. If set to nil, an in-memory content manager is used.

func WithColumns

func WithColumns(opt int) EditorOption

WithColumns sets the total number of columns in the editor, including the line-number area, if enabled. If set to < 0, then:

  • if WithWidth is set, then the maximum number of columns that would fit, based on font advance of the glyph '0', is used.
  • if WithWidth is not set, then the number of columns defaults to 80.

func WithContent

func WithContent(opt Content) EditorOption

WithContent sets the content accessor, and permits saving and loading. If set to nil, an in-memory content manager is used.

func WithContentName

func WithContentName(opt string) EditorOption

WithContentName sets the name of the content

func WithCursorColor

func WithCursorColor(opt color.Color) EditorOption

WithCursorColor sets the color of the cursor over the text. It is recommended to have an Alpha component of 90.

func WithFontColor

func WithFontColor(opt color.Color) EditorOption

WithFontColor sets the color of the text. It is recommended to have an Alpha component of 255.

func WithFontFace

func WithFontFace(opt font.Face) EditorOption

WithFontFace set the default font. If set to nil, the monospace font `github.com/hajimehoshi/bitmapfont/v3` is used.

func WithHeight

func WithHeight(opt int) EditorOption

WidthHeight sets the image height of the editor. If WithRows is set, the font is scaled appropriately to the height. If WithRows is not set, the maximum number of rows that would fit are used, with any additional padding to the bottom of the editor. If not set, see the 'WithRows()' option for the calculation.

func WithHighlightColor

func WithHighlightColor(opt color.Color) EditorOption

WithHighlightColor sets the color of the select highlight over the text. It is recommended to have an Alpha component of 70.

func WithQuit

func WithQuit(opt func()) EditorOption

WithQuit sets the function to call when ^Q is pressed, nominally to quit the editor. The default is no action.

func WithRows

func WithRows(opt int) EditorOption

WithRows sets the total number of rows in the editor, including the top bar and bottom bar, if enabled. If set to < 0, then:

  • if WithHeight is set, then the maximum number of rows that would fit, based on font height, is used.
  • if WithHeight is not set, then the number of rows defaults to 25.

func WithSearchColor

func WithSearchColor(opt color.Color) EditorOption

WithSearchColor sets the color of the search highlight over the text. It is recommended to have an Alpha component of 70.

func WithTopBar

func WithTopBar(enabled bool) EditorOption

WithTopBar enables the display of the first row as a top bar.

func WithWidth

func WithWidth(opt int) EditorOption

WidthWidth sets the image width of the editor. If WithColumns is set, the font is scaled appropriately to the width. If WithColumns is not set, the maximum number of columns that would fit are used, with any additional padding to the bottom of the editor. If not set, see the 'WithColumns()' option for the calculation.

func WithWithPadding

func WithWithPadding(opt int) EditorOption

WithWidthPadding sets the left and right side padding, in pixels. If not set, the default is 1/2 of the width of the text advance of the font's rune '0'.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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