https://github.com/chengxilo/virtualterm
virtualTerm help you predict what the string looks like if you output it into a terminal.
https://github.com/chengxilo/virtualterm
ascii bash cmd control-sequ gitbash golang powershell rune runes string terminal utf-8 virtual
Last synced: 4 months ago
JSON representation
virtualTerm help you predict what the string looks like if you output it into a terminal.
- Host: GitHub
- URL: https://github.com/chengxilo/virtualterm
- Owner: chengxilo
- License: mit
- Created: 2024-09-19T02:19:12.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-14T01:06:51.000Z (7 months ago)
- Last Synced: 2025-09-18T21:43:35.526Z (5 months ago)
- Topics: ascii, bash, cmd, control-sequ, gitbash, golang, powershell, rune, runes, string, terminal, utf-8, virtual
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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 line
* `ESC[#A` moves cursor up # lines
* `ESC[#B` moves cursor down # lines
* `ESC[#C` moves cursor right # columns
* `ESC[#D` moves cursor left # columns
* `ESC[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๐ธ
you need go mod to use it. Just always use the latest version.
```shell
go get -u github.com/chengxilo/virtualterm
```
## Getting Started ๐ค
example
```go
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.
```golang
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.
```go
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...