Coder Social home page Coder Social logo

Comments (3)

ewels avatar ewels commented on May 19, 2024

Oh, that's super weird! Took me a moment to understand what you mean, but I get the same too by changing window width..

One line, default stays inline:
image

Two lines, default moves onto its own line:
image

This has got to be something weird with the way I'm using Rich to join these elements together. I'm using a list of renderables (can be different types, eg. Markdown and Text) within a rich Columns object currently:

# Use Columns - this allows us to group different renderable types
# (Text, Markdown) onto a single line.
return Columns(items)

@willmcgugan - any ideas why this behaviour happens? Is there a way to get around this / a better way to join these?

from rich-click.

ewels avatar ewels commented on May 19, 2024

Minimal example with pure rich code:

from rich import print
from rich.console import Console
from rich.columns import Columns
from rich.markdown import Markdown
from rich.text import Text

shortext = Text("Short text")
longtext = Text("Some long text. See there how easy that is. It's amazing what you can do with a little love in your heart. Some long text. See there how easy that is. It's amazing what you can do with a little love in your heart.")
appended = Text.from_markup("[red]APPENDED RED TEXT[/]")
print(Columns([shortext, appended]))
print("-----")
print(Columns([longtext, appended]))
$ python minimal_example.py
Short text APPENDED RED TEXT
-----
Some long text. See there how easy that is. It's amazing what you can do with a little love in your
heart. Some long text. See there how easy that is. It's amazing what you can do with a little love
in your heart.
APPENDED RED TEXT

from rich-click.

ewels avatar ewels commented on May 19, 2024

Sorry, stream of consciousness here. I guess what rich is doing makes sense - they're called columns and you can't split a vertical column if the text wraps over a line.

So to get around this we need a different approach. The columns was suggested here: Textualize/rich#1951 (reply in thread) because using Group always introduces newlines between elements.

We can't just concatenate the string and then format that, because the help text can be one of: raw text, rich markup text, markdown. The default should always be a rich Text because we want consistent styling (and can't easily do [dim] in markdown for example). We can't append Text objects because they could be Markdown.

My best idea currently is to do mytext.append() on purely Text objects if we're not using Markdown (will be the majority of users) and fall back to using a Column if markdown is enabled, with the caveat that we get this edge case ☝🏻

from rich-click.

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.