tcellansi

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 5 Imported by: 1

README

tcellansi

Go Reference

tcellansi is a package for converting tcell styles to ANSI escape sequences.

Version Compatibility

  • For tcell v3, use the latest main branch of this repository.
  • For tcell v2, use the v0.3.1 tag:
  go get github.com/noborus/[email protected]

Installation

To install the package, run:

go get github.com/noborus/tcellansi

Usage

Here is a simple example of how to use tcellansi:

package main

import (
	"github.com/gdamore/tcell/v3"
	"github.com/noborus/tcellansi"
)

func main() {
	// Initialize tcell screen
	screen, _ := tcell.NewScreen()
	screen.Init()

	// Create a style
	style := tcell.StyleDefault.Foreground(tcell.ColorRed).Background(tcell.ColorBlack)

	// Convert the style to ANSI escape sequence
	ansiSeq := tcellansi.ToAnsi(style)
	screen.Fini()

	println(ansiSeq + "Hello world!")
}

License

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScreenContentToStrings

func ScreenContentToStrings(screen tcell.Screen, x1 int, x2 int, y1 int, y2 int) []string

ScreenContentToStrings converts the screen content to a slice of strings. It reads the screen content from the specified range (x1, x2, y1, y2) and converts it to a slice of strings. Each string in the slice represents a row of the screen content.

Parameters:

  • screen: tcell.Screen to be converted.
  • x1: int, the starting column of the range.
  • x2: int, the ending column of the range.
  • y1: int, the starting row of the range.
  • y2: int, the ending row of the range.

Returns:

  • A slice of strings representing the screen content in the specified range.

func ToAnsi

func ToAnsi(style tcell.Style) string

ToAnsi converts the tcell style to an ANSI escape sequence. It handles foreground color, background color, and various text attributes such as bold, italic, underline, etc. The function supports both palette colors and RGB colors for foreground and background.

Parameters:

  • style: tcell.Style to be converted.

Returns:

  • A string containing the ANSI escape sequence representing the given style.

func TrimRightSpaces

func TrimRightSpaces(lines []string) []string

TrimRightSpaces trims trailing spaces from each line of the given screen content strings. ANSI escape sequences are preserved. TrimRightSpaces removes trailing spaces from each line in the given slice of strings. If a line ends with a newline character, it trims spaces before the newline. If the line ends with a specific reset style sequence before the newline, the original lines are returned unmodified. The function preserves the newline character at the end of each line.

Types

This section is empty.

Jump to

Keyboard shortcuts

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