# README
virtual-term
VirtualTerm is created to simulate a terminal,handle the special character such as '\r','\b'. Write a string into VirtualTerm, you will know what would your string be like if you output it to stdout.
Now Support 😎
Character Encoding
- ASCII
- UTF-8
Control Characters
\b
backspace\r
carriage return\n
feed lineESC[#A
moves cursor up # linesESC[#B
moves cursor down # linesESC[#C
moves cursor right # columnsESC[#D
moves cursor left # columnsESC[H
moves cursor to home position
WARNING: if you try to write not supported ESC to it, the output may can not be predicted
install🛸
use go get to
go get -u github.com/chengxilo/virtualterm
Getting Started 🤔
example
package main
import (
"fmt"
"github.com/chengxilo/virtualterm"
"log"
)
func main() {
str := "hello\rvirtuaa\bl-terminal"
vt := virtualterm.NewDefault()
vt.Write([]byte(str))
fmt.Println(str == "virtual-terminal")
str,err := vt.String()
if err != nil {
log.Fatal(err)
}
fmt.Println(str == "virtual-terminal")
// Output:
// false
// true
}
Use virtualterm.Process
function. You will not need to create a virtual terminal and input on your own.
package main
import (
"fmt"
"github.com/chengxilo/virtualterm"
)
func main() {
str := "hello\rvirtuaa\bl-terminal"
newS,_ := virtualterm.Process(str)
fmt.Println(str == "virtual-terminal")
fmt.Println(newS == "virtual-terminal")
// Output:
// false
// true
}
go test. This is why I want to create this repository. If you don't use this,just use the str, all of them will fail.
package test
import (
"fmt"
"github.com/chengxilo/virtualterm"
"github.com/stretchr/testify/assert"
"testing"
)
func TestVirtualTerm(t *testing.T) {
str := "hello\rvirtuaa\bl-terminal"
ns,_ := virtualterm.Process(str)
assert.Equal(t, ns, "virtual-terminal")
}
func ExampleVirtualTerm() {
str := "hello\rvirtuaa\bl-terminal"
ns,_ := virtualterm.Process(str)
fmt.Print(ns)
// Output:
// virtual-terminal
}
Contribution 🎉
Pull requests are welcome. Feel free to...
- Revise documentation
- Add new features
- Fix bugs
- Suggest improvements
- or whatever you want...
# Functions
NewDefault create a default virtual terminal.
NewOptions create a virtual terminal.
OptionSilence set whether the vt is silence or not.
Process get the output directly without explicitly create a virtual terminal.
# Variables
No description provided by the author
ErrNonDeterministic is created for some situation that cannot be handled well.
# Structs
VirtualTerm this is created to simulate a terminal,handle the special character such as '\r','\b', "\033[1D".
# Type aliases
No description provided by the author