Adjust grid layout, optimize widget placement, and refine QR Code rendering logic
This commit is contained in:
parent
7a846ee660
commit
0fc1ea476b
76
main.go
76
main.go
@ -55,19 +55,47 @@ func layout() []container.Option {
|
|||||||
builder.Add(
|
builder.Add(
|
||||||
|
|
||||||
grid.ColWidthFixed(84,
|
grid.ColWidthFixed(84,
|
||||||
grid.RowHeightFixed(44,
|
grid.RowHeightFixed(21,
|
||||||
grid.Widget(widgets.Get["Wifi"],
|
grid.ColWidthFixed(38,
|
||||||
container.BorderTitle("Wifi"),
|
grid.RowHeightFixed(20,
|
||||||
container.Border(linestyle.Light),
|
grid.Widget(widgets.Get["Wifi"],
|
||||||
container.BorderColor(cell.ColorWhite)),
|
container.BorderTitle("Wifi"),
|
||||||
|
container.Border(linestyle.Light),
|
||||||
|
container.BorderColor(cell.ColorWhite),
|
||||||
|
container.PaddingLeft(1),
|
||||||
|
container.PaddingTop(1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
grid.ColWidthFixed(20,
|
||||||
|
grid.Widget(widgets.Get["NetworkDevices"],
|
||||||
|
container.BorderTitle("Network Devices"),
|
||||||
|
container.Border(linestyle.Light),
|
||||||
|
container.BorderColor(cell.ColorWhite),
|
||||||
|
container.PaddingLeft(1),
|
||||||
|
container.PaddingTop(1),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
grid.RowHeightFixed(46,
|
|
||||||
grid.Widget(widgets.Get["NetworkDevices"],
|
grid.RowHeightFixed(25,
|
||||||
container.BorderTitle("Network Devices"),
|
grid.RowHeightFixed(23,
|
||||||
container.Border(linestyle.Light),
|
grid.Widget(widgets.Get["HTTPProber"],
|
||||||
container.BorderColor(cell.ColorWhite),
|
container.BorderTitle("Website Status"),
|
||||||
container.PaddingLeft(1),
|
container.Border(linestyle.Light),
|
||||||
container.PaddingTop(1),
|
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),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -83,7 +111,7 @@ func layout() []container.Option {
|
|||||||
container.BorderColor(cell.ColorWhite),
|
container.BorderColor(cell.ColorWhite),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
grid.RowHeightFixed(12,
|
grid.RowHeightFixed(13,
|
||||||
grid.Widget(widgets.Get["PiHole"],
|
grid.Widget(widgets.Get["PiHole"],
|
||||||
container.BorderTitle("pi-hole"),
|
container.BorderTitle("pi-hole"),
|
||||||
container.Border(linestyle.Light),
|
container.Border(linestyle.Light),
|
||||||
@ -102,7 +130,7 @@ func layout() []container.Option {
|
|||||||
),
|
),
|
||||||
|
|
||||||
grid.ColWidthFixed(26,
|
grid.ColWidthFixed(26,
|
||||||
grid.RowHeightFixed(20,
|
grid.RowHeightFixed(21,
|
||||||
grid.Widget(widgets.Get["Calendar"],
|
grid.Widget(widgets.Get["Calendar"],
|
||||||
container.BorderTitle("Calendar"),
|
container.BorderTitle("Calendar"),
|
||||||
container.Border(linestyle.Light),
|
container.Border(linestyle.Light),
|
||||||
@ -120,7 +148,7 @@ func layout() []container.Option {
|
|||||||
),
|
),
|
||||||
|
|
||||||
grid.ColWidthFixed(25,
|
grid.ColWidthFixed(25,
|
||||||
grid.RowHeightFixed(20,
|
grid.RowHeightFixed(21,
|
||||||
grid.Widget(widgets.Get["CalendarEvents"],
|
grid.Widget(widgets.Get["CalendarEvents"],
|
||||||
container.BorderTitle("Events"),
|
container.BorderTitle("Events"),
|
||||||
container.Border(linestyle.Light),
|
container.Border(linestyle.Light),
|
||||||
@ -168,7 +196,7 @@ func layout() []container.Option {
|
|||||||
),
|
),
|
||||||
|
|
||||||
grid.ColWidthPerc(35,
|
grid.ColWidthPerc(35,
|
||||||
grid.RowHeightFixed(20,
|
grid.RowHeightFixed(21,
|
||||||
grid.Widget(widgets.Get["Zukitchi"],
|
grid.Widget(widgets.Get["Zukitchi"],
|
||||||
container.Border(linestyle.Light),
|
container.Border(linestyle.Light),
|
||||||
container.BorderColor(cell.ColorWhite),
|
container.BorderColor(cell.ColorWhite),
|
||||||
@ -176,22 +204,10 @@ func layout() []container.Option {
|
|||||||
container.PaddingLeft(1),
|
container.PaddingLeft(1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
grid.RowHeightFixed(24,
|
grid.RowHeightFixed(85,
|
||||||
grid.Widget(widgets.Get["HTTPProber"],
|
grid.Widget(widgets.Get["empty"],
|
||||||
container.BorderTitle("Website Status"),
|
|
||||||
container.Border(linestyle.Light),
|
container.Border(linestyle.Light),
|
||||||
container.BorderColor(cell.ColorWhite),
|
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 {
|
if devices[mac].Online {
|
||||||
status = cell.ColorGreen
|
status = cell.ColorGreen
|
||||||
}
|
}
|
||||||
if err := list.Write(fmt.Sprintf("|%-15s|", mac), text.WriteCellOpts(cell.FgColor(cell.ColorGray))); err != nil {
|
//if err := list.Write(fmt.Sprintf("|%-15s|", mac), text.WriteCellOpts(cell.FgColor(cell.ColorGray))); err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
//}
|
||||||
if err := list.Write(fmt.Sprintf("%2s ", devices[mac].Icon), text.WriteCellOpts(cell.BgColor(status), cell.FgColor(cell.ColorBlack))); err != nil {
|
if err := list.Write(fmt.Sprintf("%2s ", devices[mac].Icon), text.WriteCellOpts(cell.BgColor(status), cell.FgColor(cell.ColorBlack))); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,19 +25,65 @@ func QRCode(data string) QRCodeOptions {
|
|||||||
|
|
||||||
func QrCodeASCII(data string) string {
|
func QrCodeASCII(data string) string {
|
||||||
bitmap := util.PanicOnErrorWithResult(qrcode.New(data, qrcode.Low)).Bitmap()
|
bitmap := util.PanicOnErrorWithResult(qrcode.New(data, qrcode.Low)).Bitmap()
|
||||||
|
|
||||||
var stringBuilder strings.Builder
|
var stringBuilder strings.Builder
|
||||||
for y := range bitmap {
|
length := (len(bitmap)) / 2
|
||||||
for x := range bitmap[y] {
|
firstLineReached := false
|
||||||
if bitmap[y][x] {
|
lastLineReached := false
|
||||||
stringBuilder.WriteString("██")
|
firstColumnReached := false
|
||||||
} else {
|
firstColumn := 0
|
||||||
stringBuilder.WriteString(" ")
|
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()
|
return stringBuilder.String()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createQRCode(_ context.Context, _ terminalapi.Terminal, opt interface{}) widgetapi.Widget {
|
func createQRCode(_ context.Context, _ terminalapi.Terminal, opt interface{}) widgetapi.Widget {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user