Skip to content

Commit

Permalink
- Add spash screen for 1 sec
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Jan 25, 2023
1 parent 99579aa commit 7dd289c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 15 deletions.
14 changes: 10 additions & 4 deletions cmd/app.go
@@ -1,6 +1,8 @@
package cmd

import (
"fmt"

"github.com/one2nc/cloud-lens/internal/view"
"github.com/spf13/cobra"
)
Expand All @@ -11,11 +13,15 @@ var startCmd = &cobra.Command{
Long: `start cli for aws services[s3, ec2]`,
Run: func(cmd *cobra.Command, args []string) {
app := view.NewApp()
app.Init()
if err := app.Init(); err != nil {
panic(fmt.Sprintf("app init failed -- %v", err))
}
if err := app.Run(); err != nil {
panic(fmt.Sprintf("app run failed %v", err))
}
},
}


func init(){
func init() {
rootCmd.AddCommand(startCmd)
}
}
53 changes: 53 additions & 0 deletions internal/ui/splash.go
@@ -0,0 +1,53 @@
package ui

import (
"strings"

"github.com/derailed/tview"
"github.com/gdamore/tcell/v2"
)

// LogoBig K9s big logo for splash page.
var LogoBig = []string{
`█▀▀ █░░ █▀▀█ █░░█ █▀▀▄ █░░ █▀▀ █▀▀▄ █▀▀`,
`█░░ █░░ █░░█ █░░█ █░░█ █░░ █▀▀ █░░█ ▀▀█`,
`▀▀▀ ▀▀▀ ▀▀▀▀ ░▀▀▀ ▀▀▀░ ▀▀▀ ▀▀▀ ▀░░▀ ▀▀▀`,
}

type Splash struct {
*tview.Flex
}

func NewSplash(version string) *Splash {
s := Splash{Flex: tview.NewFlex()}
s.SetBackgroundColor(tcell.ColorBlack)

logo := tview.NewTextView()
logo.SetDynamicColors(true)
logo.SetTextAlign(tview.AlignCenter)
s.layoutLogo(logo)

vers := tview.NewTextView()
vers.SetDynamicColors(true)
vers.SetTextAlign(tview.AlignCenter)
s.layoutRev(vers, version)

s.SetDirection(tview.FlexRow)
s.AddItem(tview.NewBox(), 10, 1, false)
s.AddItem(logo, 10, 1, false)
s.AddItem(vers, 10, 1, false)

return &s
}

func (s *Splash) layoutLogo(t *tview.TextView) {
logo := strings.Join(LogoBig, "\n")
t.SetText(logo)
t.SetTextColor(tcell.ColorWheat)
t.SetBorderPadding(2, 0, 1, 1)
}

func (s *Splash) layoutRev(t *tview.TextView, rev string) {
t.SetText("v" + rev)
t.SetTextColor(tcell.ColorSpringGreen)
}
43 changes: 32 additions & 11 deletions internal/view/app.go
Expand Up @@ -6,6 +6,7 @@ import (
"sort"
"strconv"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
Expand All @@ -19,6 +20,10 @@ import (
"github.com/rs/zerolog/log"
)

const (
splashDelay = 1 * time.Second
)

type App struct {
*ui.App
cancelFn context.CancelFunc
Expand All @@ -37,7 +42,6 @@ func (a *App) Init() error {

a.App.Init()
a.layout()
a.App.Run()
return nil
}

Expand Down Expand Up @@ -258,7 +262,7 @@ func (a *App) layout() *tview.Flex {
main.AddItem(servicePage, 0, 7, true)
main.AddItem(textv, 0, 2, false)
a.Main.AddPage("main", main, true, false)
a.Main.ShowPage("main")
a.Main.AddPage("splash", ui.NewSplash("0.0.1"), true, true)
return main
}

Expand Down Expand Up @@ -373,14 +377,14 @@ func (a *App) DisplayS3Buckets(sess *session.Session, buckets []aws.BucketResp)
s3DataT.SetBorderFocusColor(tcell.ColorSpringGreen)
a.Main.AddAndSwitchToPage("s3data", flex, true)
s3DataT.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { // Empty
if event.Key() == tcell.KeyESC {
a.Application.SetFocus(a.Views()["content"].(*tview.Flex).ItemAt(0))
flex.Clear()
s3DataT.Clear()
a.Main.RemovePage("s3data")
a.Main.SwitchToPage("main")
a.Application.SetFocus(table)
}
if event.Key() == tcell.KeyESC {
a.Application.SetFocus(a.Views()["content"].(*tview.Flex).ItemAt(0))
flex.Clear()
s3DataT.Clear()
a.Main.RemovePage("s3data")
a.Main.SwitchToPage("main")
a.Application.SetFocus(table)
}
return event
})
} else {
Expand Down Expand Up @@ -531,7 +535,7 @@ func (a *App) DisplayS3Objects(s3DataTable *tview.Table, flex *tview.Flex, folde
s3DataT.Select(1, 1).SetFixed(1, 1)
a.Main.AddAndSwitchToPage("s3dataView", flex, true)
}

}

func getLevelInfo(bucketInfo *s3.ListObjectsV2Output) ([]string, []string) {
Expand All @@ -554,6 +558,7 @@ func (a *App) tempLayout(ctx context.Context) {
main := tview.NewFlex().SetDirection(tview.FlexRow)
main.AddItem(a.statusIndicator(), 1, 1, false)
a.Main.AddPage("main", main, true, false)
a.Main.AddPage("splash", ui.NewSplash("0.0.1"), true, true)
main.AddItem(flash, 1, 1, false)
a.toggleHeader(true)
}
Expand All @@ -568,6 +573,22 @@ func (a *App) QueueUpdateDraw(f func()) {
}()
}

func (a *App) Run() error {
//a.Resume()
go func() {
<-time.After(splashDelay)
a.QueueUpdateDraw(func() {
a.Main.SwitchToPage("main")
})
}()

if err := a.Application.Run(); err != nil {
return err
}

return nil
}

func (a *App) toggleHeader(header bool) {
a.showHeader = header

Expand Down

0 comments on commit 7dd289c

Please sign in to comment.