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
49831294
Commit
49831294
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
better terminal and plain-rext outputs
parent
614f5697
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Program.cs
+56
-11
56 additions, 11 deletions
Program.cs
with
56 additions
and
11 deletions
Program.cs
+
56
−
11
View file @
49831294
...
...
@@ -10,6 +10,7 @@ using System.Text.Json;
using
System.Text.Json.Nodes
;
using
System.Linq
;
using
System.Threading
;
using
StringInfo
=
System
.
Globalization
.
StringInfo
;
using
System.CommandLine
;
using
System.Runtime.InteropServices
;
...
...
@@ -242,23 +243,59 @@ abstract class RootStatusBar: StatusBar
class
StatusBarPlainText
:
RootStatusBar
{
public
static
string
RemoveMarkup
(
string
s
,
Markup
m
)
{
if
(
m
==
Markup
.
Pango
)
{
bool
inTag
=
new
();
StringBuilder
res
=
new
();
foreach
(
char
c
in
s
)
{
if
(
c
==
'<'
)
inTag
=
true
;
if
(!
inTag
)
res
.
Append
(
c
);
if
(
c
==
'>'
)
inTag
=
false
;
}
return
res
.
ToString
();
}
return
s
;
}
protected
virtual
string
elementAsString
(
Element
e
)
{
string
s
=
RemoveMarkup
(
e
.
Text
,
e
.
Markup
);
if
(
e
.
MinWidth_string
!=
null
||
e
.
MinWidth_int
!=
null
)
{
int
minWidth
=
0
;
if
(
e
.
MinWidth_string
!=
null
)
minWidth
=
new
StringInfo
(
e
.
MinWidth_string
).
LengthInTextElements
;
if
(
e
.
MinWidth_int
!=
null
)
minWidth
=
(
int
)
e
.
MinWidth_int
/
6
;
int
current
=
new
StringInfo
(
s
).
LengthInTextElements
;
if
(
current
<
minWidth
)
{
if
(
e
.
Align
==
Align
.
Left
)
s
=
s
+
new
String
(
' '
,
minWidth
-
current
);
if
(
e
.
Align
==
Align
.
Right
)
s
=
new
String
(
' '
,
minWidth
-
current
)
+
s
;
if
(
e
.
Align
==
Align
.
Center
)
s
=
new
String
(
' '
,
(
minWidth
-
current
+
1
)/
2
)
+
s
+
new
String
(
' '
,
(
minWidth
-
current
)/
2
);
}
}
return
s
;
}
public
StatusBarPlainText
(
FileInfo
configFile
):
base
(
configFile
){}
override
protected
void
format
(
TextWriter
w
,
List
<
Element
>
elements
)
{
bool
fir
st
=
true
;
Element
?
la
st
=
null
;
foreach
(
var
e
in
elements
)
{
if
(
!
first
)
w
.
Write
(
"|
"
);
first
=
false
;
w
.
Write
(
e
.
Text
)
;
if
(
last
!=
null
)
w
.
Write
(
last
.
Separator
?
"|"
:
"
"
);
w
.
Write
(
elementAsString
(
e
))
;
last
=
e
;
}
w
.
WriteLine
(
""
);
}
}
class
StatusBarTerminal
:
Root
StatusBar
class
StatusBarTerminal
:
StatusBar
PlainText
{
Thread
?
inputThread
;
public
StatusBarTerminal
(
FileInfo
configFile
,
bool
doInput
):
base
(
configFile
)
...
...
@@ -283,15 +320,23 @@ class StatusBarTerminal: RootStatusBar
Console
.
WriteLine
(
""
);
}
}
override
protected
string
elementAsString
(
Element
e
)
{
string
msg
=
base
.
elementAsString
(
e
);
if
(
e
.
Urgent
)
msg
=
$"\x1B[1m
{
msg
}
\x1B[0m"
;
if
(
e
.
Color
!=
null
)
msg
=
msg
.
Pastel
(
e
.
Color
.
Value
);
if
(
e
.
BackgroundColor
!=
null
)
msg
=
msg
.
PastelBg
(
e
.
BackgroundColor
.
Value
);
return
msg
;
}
override
protected
void
format
(
TextWriter
w
,
List
<
Element
>
elements
)
{
bool
fir
st
=
true
;
Element
?
la
st
=
null
;
foreach
(
var
e
in
elements
)
{
if
(
!
first
)
w
.
Write
(
"|"
.
Pastel
(
Color
.
FromArgb
(
165
,
229
,
250
)));
first
=
false
;
w
.
Write
(
e
.
Color
!=
null
?
e
.
Text
.
Pastel
(
e
.
Color
.
Value
):
e
.
Text
)
;
if
(
last
!=
null
)
w
.
Write
(
(
last
.
Separator
?
"|"
:
" "
)
.
Pastel
(
Color
.
FromArgb
(
165
,
229
,
250
)));
w
.
Write
(
elementAsString
(
e
))
;
last
=
e
;
}
w
.
WriteLine
(
""
);
}
...
...
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