1
1
defmodule Asciinema.Streaming.Parser.Alis do
2
- alias Asciinema.Colors
3
-
4
2
@ behaviour Asciinema.Streaming.Parser
5
3
6
- @ theme_absent 0x00
7
- @ theme_present 0x01
8
-
9
4
def init , do: % { status: :new }
10
5
11
6
def parse ( { :binary , "ALiS\x01 " } , % { status: :new } = state ) do
@@ -24,38 +19,36 @@ defmodule Asciinema.Streaming.Parser.Alis do
24
19
cols :: little - 16 ,
25
20
rows :: little - 16 ,
26
21
time :: little - float - 32 ,
27
- @ theme_absent :: 8 ,
28
- init_len :: little - 32 ,
29
- init :: binary - size ( init_len )
22
+ palette_len :: 8 ,
23
+ rest :: binary
30
24
>>
31
25
} ,
32
26
% { status: status } = state
33
27
)
34
28
when status in [ :init , :offline ] do
35
- { :ok , [ reset: % { size: { cols , rows } , init: init , time: time } ] , % { state | status: :online } }
36
- end
29
+ palette_len =
30
+ case palette_len do
31
+ 0 -> 0
32
+ # TODO: legacy, used by RC CLIs, remove after release of final CLI 3.0
33
+ 1 -> 16
34
+ 8 -> 8
35
+ 16 -> 16
36
+ end
37
37
38
- def parse (
39
- {
40
- :binary ,
41
- <<
42
- 0x01 ,
43
- cols :: little - 16 ,
44
- rows :: little - 16 ,
45
- time :: little - float - 32 ,
46
- @ theme_present :: 8 ,
47
- theme :: binary - size ( 18 * 3 ) ,
48
- init_len :: little - 32 ,
49
- init :: binary - size ( init_len )
50
- >>
51
- } ,
52
- % { status: status } = state
53
- )
54
- when status in [ :init , :offline ] do
38
+ theme_len = ( 2 + palette_len ) * 3
39
+ << theme :: binary - size ( theme_len ) , init_len :: little - 32 , init :: binary - size ( init_len ) >> = rest
55
40
theme = parse_theme ( theme )
56
41
57
- { :ok , [ reset: % { size: { cols , rows } , init: init , time: time , theme: theme } ] ,
58
- % { state | status: :online } }
42
+ commands = [
43
+ reset: % {
44
+ size: { cols , rows } ,
45
+ init: init ,
46
+ time: time ,
47
+ theme: theme
48
+ }
49
+ ]
50
+
51
+ { :ok , commands , % { state | status: :online } }
59
52
end
60
53
61
54
def parse (
@@ -97,7 +90,7 @@ defmodule Asciinema.Streaming.Parser.Alis do
97
90
end
98
91
99
92
defp parse_theme ( theme ) do
100
- colors = for << r :: 8 , g :: 8 , b :: 8 <- theme >> , do: Colors . hex ( r , g , b )
93
+ colors = for << r :: 8 , g :: 8 , b :: 8 <- theme >> , do: { r , g , b }
101
94
102
95
% {
103
96
fg: Enum . at ( colors , 0 ) ,
0 commit comments