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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
I3csstatus
Commits
d35caa63
Commit
d35caa63
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Exception reform
parent
98158b32
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ConfigParser.cs
+4
-2
4 additions, 2 deletions
ConfigParser.cs
Module.cs
+1
-8
1 addition, 8 deletions
Module.cs
Program.cs
+49
-6
49 additions, 6 deletions
Program.cs
with
54 additions
and
16 deletions
ConfigParser.cs
+
4
−
2
View file @
d35caa63
...
@@ -34,11 +34,13 @@ abstract class ConfigException: Exception
...
@@ -34,11 +34,13 @@ abstract class ConfigException: Exception
{
{
Parser
=
parser
;
Parser
=
parser
;
}
}
public
override
string
ToString
()
public
override
string
Message
{
{
r
et
urn
$"Mistake in config:
{
ErrorString
()}
"
;
g
et
=>
$"Mistake in config:
{
ErrorString
WithFile
()}
"
;
}
}
abstract
public
string
ErrorString
();
abstract
public
string
ErrorString
();
public
string
ErrorStringWithFile
()
=>
Parser
.
FileName
==
null
?
ErrorString
()
:
$"
{
Parser
.
FileName
}
:
{
ErrorString
()}
"
;
}
}
abstract
class
ConfigDuplicitException
:
ConfigException
abstract
class
ConfigDuplicitException
:
ConfigException
{
{
...
...
This diff is collapsed.
Click to expand it.
Module.cs
+
1
−
8
View file @
d35caa63
...
@@ -421,13 +421,6 @@ text = ERR
...
@@ -421,13 +421,6 @@ text = ERR
[
ModuleName
(
"i3status"
)]
[
ModuleName
(
"i3status"
)]
class
ModuleI3Status
:
Module
class
ModuleI3Status
:
Module
{
{
class
ModuleI3StatusException
:
ModuleException
{
public
override
string
ToString
()
{
return
$"I3Status don't work correctly."
;
}
}
string
name
;
string
name
;
string
configuration
;
string
configuration
;
Block
[]
elements
;
Block
[]
elements
;
...
@@ -480,7 +473,7 @@ class ModuleI3Status: Module
...
@@ -480,7 +473,7 @@ class ModuleI3Status: Module
string
line
=
process
.
StandardOutput
.
ReadLine
();
string
line
=
process
.
StandardOutput
.
ReadLine
();
if
(
line
==
null
)
if
(
line
==
null
)
{
{
throw
new
ModuleI3StatusException
(
);
throw
new
PrintAndExit
(
"I3Status don't work correctly."
);
}
}
Block
[]
data
=
(
Block
[])
parser
.
Parse
(
line
[
1
..]);
Block
[]
data
=
(
Block
[])
parser
.
Parse
(
line
[
1
..]);
if
(
data
.
Length
!=
modules
.
Count
)
if
(
data
.
Length
!=
modules
.
Count
)
...
...
This diff is collapsed.
Click to expand it.
Program.cs
+
49
−
6
View file @
d35caa63
...
@@ -38,6 +38,19 @@ using Config;
...
@@ -38,6 +38,19 @@ using Config;
namespace
i3csstatus
;
namespace
i3csstatus
;
class
PrintAndExit
:
Exception
{
public
string
ToPrint
;
public
int
ExitCode
;
public
PrintAndExit
(
string
_ToPrint
,
int
_ExitCode
=
1
)
{
ToPrint
=
_ToPrint
;
ExitCode
=
_ExitCode
;
}
public
override
string
Message
{
get
=>
$"Print \"
{
ToPrint
}
\" and exit with exit code
{
ExitCode
}
"
;
}
}
static
class
POSIX
static
class
POSIX
{
{
[
DllImport
(
"libc"
,
SetLastError
=
true
)]
[
DllImport
(
"libc"
,
SetLastError
=
true
)]
...
@@ -228,9 +241,16 @@ refresh
...
@@ -228,9 +241,16 @@ refresh
parseConfigString
(
File
.
ReadAllText
(
configFile
.
ToString
()),
configFile
.
ToString
());
parseConfigString
(
File
.
ReadAllText
(
configFile
.
ToString
()),
configFile
.
ToString
());
}
}
protected
void
parseConfigString
(
string
configString
,
string
?
fileName
)
protected
void
parseConfigString
(
string
configString
,
string
?
fileName
)
{
try
{
{
parseConfig
(
new
ConfigParser
(
configString
,
fileName
));
parseConfig
(
new
ConfigParser
(
configString
,
fileName
));
}
}
catch
(
ConfigException
e
)
when
(
e
.
Parser
.
FileName
==
fileName
&&
fileName
!=
null
)
{
throw
new
PrintAndExit
(
e
.
ErrorStringWithFile
());
}
}
virtual
protected
void
parseConfig
(
ConfigParser
p
)
virtual
protected
void
parseConfig
(
ConfigParser
p
)
{
{
var
moduleTypes
=
new
Dictionary
<
string
,
Type
>(
var
moduleTypes
=
new
Dictionary
<
string
,
Type
>(
...
@@ -257,6 +277,7 @@ refresh
...
@@ -257,6 +277,7 @@ refresh
s
.
Use
();
s
.
Use
();
s
.
CheckUnused
();
s
.
CheckUnused
();
}
}
p
.
MainSection
.
CheckUnused
();
p
.
CheckUnused
();
p
.
CheckUnused
();
}
}
public
List
<
Block
>
Get
()
public
List
<
Block
>
Get
()
...
@@ -589,6 +610,29 @@ class StatusBarI3: RootStatusBar
...
@@ -589,6 +610,29 @@ class StatusBarI3: RootStatusBar
class
Program
class
Program
{
{
#pragma warning disable 1998
#pragma warning disable 1998
static
void
LinuxCatch
(
Action
f
)
{
try
{
f
();
}
catch
(
PrintAndExit
e
)
{
Console
.
Error
.
WriteLine
(
e
.
ToPrint
.
Pastel
(
Color
.
FromArgb
(
255
,
0
,
0
)));
Environment
.
Exit
(
e
.
ExitCode
);
}
catch
(
Exception
e
)
{
Console
.
Error
.
WriteLine
(
e
.
ToString
().
Pastel
(
Color
.
FromArgb
(
255
,
0
,
0
)));
Console
.
Error
.
WriteLine
(
@"
this is not supposed to happen. Please report this bug to
jirikalvoda+i3csstatus@kam.mff.cuni.cz. Thank you."
.
Pastel
(
Color
.
FromArgb
(
255
,
0
,
0
)));
Environment
.
Exit
(
134
);
}
}
static
int
Main
(
string
[]
args
)
static
int
Main
(
string
[]
args
)
{
{
var
configOption
=
new
Option
<
FileInfo
>
var
configOption
=
new
Option
<
FileInfo
>
...
@@ -617,7 +661,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.");
...
@@ -617,7 +661,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.");
rootCommand
.
Add
(
c_plainText
);
rootCommand
.
Add
(
c_plainText
);
c_plainText
.
SetHandler
(
async
(
config
)
=>
c_plainText
.
SetHandler
(
async
(
config
)
=>
{
{
(
new
StatusBarPlainText
(
config
)).
Run
(
Console
.
Out
);
LinuxCatch
(()
=>
(
new
StatusBarPlainText
(
config
)).
Run
(
Console
.
Out
)
)
;
},
configOption
);
},
configOption
);
var
c_terminal
=
new
Command
(
"terminal"
,
"Print status bar with terminal escape secvence."
);
var
c_terminal
=
new
Command
(
"terminal"
,
"Print status bar with terminal escape secvence."
);
...
@@ -628,7 +672,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.");
...
@@ -628,7 +672,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.");
c_terminal
.
Add
(
c_terminal_input
);
c_terminal
.
Add
(
c_terminal_input
);
c_terminal
.
SetHandler
(
async
(
config
,
input
)
=>
c_terminal
.
SetHandler
(
async
(
config
,
input
)
=>
{
{
(
new
StatusBarTerminal
(
config
,
input
)).
Run
(
Console
.
Out
);
LinuxCatch
(()
=>
(
new
StatusBarTerminal
(
config
,
input
)).
Run
(
Console
.
Out
)
)
;
},
configOption
,
c_terminal_input
);
},
configOption
,
c_terminal_input
);
var
c_i3
=
new
Command
(
"i3"
,
"Comunicate with i3bar."
);
var
c_i3
=
new
Command
(
"i3"
,
"Comunicate with i3bar."
);
...
@@ -639,11 +683,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.");
...
@@ -639,11 +683,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.");
c_i3
.
Add
(
c_i3_input
);
c_i3
.
Add
(
c_i3_input
);
c_i3
.
SetHandler
(
async
(
config
,
input
)
=>
c_i3
.
SetHandler
(
async
(
config
,
input
)
=>
{
{
(
new
StatusBarI3
(
config
,
input
)).
Run
(
Console
.
Out
);
LinuxCatch
(()
=>
(
new
StatusBarI3
(
config
,
input
)).
Run
(
Console
.
Out
)
)
;
},
configOption
,
c_i3_input
);
},
configOption
,
c_i3_input
);
rootCommand
.
Invoke
(
args
);
return
rootCommand
.
Invoke
(
args
);
return
0
;
}
}
#pragma warning restore 1998
#pragma warning restore 1998
}
}
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