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
590d0dcb
Commit
590d0dcb
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Module: File and OsddLast
parent
6fb520bf
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
+85
-0
85 additions, 0 deletions
Program.cs
with
85 additions
and
0 deletions
Program.cs
+
85
−
0
View file @
590d0dcb
...
...
@@ -97,6 +97,91 @@ namespace i3csstatus {
return
new
Element
[]{
new
Element
(
text
,
color
:
color
)};
}
}
[
ModuleName
(
"file"
)]
class
ModuleFile
:
Module
{
string
path
;
protected
Color
color
;
InnerStatusBar
ifNotFound
;
InnerStatusBar
ifReadError
;
public
void
Init
(
StatusBar
_bar
,
ConfigParser
config
,
ConfigSection
section
)
{
path
=
section
.
Mandatory
(
"path"
).
AsPath
();
color
=
section
.
Optional
(
"color"
)?.
AsColor
()
??
System
.
Drawing
.
ColorTranslator
.
FromHtml
(
"white"
);
ifNotFound
=
new
InnerStatusBar
(
_bar
,
section
.
Optional
(
"not_found"
)?.
AsConfig
()
??
section
.
Optional
(
"read_error"
)?.
AsConfig
()
??
new
ConfigParser
(
@"
[constant]
color = red
text = NFound
"
));
ifReadError
=
new
InnerStatusBar
(
_bar
,
section
.
Optional
(
"read_error"
)?.
AsConfig
()
??
new
ConfigParser
(
@"
[constant]
color = red
text = ERR
"
));
}
protected
virtual
IEnumerable
<
Element
>
Parse
(
string
text
)
{
if
(
text
.
Length
>
0
&&
text
[^
1
]
==
'\n'
)
text
=
text
[..^
1
];
return
text
.
Split
(
"\n"
).
Select
(
x
=>
new
Element
(
x
,
color
:
color
)).
ToArray
();
}
public
IEnumerable
<
Element
>
Get
()
{
string
text
;
try
{
text
=
File
.
ReadAllText
(
path
);
}
catch
(
Exception
ex
)
when
(
ex
is
FileNotFoundException
||
ex
is
DirectoryNotFoundException
)
{
return
ifNotFound
.
Get
();
}
catch
(
Exception
)
{
return
ifReadError
.
Get
();
}
return
Parse
(
text
);
}
}
[
ModuleName
(
"osdd_last"
)]
class
ModuleOsddLast
:
ModuleFile
{
public
new
void
Init
(
StatusBar
_bar
,
ConfigParser
config
,
ConfigSection
section
)
{
base
.
Init
(
_bar
,
config
,
section
);
}
static
string
timeShow
(
long
t_s
)
{
if
(
t_s
<
180
)
return
$"
{
t_s
}
s"
;
if
(
t_s
<
180
*
60
)
return
$"
{
t_s
/
60
}
min"
;
return
$"
{
t_s
/
60
/
60
}
h"
;
}
protected
override
IEnumerable
<
Element
>
Parse
(
string
text
)
{
try
{
var
lines
=
text
.
Split
(
"\n"
);
List
<
Element
>
output
=
new
();
long
timeEleapsed_s
=
DateTimeOffset
.
Now
.
ToUnixTimeSeconds
()-
long
.
Parse
(
lines
[
0
]);
bool
first
=
true
;
foreach
(
var
l
in
lines
[
1
..])
{
if
(
l
.
Length
>
7
)
output
.
Add
(
new
Element
((
first
?
$"[
{
timeShow
(
timeEleapsed_s
)}
] "
:
""
)
+
l
[
7
..],
color
:
System
.
Drawing
.
ColorTranslator
.
FromHtml
(
"#"
+
l
[..
6
])));
first
=
false
;
}
return
output
;
}
catch
(
Exception
)
{
return
new
Element
[]{
new
Element
(
"OSDD parse ERROR"
,
color
:
Color
.
Red
)};
}
}
}
[
ModuleName
(
"i3status"
)]
class
ModuleI3Status
:
Module
{
...
...
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