Skip to content

Commit

Permalink
fix: remove call to get termsize
Browse files Browse the repository at this point in the history
  • Loading branch information
jon4hz committed Feb 25, 2024
1 parent aef34f5 commit bba69c4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
6 changes: 2 additions & 4 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type Context struct {
cancel context.CancelFunc

Config *config.Config
Runtime *Runtime
Hostname *Hostname
Uptime *Uptime
Sysinfo *SysInfo
Expand All @@ -23,9 +22,9 @@ type Context struct {
Plex *Plex
}

type Runtime struct {
/* type Runtime struct {
Width, Height int
}
} */

func New() *Context {
c, cancel := context.WithTimeout(context.Background(), time.Second*30)
Expand All @@ -42,7 +41,6 @@ func New() *Context {
Systemd: new(config.Systemd),
Plex: new(config.Plex),
},
Runtime: &Runtime{},
}
}

Expand Down
11 changes: 1 addition & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@ package main
import (
"fmt"
"log"
"os"
"sync"

"github.com/charmbracelet/lipgloss"
"github.com/jon4hz/gmotd/config"
"github.com/jon4hz/gmotd/context"
"github.com/jon4hz/gmotd/message"
"golang.org/x/term"
)

func main() {
ctx := context.New()
defer ctx.Cancel()

w, h, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
log.Fatal(err)
}
ctx.Runtime.Width = w
ctx.Runtime.Height = h

for _, m := range message.Message {
d, ok := m.(message.Defaulter)
if !ok {
Expand All @@ -32,7 +23,7 @@ func main() {
d.Default(ctx)
}

err = config.Load(ctx.Config)
err := config.Load(ctx.Config)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion section/hostname/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (Section) Print(c *context.Context) string {
}
}

renderStr := figletlib.SprintMsg(c.Hostname.Hostname, f, c.Runtime.Width, f.Settings(), "left")
renderStr := figletlib.SprintMsg(c.Hostname.Hostname, f, 200, f.Settings(), "left")

colors := func() string {
colors := colorGrid(lipgloss.Width(renderStr), lipgloss.Height(renderStr))
Expand Down

0 comments on commit bba69c4

Please sign in to comment.