textsel

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: MIT Imports: 6 Imported by: 1

README

TextSel

Go Reference

textsel is a Go package that extends the tview.TextView widget to include cursor movement and text selection capabilities. It allows users to navigate and select text within the TextView, making it easier to copy and highlight text.

Features

  • Cursor movement (up, down, left, right).
  • Text selection with visual highlighting.
  • Customizable colors for cursor and selection.

Installation

To install textsel, you need to have Go installed and set up on your machine. Use the following command to install the package:

go get github.com/sysread/textsel

Usage

Here's an example of how to use textsel in your project:

package main

import (
    "github.com/sysread/textsel"
    "github.com/rivo/tview"
)

func main() {
    app := tview.NewApplication()

    textSel := textsel.NewTextSel().SetText("Hello, World!")

    if err := app.SetRoot(textSel, true).Run(); err != nil {
        panic(err)
    }
}

Customization

You can customize the colors used for cursor and selection highlighting by modifying the defaultColor, cursorColor, selectionColor, and cursorInSelectionColor fields in the TextSel struct.

Example:

textSel := textsel.NewTextSel()
textSel.defaultColor = "[#FFFFFF:#000000:-]"
textSel.cursorColor = "[#000000:#FFFFFF:-]"
textSel.selectionColor = "[#000000:#FF0000:-]"
textSel.cursorInSelectionColor = "[#000000:#FF0000:bu]"

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request with your improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Overview

Package textsel provides a `tview.TextView` widget that supports selecting text with the keyboard.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TextSel

type TextSel struct {
	*tview.TextView
	// contains filtered or unexported fields
}

TextSel is a `tview.TextView` widget that supports selecting text with the keyboard.

func NewTextSel

func NewTextSel() *TextSel

NewTextSel creates and returns a new TextSel instance.

Example:

textSel := textsel.NewTextSel().SetText("Hello, World!")

func (*TextSel) FinishSelection added in v0.1.6

func (ts *TextSel) FinishSelection() *TextSel

Finishes the selection process and calls the selectFunc callback.

func (*TextSel) GetCursorPosition added in v0.1.6

func (ts *TextSel) GetCursorPosition() (int, int)

Returns the current cursor position as row and column.

func (*TextSel) GetSelectedText

func (ts *TextSel) GetSelectedText() string

GetSelectedText returns the currently selected text. If no text is selected, an empty string is returned.

Example:

selectedText := textSel.GetSelectedText()
fmt.Println("Selected text:", selectedText)

func (*TextSel) GetSelectionRange added in v0.1.6

func (ts *TextSel) GetSelectionRange() (int, int, int, int)

GetSelectionRange returns the start and end row and column of the current selection. Note that if the selection range is backwards (e.g. the selection began at (1, 5) and ends at (0, 0)), the values will be swapped so that the first point always preceeds the second.

func (*TextSel) GetText added in v0.1.3

func (ts *TextSel) GetText(stripFormatting bool) string

GetText returns the text content of the TextSel widget. If `stripFormatting` is true, any format codes in the text will be removed.

Example:

text := textSel.GetText(false)

func (*TextSel) MoveDown added in v0.1.6

func (ts *TextSel) MoveDown() *TextSel

Moves the cursor down by one row.

func (*TextSel) MoveLeft added in v0.1.6

func (ts *TextSel) MoveLeft() *TextSel

Moves the cursor left by one column, wrapping to the previous row if necessary.

func (*TextSel) MoveRight added in v0.1.6

func (ts *TextSel) MoveRight() *TextSel

Moves the cursor right by one column, wrapping to the next row if necessary.

func (*TextSel) MoveToEndOfLine added in v0.1.6

func (ts *TextSel) MoveToEndOfLine() *TextSel

Moves the cursor to the end of the current line.

func (*TextSel) MoveToFirstLine added in v0.1.7

func (ts *TextSel) MoveToFirstLine() *TextSel

Moves the cursor to the first line of the text. The current column is preserved if it is within the bounds of the first line. Otherwise, the cursor is placed at the end of the first line.

func (*TextSel) MoveToLastLine added in v0.1.7

func (ts *TextSel) MoveToLastLine() *TextSel

Moves the cursor to the last line of the text. The current column is preserved if it is within the bounds of the last line. Otherwise, the cursor is placed at the end of the last line.

func (*TextSel) MoveToStartOfLine added in v0.1.6

func (ts *TextSel) MoveToStartOfLine() *TextSel

Moves the cursor to the start of the current line.

func (*TextSel) MoveUp added in v0.1.6

func (ts *TextSel) MoveUp() *TextSel

Moves the cursor up by one row.

func (*TextSel) ResetCursor added in v0.1.6

func (ts *TextSel) ResetCursor() *TextSel

Resets the cursor position to the beginning of the text.

func (*TextSel) ResetSelection added in v0.1.6

func (ts *TextSel) ResetSelection() *TextSel

Resets the selection state.

func (*TextSel) SetCursorPosition added in v0.1.6

func (ts *TextSel) SetCursorPosition(row int, col int) *TextSel

func (*TextSel) SetSelectFunc

func (ts *TextSel) SetSelectFunc(f func(string)) *TextSel

SetSelectFunc sets the callback function that will be called when text is selected.

Example:

textSel.SetSelectFunc(func(selectedText string) {
	fmt.Println("Selected text:\n\n", selectedText)
})

func (*TextSel) SetText

func (ts *TextSel) SetText(text string) *TextSel

SetText sets the text content of the TextSel widget, resetting the cursor position and selection state.

Example:

textSel.SetText("New text content")

func (*TextSel) StartSelection added in v0.1.6

func (ts *TextSel) StartSelection() *TextSel

Starts the selection process at the current position in the document.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳