Adjust grid layout, optimize widget placement, and refine QR Code rendering logic
This commit is contained in:
@@ -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("██")
|
||||
} else {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user