ansiterm

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Simple VT-compatible Linux Terminal Emulator

Licence Golang


中文

Introduction

go-ansiterm is a Linux terminal emulator similar to pyte, specifically designed for the Go language. While retaining the powerful features of pyte, it further adapts to the Go ecosystem.

Use Cases

In scenarios involving jump servers and other situations that require strict management of user terminal command execution, it's necessary to filter commands before they are executed by the user. In the development stack based on Golang, we haven't found any related open-source libraries. Additionally, some open-source jump server projects do not support command extraction. Therefore, this tool is mainly developed based on practical needs, to solve the problem of extracting commands executed by terminal users.

Core Features

  • Command Extraction: The core functionality lies in extracting effective information from terminal outputs and echoes, mainly focusing on user command extraction. This feature is extremely useful in jump servers for the convenient extraction and effective filtering of executed commands.

  • Screen Simulation: Includes a screen simulator capable of processing character streams on the screen, supporting operations like cursor movement and text scrolling.

  • ANSI Escape Sequences: Handling various ANSI escape sequences for enhanced terminal interactions.

How to Require

    go get github.com/veops/go-ansiterm

Usage Guide

# First, create a screen object
screen := NewScreen(80, 24)

# Create a stream object
stream := InitByteStream(screen, false)

# Connect the stream object to the screen
stream.Attach(screen

# Feed input into the stream object
stream.Feed(input)

# output
output := screen.Display()

Documentation

Index

Constants

View Source
const (
	Bell             = "bell"
	Backspace        = "backspace"
	Tab              = "tab"
	Linefeed         = "linefeed"
	CarriageReturn   = "carriage_return"
	ShiftOut         = "shift_out"
	ShiftIn          = "shift_in"
	Reset            = "reset"
	Index            = "index"
	ReverseIndex     = "reverse_index"
	SetTabStop       = "set_tab_stop"
	SaveCursor       = "save_cursor"
	RestoreCursor    = "restore_cursor"
	AlignmentDisplay = "alignment_display"
)

Variables

View Source
var (
	Basic = map[string]struct{}{
		BEL: {},
		BS:  {},
		HT:  {},
		LF:  {},
		VT:  {},
		FF:  {},
		CR:  {},
		SO:  {},
		SI:  {},
	}
	Escape = map[string]struct{}{
		RIS:   {},
		IND:   {},
		NEL:   {},
		RI:    {},
		HTS:   {},
		DECSC: {},
		DECRC: {},
	}
	Sharp = map[string]struct{}{
		DECALN: {},
	}
	Csi = map[string]struct{}{
		ICH:     {},
		CUU:     {},
		CUD:     {},
		CUF:     {},
		HPR:     {},
		CUB:     {},
		CNL:     {},
		CPL:     {},
		CHA:     {},
		HPA:     {},
		CUP:     {},
		HVP:     {},
		ED:      {},
		EL:      {},
		IL:      {},
		DL:      {},
		DCH:     {},
		ECH:     {},
		DA:      {},
		DSR:     {},
		VPA:     {},
		TBC:     {},
		SM:      {},
		RM:      {},
		SGR:     {},
		DECSTBM: {},
	}
)
View Source
var (
	DefaultMode = map[int]struct{}{
		DECCOLM: {},
		DECTCEM: {},
	}
)

Functions

This section is empty.

Types

type ByteStream

type ByteStream struct {
	*Stream
	// contains filtered or unexported fields
}

func InitByteStream

func InitByteStream(screen *Screen, strict bool) *ByteStream

func (*ByteStream) Feed

func (b *ByteStream) Feed(data []byte)

type Screen

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

func NewScreen

func NewScreen(columns int, lines int) *Screen

func (*Screen) AlignmentDisplay

func (s *Screen) AlignmentDisplay()

func (*Screen) Backspace

func (s *Screen) Backspace()

func (*Screen) Bell

func (s *Screen) Bell(args ...any)

func (*Screen) CarriageReturn

func (s *Screen) CarriageReturn()

func (*Screen) ClearTabStop

func (s *Screen) ClearTabStop(how int)

func (*Screen) CursorBack

func (s *Screen) CursorBack(count int)

func (*Screen) CursorDown

func (s *Screen) CursorDown(count int)

func (*Screen) CursorDown1

func (s *Screen) CursorDown1(count int)

func (*Screen) CursorForward

func (s *Screen) CursorForward(count int)

func (*Screen) CursorPosition

func (s *Screen) CursorPosition(line, column int)

func (*Screen) CursorToColumn

func (s *Screen) CursorToColumn(column int)

func (*Screen) CursorToLine

func (s *Screen) CursorToLine(line int)

func (*Screen) CursorUp

func (s *Screen) CursorUp(count int)

func (*Screen) CursorUp1

func (s *Screen) CursorUp1(count int)

func (*Screen) DefaultChar

func (s *Screen) DefaultChar() Char

func (*Screen) DeleteCharacters

func (s *Screen) DeleteCharacters(count int)

func (*Screen) DeleteLines

func (s *Screen) DeleteLines(count int)

func (*Screen) Display

func (s *Screen) Display() []string

func (*Screen) Draw

func (s *Screen) Draw(data string)

func (*Screen) EnsureHBounds

func (s *Screen) EnsureHBounds()

func (*Screen) EnsureVBounds

func (s *Screen) EnsureVBounds(useMargins bool)

EnsureVBounds ensures the cursor is within vertical screen bounds.

func (*Screen) EraseCharacters

func (s *Screen) EraseCharacters(count int)

func (*Screen) EraseInDisplay

func (s *Screen) EraseInDisplay(how int)

func (*Screen) EraseInLine

func (s *Screen) EraseInLine(how int, private bool)

func (*Screen) Index

func (s *Screen) Index()

func (*Screen) InsertCharacters

func (s *Screen) InsertCharacters(count int)

func (*Screen) InsertLines

func (s *Screen) InsertLines(count int)

func (*Screen) LineFeed

func (s *Screen) LineFeed()

func (*Screen) ReportDeviceAttributes

func (s *Screen) ReportDeviceAttributes(mode int, kw map[string]bool)

func (*Screen) ReportDeviceStatus

func (s *Screen) ReportDeviceStatus(mode int, kw map[string]bool)

func (*Screen) Reset

func (s *Screen) Reset()

func (*Screen) ResetMode

func (s *Screen) ResetMode(modes []int, kw map[string]any)

func (*Screen) Resize

func (s *Screen) Resize(lines, columns int)

func (*Screen) RestoreCursor

func (s *Screen) RestoreCursor()

func (*Screen) ReverseIndex

func (s *Screen) ReverseIndex()

func (*Screen) SaveCursor

func (s *Screen) SaveCursor()

func (*Screen) SelectGraphicRendition

func (s *Screen) SelectGraphicRendition(attrs ...int)

func (*Screen) SetCursorPosition

func (s *Screen) SetCursorPosition(line, column int)

func (*Screen) SetMargins

func (s *Screen) SetMargins(top, bottom int)

func (*Screen) SetMode

func (s *Screen) SetMode(modes []int, kw map[string]any)

func (*Screen) SetTabStop

func (s *Screen) SetTabStop()

func (*Screen) ShiftIn

func (s *Screen) ShiftIn()

func (*Screen) ShiftOut

func (s *Screen) ShiftOut()

func (*Screen) String

func (s *Screen) String() string

func (*Screen) Tab

func (s *Screen) Tab()

func (*Screen) WriteProcessInput

func (s *Screen) WriteProcessInput(data string)

WriteProcessInput default is a noop data text to write to the process stdin

type Stream

type Stream struct {
	Listener        *Screen
	Strict          bool
	UseUTF8         bool
	TakingPlainText bool
	Basic           map[string]struct{}
	Escape          map[string]struct{}
	Sharp           map[string]struct{}
	Csi             map[string]struct{}
	//Events          map[string]struct{} // or []string
	TextPattern *regexp.Regexp
	// contains filtered or unexported fields
}

func (*Stream) Attach

func (s *Stream) Attach(screen *Screen)

func (*Stream) Feed

func (s *Stream) Feed(data string)

func (*Stream) HandleBasic

func (s *Stream) HandleBasic(char string)

func (*Stream) HandleCSI

func (s *Stream) HandleCSI(char string, params []int, kw map[string]any)

func (*Stream) HandleEscape

func (s *Stream) HandleEscape(char string)

func (*Stream) HandleSharp

func (s *Stream) HandleSharp(char string)

func (*Stream) InitializeParser

func (s *Stream) InitializeParser()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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