duingras

package module
v0.1.71 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 2 Imported by: 0

README

duingras

a heavily simplified and cleaned-up fork of rc's go-gap-buffer, primarely for use in duin.

it removes some of the redundant functions, while adding some new stuff too, like undoing and redoing.

available functions

the current functions are currently available and good:

import (
	textbuffer "codeberg.org/kollumos/duingras"
)

tb := textbuffer.New("some text") // init a new text buffer

tb.String()     // get the contents of the buffer as one, whole string
tb.Pair()       // get the contents of the buffer as two strings, left and right of the cursor
tb.LineString() // get the contents of the current line as one, whole string

tb.Column()     // get the current column of the cursor (counting starts at 0)
tb.Line()       // get the current line of the cursor (counting starts at 1)
tb.Position()   // get the current cursor position in bytes (start of the gap)
tb.Length()     // get the length of the contents of the buffer in bytes
tb.LineLength() // get the length of the contents of the current line in bytes
tb.LineCount()  // get the amount of lines

tb.Goto(pos)   // go to specified position in the buffer (or to the end of the buffer with Goto(-1))
tb.HMove(n)    // move the cursor n characters horizontally
tb.VMove(n)    // move the cursor n characters vertically
tb.Home()      // go to the start of the current line
tb.End()       // go to the end of the current line

tb.Insert("some text")  // insert text into the buffer
tb.Delete(n)            // delete n characters forwards or backwards
deleted := tb.Delete(n) // get the deleted characters

tb.Undo() // undo the last action
tb.Redo() // redo the last undone action
planned functions

these functions will be added in sometime, probably:

tb.Anchor()  // get the selection anchor
tb.Select(n) // set the selection anchor n characters before or after the cursor (or stop selection with Select(0))

// possibly maybe also some functions for working with graphemes?

known issues

duingras is not perfect. the following issues haunt me right now:

  • tb.Goto(pos) and by extension tb.Undo() and tb.Redo() work on a byte basis, rather than a character basis. this causes these functions to mess up when there's multi-byte characters at play.
  • the code does feature some repetition in its code. i'm not sure if this is reasonably fixable, but it irks me.

license

this library is licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TextBuffer

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

func New

func New(text string) *TextBuffer

func (*TextBuffer) Column

func (tb *TextBuffer) Column() int

func (*TextBuffer) Delete

func (tb *TextBuffer) Delete(n int) string

func (*TextBuffer) End

func (tb *TextBuffer) End()

func (*TextBuffer) Goto

func (tb *TextBuffer) Goto(pos int)

func (*TextBuffer) HMove added in v0.1.3

func (tb *TextBuffer) HMove(n int)

func (*TextBuffer) Home

func (tb *TextBuffer) Home()

func (*TextBuffer) Insert

func (tb *TextBuffer) Insert(text string)

func (*TextBuffer) Length

func (tb *TextBuffer) Length() int

func (*TextBuffer) Line

func (tb *TextBuffer) Line() int

func (*TextBuffer) LineCount added in v0.1.3

func (tb *TextBuffer) LineCount() int

func (*TextBuffer) LineLength

func (tb *TextBuffer) LineLength() int

func (*TextBuffer) LineString added in v0.1.1

func (tb *TextBuffer) LineString() string

func (*TextBuffer) Pair

func (tb *TextBuffer) Pair() (left string, right string)

func (*TextBuffer) Position added in v0.1.6

func (tb *TextBuffer) Position() int

func (*TextBuffer) Redo added in v0.1.6

func (tb *TextBuffer) Redo()

func (*TextBuffer) String

func (tb *TextBuffer) String() string

func (*TextBuffer) Undo added in v0.1.6

func (tb *TextBuffer) Undo()

func (*TextBuffer) VMove added in v0.1.3

func (tb *TextBuffer) VMove(n int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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