Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
I3csstatus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
I3csstatus
Commits
614f5697
Commit
614f5697
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Support whole protocol
parent
0c9c5a19
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Parsers.cs
+31
-1
31 additions, 1 deletion
Parsers.cs
Program.cs
+50
-2
50 additions, 2 deletions
Program.cs
with
81 additions
and
3 deletions
Parsers.cs
+
31
−
1
View file @
614f5697
...
...
@@ -205,10 +205,40 @@ class ParserI3: Parser
static
Element
parseElement
(
JsonNode
_json
)
{
var
json
=
_json
.
AsObject
();
var
align
=
Align
.
Left
;
if
(
json
[
"align"
]?.
GetValue
<
string
>()
==
"right"
)
align
=
Align
.
Right
;
if
(
json
[
"align"
]?.
GetValue
<
string
>()
==
"center"
)
align
=
Align
.
Center
;
var
markup
=
Markup
.
None
;
if
(
json
[
"markup"
]?.
GetValue
<
string
>()
==
"pango"
)
markup
=
Markup
.
Pango
;
string
minWidth_string
=
null
;
int
?
minWidth_int
=
null
;
try
{
minWidth_string
=
json
[
"min_width"
]?.
AsValue
()?.
GetValue
<
string
>();
}
catch
(
Exception
)
{}
try
{
minWidth_int
=
json
[
"min_width"
]?.
AsValue
()?.
GetValue
<
int
>();
}
catch
(
Exception
)
{}
return
new
Element
(
Text
:
json
[
"full_text"
].
AsValue
().
GetValue
<
string
>(),
ShortText
:
json
[
"short_text"
]?.
AsValue
()?.
GetValue
<
string
>(),
Color
:
System
.
Drawing
.
ColorTranslator
.
FromHtml
(
json
[
"color"
]?.
AsValue
()?.
GetValue
<
string
>()
??
"white"
)
Color
:
json
[
"color"
]?.
AsValue
()?.
GetValue
<
string
>()?.
ToColor
(),
BackgroundColor
:
json
[
"background"
]?.
AsValue
()?.
GetValue
<
string
>()?.
ToColor
(),
BorderColor
:
json
[
"border"
]?.
AsValue
()?.
GetValue
<
string
>()?.
ToColor
(),
BorderTop
:
json
[
"border_top"
]?.
AsValue
()?.
GetValue
<
int
>(),
BorderRight
:
json
[
"border_right"
]?.
AsValue
()?.
GetValue
<
int
>(),
BorderBottom
:
json
[
"border_bottom"
]?.
AsValue
()?.
GetValue
<
int
>(),
BorderLeft
:
json
[
"border_left"
]?.
AsValue
()?.
GetValue
<
int
>(),
MinWidth_string
:
minWidth_string
,
MinWidth_int
:
minWidth_int
,
Align
:
align
,
Urgent
:
json
[
"urgent"
]?.
AsValue
().
GetValue
<
bool
>()
??
false
,
Separator
:
json
[
"separator"
]?.
AsValue
().
GetValue
<
bool
>()
??
true
,
SeparatorBlockWidth
:
json
[
"separator_block_width"
]?.
AsValue
()?.
GetValue
<
int
>(),
Markup
:
markup
);
}
public
IEnumerable
<
Element
>
Parse
(
string
data
)
...
...
This diff is collapsed.
Click to expand it.
Program.cs
+
50
−
2
View file @
614f5697
...
...
@@ -56,19 +56,48 @@ static class JsonExtended
}
}
static
class
Color
ToHex
Extended
static
class
ColorExtended
{
static
public
string
ToHex
(
this
Color
c
)
{
return
$"#
{
c
.
R
:
X2
}{
c
.
G
:
X2
}{
c
.
B
:
X2
}
"
;
}
static
public
Color
ToColor
(
this
string
s
)
{
return
System
.
Drawing
.
ColorTranslator
.
FromHtml
(
s
);
}
}
enum
Align
{
Left
,
Right
,
Center
}
enum
Markup
{
None
,
Pango
}
record
Element
(
string
Text
,
string
?
ShortText
=
null
,
Color
?
Color
=
null
Color
?
Color
=
null
,
Color
?
BackgroundColor
=
null
,
Color
?
BorderColor
=
null
,
int
?
BorderTop
=
null
,
int
?
BorderRight
=
null
,
int
?
BorderBottom
=
null
,
int
?
BorderLeft
=
null
,
string
?
MinWidth_string
=
null
,
int
?
MinWidth_int
=
null
,
Align
Align
=
Align
.
Left
,
bool
Urgent
=
false
,
bool
Separator
=
true
,
int
?
SeparatorBlockWidth
=
null
,
Markup
Markup
=
Markup
.
None
);
...
...
@@ -277,10 +306,29 @@ class StatusBarI3: RootStatusBar
}
override
protected
void
format
(
TextWriter
w
,
List
<
Element
>
elements
)
{
JsonNode
?
intStringUnion
(
int
?
_int
,
string
?
_string
)
{
JsonNode
?
n
=
null
;
if
(
_int
!=
null
)
n
=
_int
;
if
(
_string
!=
null
)
n
=
_string
;
return
n
;
}
var
json
=
new
JsonArray
((
from
e
in
elements
select
new
JsonObject
(){
[
"full_text"
]
=
e
.
Text
,
[
"short_text"
]
=
e
.
ShortText
,
[
"color"
]
=
e
.
Color
?.
ToHex
(),
[
"background"
]
=
e
.
BackgroundColor
?.
ToHex
(),
[
"border"
]
=
e
.
BorderColor
?.
ToHex
(),
[
"border_top"
]
=
e
.
BorderTop
,
[
"border_right"
]
=
e
.
BorderTop
,
[
"border_bottom"
]
=
e
.
BorderTop
,
[
"border_left"
]
=
e
.
BorderTop
,
[
"min_width"
]
=
intStringUnion
(
e
.
MinWidth_int
,
e
.
MinWidth_string
),
[
"align"
]
=
e
.
Align
==
Align
.
Right
?
"right"
:
e
.
Align
==
Align
.
Center
?
"center"
:
null
,
[
"urgent"
]
=
e
.
Urgent
?
true
:
null
,
[
"separator"
]
=
e
.
Separator
?
null
:
false
,
[
"separator_block_width"
]
=
e
.
SeparatorBlockWidth
,
[
"markup"
]
=
e
.
Markup
==
Markup
.
Pango
?
"pango"
:
null
}.
RemoveNull
()).
ToArray
());
var
opt
=
new
JsonSerializerOptions
();
opt
.
DefaultIgnoreCondition
=
System
.
Text
.
Json
.
Serialization
.
JsonIgnoreCondition
.
WhenWritingNull
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment