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
5e89ced8
Commit
5e89ced8
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Module: Pipe
parent
c7153d34
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
+93
-1
93 additions, 1 deletion
Program.cs
with
93 additions
and
1 deletion
Program.cs
+
93
−
1
View file @
5e89ced8
...
...
@@ -155,8 +155,100 @@ text = ERR
return
Parse
(
text
);
}
}
[
ModuleName
(
"pipe"
)]
class
ModulePipe
:
Module
{
StatusBar
bar
;
string
path
;
string
text
;
protected
Color
color
;
InnerStatusBar
ifNoData
;
InnerStatusBar
ifReadError
;
Thread
inputThread
;
int
msgSeparator
;
int
scheudleIn_ms
;
bool
pipeError
=
false
;
public
void
Init
(
StatusBar
_bar
,
ConfigParser
config
,
ConfigSection
section
)
{
bar
=
_bar
;
path
=
section
.
Mandatory
(
"path"
).
AsPath
();
color
=
section
.
Optional
(
"color"
)?.
AsColor
()
??
System
.
Drawing
.
ColorTranslator
.
FromHtml
(
"white"
);
ifNoData
=
new
InnerStatusBar
(
_bar
,
section
.
Optional
(
"no_data"
)?.
AsConfig
()
??
new
ConfigParser
(
@"
"
));
ifReadError
=
new
InnerStatusBar
(
_bar
,
section
.
Optional
(
"read_error"
)?.
AsConfig
()
??
new
ConfigParser
(
@"
[constant]
color = red
text = ERR
"
));
msgSeparator
=
section
.
Optional
(
"separator"
)?.
AsInt
()
??
0
;
scheudleIn_ms
=
section
.
Optional
(
"delay"
)?.
AsMs
()
??
10
;
inputThread
=
new
Thread
(
this
.
inputThreadFunc
);
inputThread
.
IsBackground
=
true
;
inputThread
.
Start
();
}
void
inputThreadFunc
()
{
while
(
true
)
{
int
r
=
POSIX
.
mkfifo
(
path
,
(
7
<<
6
)+(
7
<<
3
)+
7
);
int
err
=
POSIX
.
ERRNO
;
Console
.
WriteLine
(
$"
{
r
}
{
err
}
"
);
if
(
r
==
0
)
break
;
if
(
r
!=
0
&&
err
==
POSIX
.
EEXIST
)
{
File
.
Delete
(
path
);
continue
;
}
pipeError
=
true
;
throw
new
Exception
(
$"POSIX.mkfifo fail with ERRNO
{
err
}
"
);
}
var
sr
=
new
StreamReader
(
path
);
var
sw
=
new
StreamWriter
(
path
);
// Only for keeping pipe alive
StringBuilder
s
=
new
();
while
(
true
)
{
int
c
=
sr
.
Read
();
if
(
c
==
msgSeparator
)
{
lock
(
this
)
{
text
=
s
.
ToString
();
s
=
new
StringBuilder
();
}
bar
.
Schedule
(
scheudleIn_ms
);
}
else
{
s
.
Append
((
char
)
c
);
}
}
}
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
;
lock
(
this
)
{
_text
=
text
;
}
if
(
pipeError
)
return
ifReadError
.
Get
();
if
(
_text
==
null
)
return
ifNoData
.
Get
();
return
Parse
(
_text
);
}
}
[
ModuleName
(
"osdd_last"
)]
class
ModuleOsddLast
:
Module
Fil
e
class
ModuleOsddLast
:
Module
Pip
e
{
public
new
void
Init
(
StatusBar
_bar
,
ConfigParser
config
,
ConfigSection
section
)
{
...
...
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