Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
feat: title and borders for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann-Gael GAUTHERON committed Apr 23, 2021
1 parent b463a5f commit 3ca97ab
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
11 changes: 7 additions & 4 deletions pkg/ktop/ktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
type Monitor struct {
*kube.KubeClients

logs *ui.TextField
logs *ui.Paragraph
table *ui.Table
tableTypeCircle *ring.Ring

Expand Down Expand Up @@ -69,8 +69,11 @@ func NewMonitor(kubeclients *kube.KubeClients, podQuery, containerQuery, nodeQue
table.CursorColor = selectedTableColor

// logs of pod
logs := ui.NewTextField()
logs.Text = `TEST TextField`
logs := ui.NewParagraph()
logs.Title = "⎈ Logs ⎈"
logs.TitleStyle = titleStyle
logs.Text = `Loading...`
logs.BorderStyle = termui.NewStyle(borderColor)
logs.TextStyle = termui.NewStyle(termui.Color(244), termui.ColorClear)

// graph for cpu
Expand Down Expand Up @@ -156,7 +159,7 @@ func (m *Monitor) GetPodTable() *ui.Table {
return m.table
}

func (m *Monitor) GetLogs() *ui.TextField {
func (m *Monitor) GetLogs() *ui.Paragraph {
return m.logs
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (k *KubeClients) GetPodList(namespace string, labelSelector labels.Selector
}

func (k *KubeClients) GetPodLogs(namespace string, podName string) (string, error) {
count := int64(100)
// Tail size (number of lines)
count := int64(30)
follow := false
message := ""
podLogOptions := corev1.PodLogOptions{
//Container: containerName,
Follow: follow,
TailLines: &count,
}
Expand Down
48 changes: 48 additions & 0 deletions pkg/ui/paragraph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.

package ui

import (
"image"

. "github.com/gizak/termui/v3"
)

type Paragraph struct {
Block
Text string
TextStyle Style
WrapText bool
}

func NewParagraph() *Paragraph {
return &Paragraph{
Block: *NewBlock(),
TextStyle: Theme.Paragraph.Text,
WrapText: true,
}
}

func (self *Paragraph) Draw(buf *Buffer) {
self.Block.Draw(buf)

cells := ParseStyles(self.Text, self.TextStyle)
if self.WrapText {
cells = WrapCells(cells, uint(self.Inner.Dx()))
}

rows := SplitCells(cells, '\n')

for y, row := range rows {
if y+self.Inner.Min.Y >= self.Inner.Max.Y {
break
}
row = TrimCells(row, self.Inner.Dx())
for _, cx := range BuildCellWithXArray(row) {
x, cell := cx.X, cx.Cell
buf.SetCell(cell, image.Pt(x, y).Add(self.Inner.Min))
}
}
}

0 comments on commit 3ca97ab

Please sign in to comment.