Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Preserve exact spacing in st.text #10055

@netnem

Description

@netnem

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

st.text behavior seems to have changed between 1.37 and the latest version (1.41) in which it no longer respects pre-formatted spacing.

Reproducible Code Example

import streamlit as st

def display_preformatted_text():
    preformatted_text = """
    Interface:      GigabitEthernet1/0/1
    MAC Address:    00:1A:2B:3C:4D:5E
    IPv4 Address:   192.168.1.10
    IPv6 Address:   fe80::1a2b:3c4d:5e6f
    User-Name:      user1
    User-Role:      admin
    Status:         active
    Domain:         example.com
    Current Policy: default
    Vlan:           10
    Device-name:    device1
    """

    st.text(preformatted_text)
    st.write(preformatted_text)
    st.code(preformatted_text,language=None )

display_preformatted_text()

Steps To Reproduce

Should be demonstrated in example code (self-evident)

Expected Behavior

Adding an option to preserve spacing like previous behavior

Current Behavior

Screenshot of before (1.37) -> (1.41):
image

While I am aware I can get similar results with st.code it does add a grey background that I can't seem to remove. An option to remove the grey background on st.code to the standard black might be sufficient too.

image

I think ideally, I would like the option to preserve spacing(old behavior) or not preserve spacing (current behavior).

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.41
  • Python version: 3.12
  • Operating System: win
  • Browser: edge

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:st.textRelated to the `st.text` elementtype:enhancementRequests for feature enhancements or new features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions