github.com/oam-dev/kubevela@v1.9.11/references/cli/top/view/help_view.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 view
    18  
    19  import (
    20  	"fmt"
    21  	"strings"
    22  
    23  	"github.com/gdamore/tcell/v2"
    24  	"github.com/rivo/tview"
    25  
    26  	"github.com/oam-dev/kubevela/references/cli/top/component"
    27  	"github.com/oam-dev/kubevela/references/cli/top/model"
    28  )
    29  
    30  // HelpView is the view which display help tips about how to use app
    31  type HelpView struct {
    32  	*tview.TextView
    33  	app     *App
    34  	actions model.KeyActions
    35  }
    36  
    37  var (
    38  	helpViewInstance = new(HelpView)
    39  )
    40  
    41  // NewHelpView return a new help view
    42  func NewHelpView(app *App) model.View {
    43  	if helpViewInstance.TextView == nil {
    44  		helpViewInstance.TextView = tview.NewTextView()
    45  		helpViewInstance.app = app
    46  		helpViewInstance.actions = make(model.KeyActions)
    47  	}
    48  	return helpViewInstance
    49  }
    50  
    51  // Init help view init
    52  func (v *HelpView) Init() {
    53  	title := fmt.Sprintf("[ %s ]", v.Name())
    54  	v.SetDynamicColors(true)
    55  	v.SetTitle(title).SetTitleColor(v.app.config.Theme.Table.Title.Color())
    56  	v.SetBorder(true)
    57  	v.SetBorderAttributes(tcell.AttrItalic)
    58  	v.SetBorderPadding(1, 1, 2, 2)
    59  	v.bindKeys()
    60  }
    61  
    62  // Start the help view
    63  func (v *HelpView) Start() {
    64  	tips := `
    65  [highlight:]vela top[normal:] is a UI based CLI tool provided in KubeVela. By using it, you can obtain the overview information of the platform and diagnose the resource status of the application.
    66  
    67  At present, the tool has provided the following feature:
    68  
    69  [highlight:]*[normal:] Platform information overview
    70  [highlight:]*[normal:] Display of resource status information in Application, Managed Resource, Pod and Container levels
    71  [highlight:]*[normal:] Application Resource Topology
    72  [highlight:]*[normal:] Resource YAML text display
    73  [highlight:]*[normal:] Theme switching
    74  
    75  This information panel component in UI header will display the performance information of the KubeVela system.
    76  
    77  Resource tables are in the UI body, resource of four levels are displayed here. You can use the <enter> key to enter the next resource level or the <q> key to return to the previous level.
    78  
    79  The crumbs component in the footer indicates the current resource level.
    80  
    81  At present, vela top has provided more than ten built-in themes, which you can use the <ctrl+t> key to enter theme switching view and choose according to your own preferences. What's more, vela top also supports custom themes, you can refer to the following link to customize your own theme: https://kubevela.io/docs/next/tutorials/vela-top .
    82  `
    83  	tips = strings.ReplaceAll(tips, "highlight", v.app.config.Theme.Info.Title.String())
    84  	tips = strings.ReplaceAll(tips, "normal", v.app.config.Theme.Info.Text.String())
    85  
    86  	v.SetText(tips)
    87  }
    88  
    89  // Stop the help view
    90  func (v *HelpView) Stop() {}
    91  
    92  // Name return help view name
    93  func (v *HelpView) Name() string {
    94  	return "Help"
    95  }
    96  
    97  // Hint return the menu hints of yaml view
    98  func (v *HelpView) Hint() []model.MenuHint {
    99  	return v.actions.Hint()
   100  }
   101  
   102  func (v *HelpView) bindKeys() {
   103  	v.actions.Add(model.KeyActions{
   104  		component.KeyQ:    model.KeyAction{Description: "Back", Action: v.app.Back, Visible: true, Shared: true},
   105  		component.KeyHelp: model.KeyAction{Description: "Back", Action: v.app.Back, Visible: true, Shared: true},
   106  	})
   107  }