You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by al...@apache.org on 2020/08/29 15:19:10 UTC

[skywalking-cli] branch traces-search created (now cb8b1c8)

This is an automated email from the ASF dual-hosted git repository.

alonelaval pushed a change to branch traces-search
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git.


      at cb8b1c8  update traces search

This branch includes the following new commits:

     new cb8b1c8  update traces search

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-cli] 01/01: update traces search

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alonelaval pushed a commit to branch traces-search
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git

commit cb8b1c83a5a4e15cab209fddaa8275bd5f2d5c1c
Author: huawei <al...@gmail.com>
AuthorDate: Sat Aug 29 23:18:42 2020 +0800

    update traces search
---
 display/graph/tree/list.go | 121 +++++++++++++++++++++++++++++----------------
 display/graph/tree/tree.go |   6 +--
 2 files changed, 82 insertions(+), 45 deletions(-)

diff --git a/display/graph/tree/list.go b/display/graph/tree/list.go
index cb11f34..f125d37 100644
--- a/display/graph/tree/list.go
+++ b/display/graph/tree/list.go
@@ -33,8 +33,9 @@ import (
 )
 
 const DefaultPageSize = 15
-const keymap = " Keymap "
-const cc = "<C-c>"
+const KeyMap = " Keymap "
+const Detail = " Detail "
+const Quit = "<C-c>"
 
 func DisplayList(ctx *cli.Context, displayable *d.Displayable) error {
 	data := displayable.Data.(schema.TraceBrief)
@@ -48,59 +49,73 @@ func DisplayList(ctx *cli.Context, displayable *d.Displayable) error {
 	list.TitleStyle.Fg = ui.ColorRed
 	list.TextStyle = ui.NewStyle(ui.ColorYellow)
 	list.WrapText = false
-
+	list.SelectedRowStyle = ui.Style{
+		Fg:       ui.ColorBlack,
+		Bg:       ui.ColorWhite,
+		Modifier: ui.ModifierBold,
+	}
 	tree := widgets.NewTree()
 	tree.TextStyle = ui.NewStyle(ui.ColorYellow)
 	tree.WrapText = false
 	tree.TitleStyle.Fg = ui.ColorRed
+	tree.SelectedRowStyle = ui.Style{
+		Fg:       ui.ColorBlack,
+		Bg:       ui.ColorWhite,
+		Modifier: ui.ModifierBold,
+	}
 
 	help := widgets.NewParagraph()
 	help.WrapText = false
-	help.Title = keymap
-	help.Text = `[k          ](fg:red,mod:bold) Scroll Up
-		[<Up>       ](fg:red,mod:bold) Scroll Up
-		[j          ](fg:red,mod:bold) Scroll Down
-		[<Down>     ](fg:red,mod:bold) Scroll Down
-		[<Ctr-b>    ](fg:red,mod:bold) list Page Up
-		[<Ctr-f>    ](fg:red,mod:bold) list Page Down           
+	help.Title = KeyMap
+	help.Text = `[<Left>     ](fg:red,mod:bold) list activated
+		[<Right>    ](fg:red,mod:bold) tree activated
+		[K or <Up>  ](fg:red,mod:bold) list or tree Scroll Up
+		[j or <Down>](fg:red,mod:bold) list or tree Scroll Down
+		[<Ctr-b>    ](fg:red,mod:bold) list or tree Page Up
+		[<Ctr-f>    ](fg:red,mod:bold) list or tree Page Down
 		[p          ](fg:red,mod:bold) list Page Up
 		[n          ](fg:red,mod:bold) list Page Down
-		[<Ctr-u>    ](fg:red,mod:bold) Scroll Half Page Up
-		[<Ctr-d>    ](fg:red,mod:bold) Scroll Half Page Down
-		[<Home>     ](fg:red,mod:bold) Scroll to Top
-		[<Enter>    ](fg:red,mod:bold) Show Trace
-		[<End>      ](fg:red,mod:bold) Scroll to Bottom
-		[q          ](fg:red,mod:bold) Quit
-		[<Ctr-c>    ](fg:red,mod:bold) Quit
+		[<Home>     ](fg:red,mod:bold) list or tree Scroll to Top
+		[<End>      ](fg:red,mod:bold) list or tree Scroll to Bottom
+		[q or <Ctr-c>](fg:red,mod:bold) Quit
         `
-	draw(list, tree, help, data, 0, ctx, condition)
-	listenTracesKeyboard(list, tree, data, ctx, help, condition)
+	detail := widgets.NewParagraph()
+	detail.Title = Detail
+	detail.WrapText = false
+
+	draw(list, tree, detail, help, data, ctx, condition)
+	listenTracesKeyboard(list, tree, data, ctx, detail, help, condition)
 
 	return nil
 }
 
-func draw(list *widgets.List, tree *widgets.Tree, help *widgets.Paragraph, data schema.TraceBrief, showIndex int,
+func draw(list *widgets.List, tree *widgets.Tree, detail, help *widgets.Paragraph, data schema.TraceBrief,
 	ctx *cli.Context, condition *schema.TraceQueryCondition) {
 	x, y := ui.TerminalDimensions()
 
 	if data.Total != 0 {
+		showIndex := list.SelectedRow
 		var traceID = data.Traces[showIndex].TraceIds[0]
 		list.Title = fmt.Sprintf("[ %d/%d  %s]", *condition.Paging.PageNum, totalPages(data.Total), traceID)
 		nodes, serviceNames := getNodeData(ctx, traceID)
 		tree.Title = fmt.Sprintf("[%s]", strings.Join(serviceNames, "->"))
 		tree.SetNodes(nodes)
 		list.Rows = rows(data, x/4)
+		selected := extra[tree.SelectedNode()]
+		detail.Text = selected.Detail
 	} else {
 		noData := "no data"
 		list.Title = noData
 		tree.Title = noData
+		detail.Title = noData
 	}
 
 	list.SetRect(0, 0, x, y)
-	tree.SetRect(x/4, 0, x, y)
-	help.SetRect(x-x/7, 0, x, y)
+	tree.SetRect(x/5, 0, x, y)
+	detail.SetRect(x-x/5, 0, x, y/2)
+	help.SetRect(x-x/5, y/2, x, y)
 	tree.ExpandAll()
-	ui.Render(list, tree, help)
+	ui.Render(list, tree, detail, help)
 }
 func totalPages(total int) int {
 	if total%DefaultPageSize == 0 {
@@ -110,14 +125,14 @@ func totalPages(total int) int {
 }
 
 func listenTracesKeyboard(list *widgets.List, tree *widgets.Tree, data schema.TraceBrief, ctx *cli.Context,
-	help *widgets.Paragraph, condition *schema.TraceQueryCondition) {
+	detail, help *widgets.Paragraph, condition *schema.TraceQueryCondition) {
 	uiEvents := ui.PollEvents()
+	listActive := true
 	for {
-		showIndex := 0
 		e := <-uiEvents
 
 		switch e.ID {
-		case "q", cc:
+		case "q", Quit:
 			return
 		case "<C-b>", "p":
 			pageNum := *condition.Paging.PageNum
@@ -133,30 +148,52 @@ func listenTracesKeyboard(list *widgets.List, tree *widgets.Tree, data schema.Tr
 				condition.Paging.PageNum = &pageNum
 				data = trace.Traces(ctx, condition)
 			}
+		case "<Right>":
+			listActive = false
+		case "<Left>":
+			listActive = true
 		default:
-			if action := listActions(e.ID, list); action != nil {
+			if action := listActions(e.ID, list, tree, listActive); action != nil {
 				action()
 			}
-			showIndex = list.SelectedRow
 		}
-		draw(list, tree, help, data, showIndex, ctx, condition)
+
+		draw(list, tree, detail, help, data, ctx, condition)
 	}
 }
-func listActions(key string, list *widgets.List) func() {
-	// mostly vim style
-	actions := map[string]func(){
-		"k":      list.ScrollUp,
-		"<Up>":   list.ScrollUp,
-		"j":      list.ScrollDown,
-		"<Down>": list.ScrollDown,
-		"<C-u>":  list.ScrollHalfPageUp,
-		"<C-d>":  list.ScrollHalfPageDown,
-		"<Home>": list.ScrollTop,
-		"G":      list.ScrollBottom,
-		"<End>":  list.ScrollBottom,
+
+func listActions(key string, list *widgets.List, tree *widgets.Tree, listActive bool) func() {
+	var f func()
+	switch key {
+	case "k", "<Up>":
+		if listActive {
+			f = list.ScrollUp
+			tree.SelectedRow = 0
+		} else {
+			f = tree.ScrollUp
+		}
+	case "j", "<Down>":
+		if listActive {
+			tree.SelectedRow = 0
+			f = list.ScrollDown
+		} else {
+			f = tree.ScrollDown
+		}
+	case "<Home>":
+		if listActive {
+			f = list.ScrollTop
+		} else {
+			f = tree.ScrollTop
+		}
+	case "<End>":
+		if listActive {
+			f = list.ScrollBottom
+		} else {
+			f = tree.ScrollBottom
+		}
 	}
 
-	return actions[key]
+	return f
 }
 
 func getNodeData(ctx *cli.Context, traceID string) (nodes []*widgets.TreeNode, serviceNames []string) {
diff --git a/display/graph/tree/tree.go b/display/graph/tree/tree.go
index aff3bf0..ee0e168 100644
--- a/display/graph/tree/tree.go
+++ b/display/graph/tree/tree.go
@@ -72,14 +72,14 @@ func Display(roots []*Node, serviceNames []string) error {
 	tree.SetRect(0, 0, x, y)
 
 	detail := widgets.NewParagraph()
-	detail.Title = " Detail "
+	detail.Title = Detail
 	detail.WrapText = false
 	detail.SetRect(x, 0, x, y)
 
 	help := widgets.NewParagraph()
 	help.WrapText = false
 	help.SetRect(x, 0, x, y)
-	help.Title = keymap
+	help.Title = KeyMap
 	help.Text = `
 		[?          ](fg:red,mod:bold) Toggle this help
 		[k          ](fg:red,mod:bold) Scroll Up
@@ -165,7 +165,7 @@ func listenKeyboard(tree *widgets.Tree, detail, help *widgets.Paragraph) {
 		e := <-uiEvents
 
 		switch e.ID {
-		case "q", cc:
+		case "q", Quit:
 			return
 		case "g":
 			if previousKey == "g" {