Adjust grid layout, optimize widget placement, and refine QR Code rendering logic
This commit is contained in:
parent
7a846ee660
commit
0fc1ea476b
58
main.go
58
main.go
@ -55,13 +55,19 @@ func layout() []container.Option {
|
||||
builder.Add(
|
||||
|
||||
grid.ColWidthFixed(84,
|
||||
grid.RowHeightFixed(44,
|
||||
grid.RowHeightFixed(21,
|
||||
grid.ColWidthFixed(38,
|
||||
grid.RowHeightFixed(20,
|
||||
grid.Widget(widgets.Get["Wifi"],
|
||||
container.BorderTitle("Wifi"),
|
||||
container.Border(linestyle.Light),
|
||||
container.BorderColor(cell.ColorWhite)),
|
||||
container.BorderColor(cell.ColorWhite),
|
||||
container.PaddingLeft(1),
|
||||
container.PaddingTop(1),
|
||||
),
|
||||
grid.RowHeightFixed(46,
|
||||
),
|
||||
),
|
||||
grid.ColWidthFixed(20,
|
||||
grid.Widget(widgets.Get["NetworkDevices"],
|
||||
container.BorderTitle("Network Devices"),
|
||||
container.Border(linestyle.Light),
|
||||
@ -72,6 +78,28 @@ func layout() []container.Option {
|
||||
),
|
||||
),
|
||||
|
||||
grid.RowHeightFixed(25,
|
||||
grid.RowHeightFixed(23,
|
||||
grid.Widget(widgets.Get["HTTPProber"],
|
||||
container.BorderTitle("Website Status"),
|
||||
container.Border(linestyle.Light),
|
||||
container.BorderColor(cell.ColorWhite),
|
||||
container.PaddingLeft(1),
|
||||
container.PaddingTop(1),
|
||||
),
|
||||
),
|
||||
grid.RowHeightFixed(40,
|
||||
grid.Widget(widgets.Get["Docker"],
|
||||
container.BorderTitle("Docker"),
|
||||
container.Border(linestyle.Light),
|
||||
container.BorderColor(cell.ColorWhite),
|
||||
container.PaddingLeft(1),
|
||||
container.PaddingTop(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
grid.ColWidthPerc(62,
|
||||
grid.RowHeightFixed(44,
|
||||
grid.ColWidthFixed(40,
|
||||
@ -83,7 +111,7 @@ func layout() []container.Option {
|
||||
container.BorderColor(cell.ColorWhite),
|
||||
),
|
||||
),
|
||||
grid.RowHeightFixed(12,
|
||||
grid.RowHeightFixed(13,
|
||||
grid.Widget(widgets.Get["PiHole"],
|
||||
container.BorderTitle("pi-hole"),
|
||||
container.Border(linestyle.Light),
|
||||
@ -102,7 +130,7 @@ func layout() []container.Option {
|
||||
),
|
||||
|
||||
grid.ColWidthFixed(26,
|
||||
grid.RowHeightFixed(20,
|
||||
grid.RowHeightFixed(21,
|
||||
grid.Widget(widgets.Get["Calendar"],
|
||||
container.BorderTitle("Calendar"),
|
||||
container.Border(linestyle.Light),
|
||||
@ -120,7 +148,7 @@ func layout() []container.Option {
|
||||
),
|
||||
|
||||
grid.ColWidthFixed(25,
|
||||
grid.RowHeightFixed(20,
|
||||
grid.RowHeightFixed(21,
|
||||
grid.Widget(widgets.Get["CalendarEvents"],
|
||||
container.BorderTitle("Events"),
|
||||
container.Border(linestyle.Light),
|
||||
@ -168,7 +196,7 @@ func layout() []container.Option {
|
||||
),
|
||||
|
||||
grid.ColWidthPerc(35,
|
||||
grid.RowHeightFixed(20,
|
||||
grid.RowHeightFixed(21,
|
||||
grid.Widget(widgets.Get["Zukitchi"],
|
||||
container.Border(linestyle.Light),
|
||||
container.BorderColor(cell.ColorWhite),
|
||||
@ -176,22 +204,10 @@ func layout() []container.Option {
|
||||
container.PaddingLeft(1),
|
||||
),
|
||||
),
|
||||
grid.RowHeightFixed(24,
|
||||
grid.Widget(widgets.Get["HTTPProber"],
|
||||
container.BorderTitle("Website Status"),
|
||||
grid.RowHeightFixed(85,
|
||||
grid.Widget(widgets.Get["empty"],
|
||||
container.Border(linestyle.Light),
|
||||
container.BorderColor(cell.ColorWhite),
|
||||
container.PaddingLeft(1),
|
||||
container.PaddingTop(1),
|
||||
),
|
||||
),
|
||||
grid.RowHeightFixed(40,
|
||||
grid.Widget(widgets.Get["Docker"],
|
||||
container.BorderTitle("Docker"),
|
||||
container.Border(linestyle.Light),
|
||||
container.BorderColor(cell.ColorWhite),
|
||||
container.PaddingLeft(1),
|
||||
container.PaddingTop(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
16
test/test.go
Normal file
16
test/test.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
lines := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
|
||||
length := (len(lines)) / 2
|
||||
for i := range length {
|
||||
fmt.Println("-")
|
||||
fmt.Printf("%d=>%d\n", lines[i*2], lines[i*2+1])
|
||||
fmt.Println("-")
|
||||
}
|
||||
if len(lines)%2 == 1 {
|
||||
fmt.Printf("%d", lines[len(lines)-1])
|
||||
}
|
||||
}
|
||||
@ -33,9 +33,9 @@ func createNetworkDevicesList(ctx context.Context, _ terminalapi.Terminal, _ int
|
||||
if devices[mac].Online {
|
||||
status = cell.ColorGreen
|
||||
}
|
||||
if err := list.Write(fmt.Sprintf("|%-15s|", mac), text.WriteCellOpts(cell.FgColor(cell.ColorGray))); err != nil {
|
||||
return err
|
||||
}
|
||||
//if err := list.Write(fmt.Sprintf("|%-15s|", mac), text.WriteCellOpts(cell.FgColor(cell.ColorGray))); err != nil {
|
||||
// return err
|
||||
//}
|
||||
if err := list.Write(fmt.Sprintf("%2s ", devices[mac].Icon), text.WriteCellOpts(cell.BgColor(status), cell.FgColor(cell.ColorBlack))); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -25,19 +25,65 @@ func QRCode(data string) QRCodeOptions {
|
||||
|
||||
func QrCodeASCII(data string) string {
|
||||
bitmap := util.PanicOnErrorWithResult(qrcode.New(data, qrcode.Low)).Bitmap()
|
||||
|
||||
var stringBuilder strings.Builder
|
||||
for y := range bitmap {
|
||||
for x := range bitmap[y] {
|
||||
if bitmap[y][x] {
|
||||
stringBuilder.WriteString("██")
|
||||
length := (len(bitmap)) / 2
|
||||
firstLineReached := false
|
||||
lastLineReached := false
|
||||
firstColumnReached := false
|
||||
firstColumn := 0
|
||||
lastColumn := 0
|
||||
for i := range length {
|
||||
if !firstLineReached {
|
||||
for x := range bitmap[i] {
|
||||
u := bitmap[i*2][x]
|
||||
firstLineReached = firstLineReached || u
|
||||
if firstLineReached && !firstColumnReached {
|
||||
firstColumn = x
|
||||
firstColumnReached = true
|
||||
}
|
||||
if firstLineReached && u {
|
||||
lastColumn = x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if firstLineReached {
|
||||
linesHaveBits := false
|
||||
for x := range bitmap[i] {
|
||||
u := bitmap[i*2][x]
|
||||
d := bitmap[i*2+1][x]
|
||||
linesHaveBits = linesHaveBits || u || !d
|
||||
}
|
||||
lastLineReached = !linesHaveBits
|
||||
if lastLineReached {
|
||||
break
|
||||
}
|
||||
if stringBuilder.Len() > 0 {
|
||||
stringBuilder.WriteByte('\n')
|
||||
}
|
||||
for x := range bitmap[i] {
|
||||
if x < firstColumn {
|
||||
continue
|
||||
}
|
||||
if x > lastColumn {
|
||||
break
|
||||
}
|
||||
u := bitmap[i*2][x]
|
||||
d := bitmap[i*2+1][x]
|
||||
if u && d {
|
||||
stringBuilder.WriteString("█")
|
||||
} else if u {
|
||||
stringBuilder.WriteString("▀")
|
||||
} else if d {
|
||||
stringBuilder.WriteString("▄")
|
||||
} else {
|
||||
stringBuilder.WriteString(" ")
|
||||
}
|
||||
}
|
||||
stringBuilder.WriteByte('\n')
|
||||
}
|
||||
}
|
||||
return stringBuilder.String()
|
||||
|
||||
}
|
||||
|
||||
func createQRCode(_ context.Context, _ terminalapi.Terminal, opt interface{}) widgetapi.Widget {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user