Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ynerant
cemantix-charm
Commits
b3768042
Verified
Commit
b3768042
authored
Apr 28, 2022
by
ynerant
Browse files
Auto resize progress bars
parent
f68970ea
Changes
1
Hide whitespace changes
Inline
Side-by-side
main.go
View file @
b3768042
...
...
@@ -143,6 +143,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m
.
wordsViewport
.
Height
=
msg
.
Height
-
verticalMarginHeight
}
lineWidth
:=
lipgloss
.
Width
(
fmt
.
Sprintf
(
"* %s %s %s %4d "
,
strings
.
Repeat
(
" "
,
m
.
maxLength
),
"-00.00"
,
" "
,
42
,
))
m
.
progressBar
.
Width
=
msg
.
Width
-
lineWidth
m
.
wordsViewport
.
SetContent
(
m
.
wordsView
())
case
errMsg
:
m
.
err
=
msg
return
m
,
nil
...
...
@@ -168,11 +178,16 @@ func (m model) InputWord() (model, tea.Cmd) {
w
:=
word
{
input
,
200
*
rand
.
Float64
()
-
100
,
rand
.
Intn
(
1000
)}
m
.
words
=
append
(
m
.
words
,
w
)
var
content
string
for
_
,
w
:=
range
m
.
words
{
content
+=
w
.
View
(
m
)
}
m
.
wordsViewport
.
SetContent
(
content
)
lineWidth
:=
lipgloss
.
Width
(
fmt
.
Sprintf
(
"* %s %s %s %4d "
,
strings
.
Repeat
(
" "
,
m
.
maxLength
),
"-00.00"
,
" "
,
42
,
))
m
.
progressBar
.
Width
=
m
.
wordsViewport
.
Width
-
lineWidth
m
.
wordsViewport
.
SetContent
(
m
.
wordsView
())
m
.
textInput
.
SetValue
(
""
)
m
.
textInput
.
CursorStart
()
...
...
@@ -209,7 +224,7 @@ func (w word) View(m model) string {
}
return
fmt
.
Sprintf
(
"* %s
\t
%s %s
\t
%4d %s
\n
"
,
"* %s
%s %s
%4d %s
\n
"
,
w
.
content
+
strings
.
Repeat
(
" "
,
m
.
maxLength
-
len
(
w
.
content
)),
distStr
,
emoji
,
...
...
@@ -240,6 +255,14 @@ func (m model) headerView() string {
return
msg
}
func
(
m
model
)
wordsView
()
string
{
var
content
string
for
_
,
w
:=
range
m
.
words
{
content
+=
w
.
View
(
m
)
}
return
content
}
func
(
m
model
)
footerView
()
string
{
info
:=
infoStyle
.
Render
(
fmt
.
Sprintf
(
"%3.f%%"
,
m
.
wordsViewport
.
ScrollPercent
()
*
100
))
line
:=
strings
.
Repeat
(
"─"
,
int
(
math
.
Max
(
0
,
float64
(
m
.
wordsViewport
.
Width
-
lipgloss
.
Width
(
info
)))))
...
...
@@ -248,7 +271,7 @@ func (m model) footerView() string {
func
(
m
model
)
View
()
string
{
if
!
m
.
ready
{
return
"
\n\t
Initiali
zing...
"
return
"
\n\t
Initiali
sation…
"
}
return
fmt
.
Sprintf
(
"%s
\n
%s
\n
%s"
,
m
.
headerView
(),
m
.
wordsViewport
.
View
(),
m
.
footerView
())
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment