Git Product home page Git Product logo

Comments (4)

meowgorithm avatar meowgorithm commented on July 17, 2024 4

Hi! Bubble Tea checks the window size for you, but it's your responsibility to wrap or trim your lines. Listen for tea.WindowSizeMsg in Update and then trim or wrap your strings accordingly. I recommend the reflow package for doing word wrapping as it works nicely with ANSI-formatted strings. Note that WindowSizeMsg is sent before the first render and then again every resize.

So in update:

switch msg := msg.(type) {
case tea.WindowSizeMsg:
    model.width = msg.width
    model.height = msg.height // height is available too
}

And then in your view:

import "github.com/muesli/reflow/wordwrap"

func (m model) View() string {
    return wordwrap.String(m.bigLongString, m.width)
}

from bubbletea.

hbollon avatar hbollon commented on July 17, 2024 1

Nice ! I didn't know about WindowSizeMsg, it's really cool!
And I will follow your advice for the maximum width 👍
Thanks mate!

from bubbletea.

Dentrax avatar Dentrax commented on July 17, 2024 1

Hey @meowgorithm, I have an exact same issue but for terminal height instead. I fill a bytes.Buffer that exceeds my terminal height and have some overlapping, overdrawing issues. Should I file a new issue for this? Display issue when line content is greater than terminal height

from bubbletea.

meowgorithm avatar meowgorithm commented on July 17, 2024

Also, I personally like to set a max width when word wrapping for readability, so I'd probably do something like:

const maxWidth = 80

func (m model) View() string {
    return wordwrap.String(m.bigLongString, min(m.width, maxWidth))
}

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}

from bubbletea.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.