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

Commit 3ca97ab

Browse files
author
Yann-Gael GAUTHERON
committed
feat: title and borders for logs
1 parent b463a5f commit 3ca97ab

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

pkg/ktop/ktop.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const (
4040
type Monitor struct {
4141
*kube.KubeClients
4242

43-
logs *ui.TextField
43+
logs *ui.Paragraph
4444
table *ui.Table
4545
tableTypeCircle *ring.Ring
4646

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

7171
// logs of pod
72-
logs := ui.NewTextField()
73-
logs.Text = `TEST TextField`
72+
logs := ui.NewParagraph()
73+
logs.Title = "⎈ Logs ⎈"
74+
logs.TitleStyle = titleStyle
75+
logs.Text = `Loading...`
76+
logs.BorderStyle = termui.NewStyle(borderColor)
7477
logs.TextStyle = termui.NewStyle(termui.Color(244), termui.ColorClear)
7578

7679
// graph for cpu
@@ -156,7 +159,7 @@ func (m *Monitor) GetPodTable() *ui.Table {
156159
return m.table
157160
}
158161

159-
func (m *Monitor) GetLogs() *ui.TextField {
162+
func (m *Monitor) GetLogs() *ui.Paragraph {
160163
return m.logs
161164
}
162165

pkg/kube/clients.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ func (k *KubeClients) GetPodList(namespace string, labelSelector labels.Selector
5656
}
5757

5858
func (k *KubeClients) GetPodLogs(namespace string, podName string) (string, error) {
59-
count := int64(100)
59+
// Tail size (number of lines)
60+
count := int64(30)
6061
follow := false
6162
message := ""
6263
podLogOptions := corev1.PodLogOptions{
63-
//Container: containerName,
6464
Follow: follow,
6565
TailLines: &count,
6666
}

pkg/ui/paragraph.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2017 Zack Guo <[email protected]>. All rights reserved.
2+
// Use of this source code is governed by a MIT license that can
3+
// be found in the LICENSE file.
4+
5+
package ui
6+
7+
import (
8+
"image"
9+
10+
. "github.com/gizak/termui/v3"
11+
)
12+
13+
type Paragraph struct {
14+
Block
15+
Text string
16+
TextStyle Style
17+
WrapText bool
18+
}
19+
20+
func NewParagraph() *Paragraph {
21+
return &Paragraph{
22+
Block: *NewBlock(),
23+
TextStyle: Theme.Paragraph.Text,
24+
WrapText: true,
25+
}
26+
}
27+
28+
func (self *Paragraph) Draw(buf *Buffer) {
29+
self.Block.Draw(buf)
30+
31+
cells := ParseStyles(self.Text, self.TextStyle)
32+
if self.WrapText {
33+
cells = WrapCells(cells, uint(self.Inner.Dx()))
34+
}
35+
36+
rows := SplitCells(cells, '\n')
37+
38+
for y, row := range rows {
39+
if y+self.Inner.Min.Y >= self.Inner.Max.Y {
40+
break
41+
}
42+
row = TrimCells(row, self.Inner.Dx())
43+
for _, cx := range BuildCellWithXArray(row) {
44+
x, cell := cx.X, cx.Cell
45+
buf.SetCell(cell, image.Pt(x, y).Add(self.Inner.Min))
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)