Skip to content

Paragraph, Block, and Padding#6

Open
aymanbagabas wants to merge 10 commits into
mainfrom
paragraph
Open

Paragraph, Block, and Padding#6
aymanbagabas wants to merge 10 commits into
mainfrom
paragraph

Conversation

@aymanbagabas

@aymanbagabas aymanbagabas commented Jun 2, 2025

Copy link
Copy Markdown
Contributor

This adds new Paragraph, Block and Padding types. A Paragraph is a blob of text that can be wrapped or truncated. The text can have style attributes.

A Block can wrap any component. The wrapped component inherits any style attributes defined in the Block.

image

@aymanbagabas aymanbagabas requested a review from Copilot June 2, 2025 22:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds foundational layout and component types for rendering styled text blocks with padding in terminal UIs.

  • Introduces Padding type with IsZero and Apply to adjust drawing areas.
  • Implements Paragraph component to wrap, truncate, and style text.
  • Implements Block component that applies background fill, padding, and inherited styles/links.
  • Provides an example showcasing the new types in an interactive terminal app.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
layout/padding.go New Padding struct with zero-check and area apply
component/paragraph/paragraph.go New Paragraph.Draw logic for wrapping and truncation
component/block/block.go New Block.Draw logic for background, padding, style inheritance
examples/paragraph/main.go Sample application demonstrating Paragraph and Block usage
Comments suppressed due to low confidence (1)

component/paragraph/paragraph.go:24

  • The new Draw method handles wrapping, truncation, and newline logic; consider adding unit tests covering each scenario (normal wrap, explicit newline, truncation with tail) to ensure edge cases are handled correctly.
func (p Paragraph) Draw(scr uv.Screen, area uv.Rectangle) {


pos := uv.Pos(x, y)
if pos.In(area) {
if p.Truncate && y >= area.Max.Y-1 && tailWidth > 0 && x+w > area.Max.X-tailWidth {

Copilot AI Jun 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After drawing the truncation tail, the loop continues processing original text graphemes, potentially rendering characters beyond the tail. Consider breaking out of the loop or returning after appending the tail to prevent overdraw.

Copilot uses AI. Check for mistakes.
Comment thread component/block/block.go Outdated
b.Component.Draw(scr, area)

// Apply missing style and link to the component.
for y := area.Min.Y; y < area.Max.Y; y++ {

Copilot AI Jun 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This nested loop applies style and link to each cell individually, which could be costly for large areas. Consider merging style inheritance into the main draw pass or tracking regions that actually need updates to reduce iterations.

Copilot uses AI. Check for mistakes.
Comment thread layout/padding.go Outdated
}

// Apply applies the padding to the given area and returns a new area.
func (p Padding) Apply(area uv.Rectangle) uv.Rectangle {

Copilot AI Jun 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If padding exceeds the dimensions of the provided area, area.Min may become greater than area.Max, leading to invalid rectangles. Consider clamping values or returning a zero-area rectangle to avoid unintended behavior.

Copilot uses AI. Check for mistakes.
This adds a new `paragraph` component that allows rendering paragraphs
of text with optional truncation and tail. The component can handle line
wrapping and supports styles and links.
This commit introduces a new `Block` component that allows for creating
blocks that wrap other components with optional padding.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants