github.com/oam-dev/kubevela@v1.9.11/references/cli/top/component/crumbs.go (about) 1 /* 2 Copyright 2022 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package component 18 19 import ( 20 "github.com/rivo/tview" 21 22 "github.com/oam-dev/kubevela/references/cli/top/config" 23 "github.com/oam-dev/kubevela/references/cli/top/model" 24 ) 25 26 // Crumbs component lay on footer of app and indicate resource level 27 type Crumbs struct { 28 *tview.Flex 29 style *config.ThemeConfig 30 } 31 32 // NewCrumbs return a new crumbs component 33 func NewCrumbs(config *config.ThemeConfig) *Crumbs { 34 c := &Crumbs{ 35 Flex: tview.NewFlex(), 36 style: config, 37 } 38 return c 39 } 40 41 // StackPop change itself when accept "pop" notify from app's main view 42 func (c *Crumbs) StackPop(_, _ model.View) { 43 num := c.GetItemCount() 44 if num >= 2 { 45 c.RemoveItem(c.GetItem(num - 1)) 46 c.RemoveItem(c.GetItem(num - 2)) 47 } 48 } 49 50 // StackPush change itself when accept "push" notify from app's main view 51 func (c *Crumbs) StackPush(_, new model.View) { 52 name := new.Name() 53 t := tview.NewTextView() 54 t.SetTextColor(c.style.Crumbs.Foreground.Color()) 55 t.SetBackgroundColor(c.style.Crumbs.Background.Color()) 56 t.SetTextAlign(tview.AlignCenter) 57 58 t.SetText(name) 59 c.AddItem(t, len(name)+2, 0, false) 60 c.AddItem(tview.NewTextView(), 1, 0, false) 61 }