Refine widget formatting, adjust grid dimensions, and improve calendar functionality
This commit is contained in:
parent
0fc1ea476b
commit
45a8115d30
8
main.go
8
main.go
@ -79,7 +79,7 @@ func layout() []container.Option {
|
||||
),
|
||||
|
||||
grid.RowHeightFixed(25,
|
||||
grid.RowHeightFixed(23,
|
||||
grid.RowHeightFixed(19,
|
||||
grid.Widget(widgets.Get["HTTPProber"],
|
||||
container.BorderTitle("Website Status"),
|
||||
container.Border(linestyle.Light),
|
||||
@ -101,7 +101,7 @@ func layout() []container.Option {
|
||||
),
|
||||
|
||||
grid.ColWidthPerc(62,
|
||||
grid.RowHeightFixed(44,
|
||||
grid.RowHeightFixed(40,
|
||||
grid.ColWidthFixed(40,
|
||||
grid.RowHeightFixed(8,
|
||||
grid.Widget(widgets.Get["Clock"],
|
||||
@ -120,7 +120,7 @@ func layout() []container.Option {
|
||||
container.PaddingTop(1),
|
||||
),
|
||||
),
|
||||
grid.RowHeightFixed(40,
|
||||
grid.RowHeightFixed(38,
|
||||
grid.Widget(widgets.Get["PiHoleBlocked"],
|
||||
container.BorderTitle("pi-hole (Blocked Percent)"),
|
||||
container.Border(linestyle.Light),
|
||||
@ -157,7 +157,7 @@ func layout() []container.Option {
|
||||
container.PaddingTop(1),
|
||||
),
|
||||
),
|
||||
grid.RowHeightFixed(13,
|
||||
grid.RowHeightFixed(11,
|
||||
grid.Widget(widgets.Get["Weather"],
|
||||
container.BorderTitle("Weather"),
|
||||
container.Border(linestyle.Light),
|
||||
|
||||
@ -24,12 +24,12 @@ func createCalendar(ctx context.Context, _ terminalapi.Terminal, _ interface{})
|
||||
widget := util.PanicOnErrorWithResult(text.New())
|
||||
|
||||
go util.Periodic(ctx, 1*time.Hour, func() error {
|
||||
|
||||
date := time.Now()
|
||||
widget.Reset()
|
||||
if err := widget.Write("┌────────────────────┐\n", text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := widget.Write(fmt.Sprintf("│%-20s│\n", time.Now().Format("January 2006")), text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
if err := widget.Write(fmt.Sprintf("│%-20s│\n", date.Format("January 2006")), text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := widget.Write("├──┬──┬──┬──┬──┬──┬──┤\n", text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
@ -38,7 +38,7 @@ func createCalendar(ctx context.Context, _ terminalapi.Terminal, _ interface{})
|
||||
if err := createRow(widget, "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := createTableForMonth(widget); err != nil {
|
||||
if err := createTableForMonth(date, widget); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := createLowerBorder(widget); err != nil {
|
||||
@ -50,23 +50,23 @@ func createCalendar(ctx context.Context, _ terminalapi.Terminal, _ interface{})
|
||||
return widget
|
||||
}
|
||||
|
||||
func createTableForMonth(widget *text.Text) error {
|
||||
func createTableForMonth(date time.Time, widget *text.Text) error {
|
||||
table := make([]int, 0)
|
||||
now := time.Now()
|
||||
firstMonthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
firstMonthday := time.Date(date.Year(), date.Month(), 1, 0, 0, 0, 0, time.UTC)
|
||||
for range (firstMonthday.Weekday() + 6) % 7 {
|
||||
table = append(table, 0)
|
||||
}
|
||||
|
||||
//34
|
||||
//35
|
||||
for {
|
||||
day := firstMonthday.Day()
|
||||
table = append(table, day)
|
||||
firstMonthday = firstMonthday.AddDate(0, 0, 1)
|
||||
if firstMonthday.Month() != now.Month() {
|
||||
if firstMonthday.Month() != date.Month() {
|
||||
break
|
||||
}
|
||||
}
|
||||
remainingDays := 8 - len(table)/7
|
||||
remainingDays := 7 - len(table)%7
|
||||
for range remainingDays {
|
||||
table = append(table, 0)
|
||||
}
|
||||
@ -87,7 +87,7 @@ func createTableForMonth(widget *text.Text) error {
|
||||
str = fmt.Sprintf("%2d", field)
|
||||
}
|
||||
var color text.WriteOption
|
||||
if field == now.Day() {
|
||||
if field == date.Day() {
|
||||
color = text.WriteCellOpts(cell.FgColor(cell.ColorBlack), cell.BgColor(cell.ColorWhite), cell.Bold())
|
||||
} else {
|
||||
color = text.WriteCellOpts(cell.FgColor(cell.ColorWhite), cell.BgColor(cell.ColorDefault))
|
||||
|
||||
@ -34,7 +34,7 @@ func createWeather(ctx context.Context, _ terminalapi.Terminal, _ interface{}) w
|
||||
|
||||
weatherIcon := getIcon(weather.Weather[0].Icon)
|
||||
|
||||
if err := widget.Write(fmt.Sprintf("\n %s\n\n", weather.Name), text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
if err := widget.Write(fmt.Sprintf(" %s\n\n", weather.Name), text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ func createWeather(ctx context.Context, _ terminalapi.Terminal, _ interface{}) w
|
||||
} else {
|
||||
riseSet = `Sunrise: ` + time.Unix(weather.Sys.Sunrise, 0).Format("15:04")
|
||||
}
|
||||
if err := widget.Write(fmt.Sprintf(" %s\n\n", riseSet), text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
if err := widget.Write(fmt.Sprintf(" %s\n", riseSet), text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user