diff --git a/pkg/ktop/ktop.go b/pkg/ktop/ktop.go index 309f9f3..8aa8b49 100644 --- a/pkg/ktop/ktop.go +++ b/pkg/ktop/ktop.go @@ -40,7 +40,7 @@ const ( type Monitor struct { *kube.KubeClients - logs *ui.TextField + logs *ui.Paragraph table *ui.Table tableTypeCircle *ring.Ring @@ -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 @@ -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 } diff --git a/pkg/kube/clients.go b/pkg/kube/clients.go index 34734af..555283c 100644 --- a/pkg/kube/clients.go +++ b/pkg/kube/clients.go @@ -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, } diff --git a/pkg/ui/paragraph.go b/pkg/ui/paragraph.go new file mode 100644 index 0000000..ef5d0cd --- /dev/null +++ b/pkg/ui/paragraph.go @@ -0,0 +1,48 @@ +// Copyright 2017 Zack Guo . 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)) + } + } +}