62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
ui "github.com/VladimirMarkelov/clui"
|
|
)
|
|
|
|
type RebootDialog struct {
|
|
View *ui.Window
|
|
}
|
|
|
|
func CreateRebootDialog(title, login string) *RebootDialog {
|
|
dlg := new(RebootDialog)
|
|
|
|
sWidth, sHeight := ui.ScreenSize()
|
|
wWidth, wHeight := 48, 10
|
|
dlg.View = ui.AddWindow(sWidth/2-wWidth/2, sHeight/2-wHeight/2, wWidth, wHeight, title)
|
|
ui.WindowManager().BeginUpdate()
|
|
defer ui.WindowManager().EndUpdate()
|
|
|
|
dlg.View.SetModal(true)
|
|
dlg.View.SetSizable(false)
|
|
dlg.View.SetTitleButtons(ui.ButtonDefault)
|
|
dlg.View.SetPack(ui.Vertical)
|
|
|
|
textfrm := ui.CreateFrame(dlg.View, 1, 1, ui.BorderNone, ui.Fixed)
|
|
textfrm.SetPaddings(1, 1)
|
|
textfrm.SetPack(ui.Vertical)
|
|
textfrm.SetGaps(2, 1)
|
|
|
|
lbl1 := ui.CreateLabel(textfrm, ui.AutoSize, ui.AutoSize, " You are now successfully logged in as:", ui.Fixed)
|
|
lbl1.SetTextColor(ui.ColorWhiteBold)
|
|
|
|
for i := 0; i <= wWidth/2-len(login)/2; i += 1 {
|
|
login = " " + login
|
|
}
|
|
lbl2 := ui.CreateLabel(textfrm, ui.AutoSize, ui.AutoSize, login, 1)
|
|
lbl2.SetTextColor(ui.ColorGreenBold)
|
|
|
|
lbl3 := ui.CreateLabel(textfrm, 40, 2, " Your computer will automatically\n reboot in a few seconds...", ui.Fixed)
|
|
lbl3.SetMultiline(true)
|
|
|
|
progress := ui.CreateProgressBar(textfrm, ui.AutoSize, ui.AutoSize, ui.Fixed)
|
|
progress.SetLimits(0, 100)
|
|
|
|
lbl4 := ui.CreateLabel(textfrm, 40, 4, "\nThe challenge begins right after the reboot. Good luck!", ui.Fixed)
|
|
lbl4.SetTextColor(ui.ColorWhiteBold)
|
|
lbl4.SetMultiline(true)
|
|
|
|
go func() {
|
|
for i := 0; i < 100; i += 1 {
|
|
progress.SetValue(i)
|
|
ui.PutEvent(ui.Event{Type: ui.EventRedraw})
|
|
time.Sleep(64 * time.Millisecond)
|
|
}
|
|
ui.WindowManager().DestroyWindow(dlg.View)
|
|
}()
|
|
|
|
return dlg
|
|
}
|