Skip to content

Commit

Permalink
- Add flash messages while loading s3 and ec3 services
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Jan 25, 2023
1 parent 7dd289c commit ef24afb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
15 changes: 15 additions & 0 deletions cmd/app.go
Expand Up @@ -2,16 +2,31 @@ package cmd

import (
"fmt"
"os"

"github.com/one2nc/cloud-lens/internal/view"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/rs/zerolog/log"
)

var startCmd = &cobra.Command{
Use: `start`,
Short: `start cloudlens tui`,
Long: `start cli for aws services[s3, ec2]`,
Run: func(cmd *cobra.Command, args []string) {
mod := os.O_CREATE | os.O_APPEND | os.O_WRONLY
file, err := os.OpenFile("./log.txt", mod, 0644)
if err != nil {
panic(err)
}
defer func() {
if file != nil {
_ = file.Close()
}
}()
log.Logger = log.Output(zerolog.ConsoleWriter{Out: file})

app := view.NewApp()
if err := app.Init(); err != nil {
panic(fmt.Sprintf("app init failed -- %v", err))
Expand Down
2 changes: 1 addition & 1 deletion internal/model/flash.go
Expand Up @@ -10,7 +10,7 @@ import (

const (
// DefaultFlashDelay sets the flash clear delay.
DefaultFlashDelay = 3 * time.Second
DefaultFlashDelay = 2 * time.Second

// FlashInfo represents an info message.
FlashInfo FlashLevel = iota
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/flash.go
Expand Up @@ -32,7 +32,7 @@ func NewFlash(app *App) *Flash {
f.SetTextColor(tcell.ColorAqua)
f.SetDynamicColors(true)
f.SetTextAlign(tview.AlignCenter)
f.SetBorderPadding(0, 0, 1, 1)
f.SetBorderPadding(1, 1, 1, 1)

return &f
}
Expand Down
27 changes: 13 additions & 14 deletions internal/view/app.go
Expand Up @@ -38,28 +38,26 @@ func NewApp() *App {
}

func (a *App) Init() error {
_ = context.WithValue(context.Background(), internal.KeyApp, a)
ctx := context.WithValue(context.Background(), internal.KeyApp, a)

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

func (a *App) layout() *tview.Flex {
func (a *App) layout(ctx context.Context) *tview.Flex {
cfg, _ := config.Get()

main := tview.NewFlex().SetDirection(tview.FlexRow)

//----Flash Mesages----
flash := ui.NewFlash(a.App)
go flash.Watch(ctx, a.Flash().Channel())
//------menu-----
menuColFlex := tview.NewFlex().SetDirection(tview.FlexColumn)
//menuColFlex.SetBorder(true)
ddRowFlex := tview.NewFlex().SetDirection(tview.FlexRow)
//ddRowFlex.SetBorder(true)

textv := tview.NewTextView()
textv.SetBackgroundColor(tcell.ColorBlack)
//textv.SetBorder(true)

var ins []aws.EC2Resp
var buckets []aws.BucketResp

Expand All @@ -81,7 +79,6 @@ func (a *App) layout() *tview.Flex {
sess, _ = config.GetSession(*currentProfile, *currentRegion, cfg.AwsConfig)
ins, _ = aws.GetInstances(*sess)
buckets, _ = aws.ListBuckets(*sess)
textv.SetText("🌈🌧️ cloudlens profile..." + fmt.Sprintf("%v", a.Main.Pages.CurrentPage()))
if servicePage.ItemAt(0) != nil {
servicePage.RemoveItemAtIndex(0)
}
Expand All @@ -101,7 +98,6 @@ func (a *App) layout() *tview.Flex {
sess, _ = config.GetSession(*currentProfile, *currentRegion, cfg.AwsConfig)
ins, _ = aws.GetInstances(*sess)
buckets, _ = aws.ListBuckets(*sess)
textv.SetText("🌈🌧️ cloudlens region... " + fmt.Sprintf("%v", ins))
if servicePage.ItemAt(0) != nil {
servicePage.RemoveItemAtIndex(0)
}
Expand All @@ -123,6 +119,7 @@ func (a *App) layout() *tview.Flex {
menuColFlex.AddItem(ddRowFlex, 0, 1, false)

servicePage = tview.NewFlex().SetDirection(tview.FlexRow)
a.Flash().Info("Loading EC2 instacnes...")
servicePageContent = a.DisplayEc2Instances(ins, sess)
servicePageContent.SetBorderFocusColor(tcell.ColorSpringGreen)
a.Application.SetFocus(servicePageContent)
Expand Down Expand Up @@ -228,13 +225,15 @@ func (a *App) layout() *tview.Flex {
serviceName := inputField.GetText()
switch serviceName {
case "S3", "s3":
a.Flash().Info("Loading S3 Buckets...")
servicePage.RemoveItemAtIndex(0)
servicePageContent = a.DisplayS3Buckets(sess, buckets)
servicePage.AddItem(servicePageContent, 0, 6, true)
a.Application.SetFocus(servicePageContent)
inputField.SetText("")

case "EC2", "ec2", "Ec2", "eC2":
a.Flash().Info("Loading EC2 instacnes...")
servicePage.RemoveItemAtIndex(0)
servicePageContent = a.DisplayEc2Instances(ins, sess)
// ec2Page.AddItem(menuColFlex, 0, 2, false)
Expand All @@ -243,8 +242,8 @@ func (a *App) layout() *tview.Flex {
inputField.SetText("")

default:
textv.SetText("🌈🌧️ No service...")
inputField.SetText("")
a.Flash().Err(fmt.Errorf("NO SERVICE..."))
}
}
})
Expand All @@ -258,9 +257,8 @@ func (a *App) layout() *tview.Flex {

main.AddItem(menuColFlex, 0, 2, false)
main.AddItem(inputField, 0, 1, false)
// main.AddItem(content, 0, 6, true)
main.AddItem(servicePage, 0, 7, true)
main.AddItem(textv, 0, 2, false)
main.AddItem(servicePage, 0, 8, true)
main.AddItem(flash, 0, 1, false)
a.Main.AddPage("main", main, true, false)
a.Main.AddPage("splash", ui.NewSplash("0.0.1"), true, true)
return main
Expand Down Expand Up @@ -579,6 +577,7 @@ func (a *App) Run() error {
<-time.After(splashDelay)
a.QueueUpdateDraw(func() {
a.Main.SwitchToPage("main")
a.Application.SetFocus(a.Main.CurrentPage().Item)
})
}()

Expand Down

0 comments on commit ef24afb

Please sign in to comment.