From 6ac833958fd413262c24cd3f90b828ac4209df0f Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 4 Feb 2025 14:38:56 -0500 Subject: [PATCH] docs(examples): update cellbuf examples --- examples/cellbuf/main.go | 16 ++++++---------- examples/layout/main.go | 11 +++++------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/examples/cellbuf/main.go b/examples/cellbuf/main.go index 3262bb41..571338f4 100644 --- a/examples/cellbuf/main.go +++ b/examples/cellbuf/main.go @@ -53,17 +53,14 @@ func main() { os.Stdout.WriteString(ansi.SetMode(modes...)) //nolint:errcheck defer os.Stdout.WriteString(ansi.ResetMode(modes...)) //nolint:errcheck - x, y := 0, 0 + x, y := (w/2)-10, h/2 - ctx := scr.NewWindow(10, 5, 40, 10) render := func() { scr.Clear() - ctx.Fill(cellbuf.NewCell('你')) - text := " !Hello, world! " - ctx.SetHyperlink("https://charm.sh") - ctx.EnableAttributes(cellbuf.ReverseAttr) - ctx.MoveTo(x, y) - ctx.PrintTruncate(text, "") + scr.Fill(cellbuf.NewCell('你')) + text := ansi.SetHyperlink("https://charm.sh") + + ansi.Style{}.Reverse().Styled(" !Hello, world! ") + scr.Print(x, y, text) scr.Render() } @@ -73,7 +70,6 @@ func main() { w = nw } scr.Resize(nw, nh) - ctx.Resize(nw, nh) render() } @@ -99,7 +95,7 @@ func main() { case input.WindowSizeEvent: resize(ev.Width, ev.Height) case input.MouseClickEvent: - x, y = ev.X-10, ev.Y-5 + x, y = ev.X, ev.Y case input.KeyPressEvent: switch ev.String() { case "ctrl+c", "q": diff --git a/examples/layout/main.go b/examples/layout/main.go index 60c9d242..f4334287 100644 --- a/examples/layout/main.go +++ b/examples/layout/main.go @@ -407,14 +407,13 @@ func main() { } dialogWidth := lipgloss.Width(dialogUI) + dialogBoxStyle.GetHorizontalFrameSize() - dialogHeight := lipgloss.Height(dialogUI) + dialogBoxStyle.GetVerticalFrameSize() + // dialogHeight := lipgloss.Height(dialogUI) + dialogBoxStyle.GetVerticalFrameSize() dialogX, dialogY := physicalWidth/2-dialogWidth/2-docStyle.GetVerticalFrameSize()-1, 12 - ctx := scr.DefaultWindow() render := func() { - ctx.Clear() - ctx.SetContent(docStyle.Render(doc.String())) - box := scr.NewWindow(dialogX, dialogY, dialogWidth, dialogHeight) - box.SetContent(dialogBoxStyle.Render(dialogUI)) + scr.Clear() + scr.SetContent(docStyle.Render(doc.String())) + // box := scr.NewWindow(dialogX, dialogY, dialogWidth, dialogHeight) + // box.SetContent(dialogBoxStyle.Render(dialogUI)) scr.Render() }