Skip to content

Commit

Permalink
docs(examples): update cellbuf examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 4, 2025
1 parent 1e7ecf7 commit 6ac8339
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
16 changes: 6 additions & 10 deletions examples/cellbuf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -73,7 +70,6 @@ func main() {
w = nw
}
scr.Resize(nw, nh)
ctx.Resize(nw, nh)
render()
}

Expand All @@ -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":
Expand Down
11 changes: 5 additions & 6 deletions examples/layout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit 6ac8339

Please sign in to comment.