Skip to content

Commit ab4a2b7

Browse files
committed
feat: Improve documentation
1 parent 1122348 commit ab4a2b7

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# asciinema parser
22

3+
[中文文档](./README.md)
4+
[English Document](./README_en.md)
5+
36
# 一、这是什么?解决了什么问题?
47

58
这个网站[https://asciinema.org/](https://asciinema.org/)是一个命令行录屏分享网站,它定义了一套`Ascii Cast`格式的文件来存储录屏内容,这个库就是用来解析`Ascii Cast`文件的,支持[v1](https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v1.md)[v2](https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v2.md)两个版本。

README_en.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# asciinema parser
2+
3+
[中文文档](./README.md)
4+
[English Document](./README_en.md)
5+
6+
# 1. What is this? What problem was solved?
7+
8+
This website [https://asciinema.org/](https://asciinema.org/) Is a command line screen sharing website, it defines a set of Ascii Cast format files to store screen content, this library is used to parse Ascii Cast files,support [v1](https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v1.md) and [v2](https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v2.md) two versions.
9+
10+
# 2. API code examples
11+
12+
## 2.1 Check the version of the screen recording file
13+
14+
```go
15+
package main
16+
17+
import (
18+
"context"
19+
"fmt"
20+
asciinema_parser "github.com/golang-infrastructure/go-asciinema-parser"
21+
)
22+
23+
func main() {
24+
25+
asciiCastV2String := `{"version": 2, "width": 80, "height": 24, "timestamp": 1504467315, "title": "Demo", "env": {"TERM": "xterm-256color", "SHELL": "/bin/zsh"}}
26+
[0.248848, "o", "\u001b[1;31mHello \u001b[32mWorld!\u001b[0m\n"]
27+
[1.001376, "o", "That was ok\rThis is better."]
28+
[2.143733, "o", " "]
29+
[6.541828, "o", "Bye!"]`
30+
31+
version, err := asciinema_parser.DetectVersion(context.Background(), asciiCastV2String)
32+
if err != nil {
33+
panic(err)
34+
}
35+
fmt.Println(version) // Output: 2
36+
37+
}
38+
```
39+
40+
## 2.2 Parse V1 format of the screen recording software
41+
42+
```go
43+
package main
44+
45+
import (
46+
"context"
47+
"fmt"
48+
asciinema_parser "github.com/golang-infrastructure/go-asciinema-parser"
49+
)
50+
51+
func main() {
52+
53+
asciiCastV1String := `{
54+
"version": 1,
55+
"width": 80,
56+
"height": 24,
57+
"duration": 1.515658,
58+
"command": "/bin/zsh",
59+
"title": "",
60+
"env": {
61+
"TERM": "xterm-256color",
62+
"SHELL": "/bin/zsh"
63+
},
64+
"stdout": [
65+
[
66+
0.248848,
67+
"\u001b[1;31mHello \u001b[32mWorld!\u001b[0m\n"
68+
],
69+
[
70+
1.001376,
71+
"I am \rThis is on the next line."
72+
]
73+
]
74+
}`
75+
76+
v1, err := asciinema_parser.ParseV1(context.Background(), []byte(asciiCastV1String))
77+
if err != nil {
78+
panic(err)
79+
}
80+
fmt.Println(fmt.Sprintf("%v", v1))
81+
82+
}
83+
```
84+
85+
## 2.3 Parse V2 format of the screen recording software
86+
87+
```go
88+
package main
89+
90+
import (
91+
"context"
92+
"fmt"
93+
asciinema_parser "github.com/golang-infrastructure/go-asciinema-parser"
94+
)
95+
96+
func main() {
97+
98+
asciiCastV2String := `{"version": 2, "width": 80, "height": 24, "timestamp": 1504467315, "title": "Demo", "env": {"TERM": "xterm-256color", "SHELL": "/bin/zsh"}}
99+
[0.248848, "o", "\u001b[1;31mHello \u001b[32mWorld!\u001b[0m\n"]
100+
[1.001376, "o", "That was ok\rThis is better."]
101+
[2.143733, "o", " "]
102+
[6.541828, "o", "Bye!"]`
103+
104+
v2, err := asciinema_parser.ParseV2(context.Background(), []byte(asciiCastV2String))
105+
if err != nil {
106+
panic(err)
107+
}
108+
fmt.Println(fmt.Sprintf("%v", v2))
109+
110+
}
111+
```
112+
113+
114+

0 commit comments

Comments
 (0)