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
f32ab316
Commit
f32ab316
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Module: i3status
parent
47d5fe49
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Program.cs
+71
-0
71 additions, 0 deletions
Program.cs
with
71 additions
and
0 deletions
Program.cs
+
71
−
0
View file @
f32ab316
...
@@ -131,6 +131,77 @@ namespace i3csstatus {
...
@@ -131,6 +131,77 @@ namespace i3csstatus {
return
new
Element
[]{
new
Element
(
text
,
color
:
color
)};
return
new
Element
[]{
new
Element
(
text
,
color
:
color
)};
}
}
}
}
[
ModuleName
(
"i3status"
)]
class
ModuleI3Status
:
Module
{
string
name
;
string
configuration
;
Element
[]
elements
;
class
Global
:
GlobalModuleResource
{
public
List
<
ModuleI3Status
>
modules
=
new
();
System
.
Diagnostics
.
Process
process
;
public
override
void
InitEnd
()
{
process
=
new
();
//process.StartInfo.FileName = "tail";
//process.StartInfo.Arguments = "-n 5";
process
.
StartInfo
.
FileName
=
"i3status"
;
process
.
StartInfo
.
Arguments
=
"-c /dev/stdin"
;
process
.
StartInfo
.
RedirectStandardInput
=
true
;
process
.
StartInfo
.
RedirectStandardOutput
=
true
;
process
.
Start
();
TextWriter
stdin
=
process
.
StandardInput
;
//stdin = Console.Out;
var
stdout
=
process
.
StandardOutput
;
stdin
.
WriteLine
(
"general {"
);
stdin
.
WriteLine
(
"output_format = \"i3bar\""
);
stdin
.
WriteLine
(
"colors = true"
);
stdin
.
WriteLine
(
"interval = 1000000000"
);
stdin
.
WriteLine
(
"}"
);
foreach
(
var
m
in
modules
)
{
stdin
.
WriteLine
(
$"order += \"
{
m
.
name
}
\""
);
stdin
.
WriteLine
(
$"
{
m
.
name
}
{{
");
if
(
m
.
configuration
!=
null
)
stdin
.
WriteLine
(
m
.
configuration
);
stdin
.
WriteLine
(
$"}}"
);
}
stdin
.
Close
();
stdout
.
ReadLine
();
stdout
.
ReadLine
();
stdout
.
ReadLine
();
}
static
Element
parseElement
(
JsonObject
json
)
{
return
new
Element
(
text
:
json
[
"full_text"
].
AsValue
().
GetValue
<
string
>(),
short_text
:
json
[
"short_text"
]?.
AsValue
()?.
GetValue
<
string
>(),
color
:
System
.
Drawing
.
ColorTranslator
.
FromHtml
(
json
[
"color"
]?.
AsValue
()?.
GetValue
<
string
>()
??
"white"
)
);
}
public
override
void
GetBegin
()
{
process
.
KillBySignal
(
10
);
string
str
=
process
.
StandardOutput
.
ReadLine
()[
1
..];
Console
.
WriteLine
(
str
);
JsonArray
json
=
JsonObject
.
Parse
(
str
).
AsArray
();
if
(
json
.
Count
!=
modules
.
Count
)
throw
new
Exception
(
"Parse i3status error"
);
for
(
int
i
=
0
;
i
<
modules
.
Count
;
i
++)
{
modules
[
i
].
elements
=
new
[]{
parseElement
(
json
[
i
].
AsObject
())};
}
}
}
public
void
Init
(
StatusBar
_bar
,
ConfigParser
config
,
ConfigSection
section
)
{
name
=
section
.
GetMandatory
(
"name"
);
configuration
=
config
.
GetValue
(
section
.
SectionName
,
"config"
);
_bar
.
GetGlobal
<
Global
>().
modules
.
Add
(
this
);
}
public
IEnumerable
<
Element
>
Get
()
=>
elements
??
new
Element
[]{};
}
#
nullable
restore
#
nullable
restore
abstract
class
StatusBar
abstract
class
StatusBar
{
{
...
...
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