Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: gradual transition from standard command line application with prints() to textual app #3502

Closed
menteora opened this issue Oct 10, 2023 · 0 comments

Comments

@menteora
Copy link

Hi, I've been using this library recently, and it seems fantastic.

I would like to gradually manage the transition from a command-line app to a textual app. Therefore, I would like to convert all the initial print() statements in the old app into prints within a textual window with a header and footer. Is it possible?

from textual.app import App, ComposeResult
from textual.widgets import RichLog
from textual.widgets import Header, Footer
from textual.containers import VerticalScroll

class RichLogApp(App):
    def compose(self) -> ComposeResult:
        yield Header(self.title)
        yield Footer()
        yield VerticalScroll(
            RichLog(highlight=True, markup=True)
        )

    def print(self, message):
        text_log = self.query_one(RichLog)
        text_log.write(message)

if __name__ == "__main__":
    app = RichLogApp()
    app.run()
    app.print('your message here')
    app.print('your message here 2')

Of course, the code I've written doesn't work because the run() function is blocking the execution of the code.

Is there a way to achieve the result I'm looking for?

Thank you

@Textualize Textualize deleted a comment from github-actions bot Oct 11, 2023
@Textualize Textualize locked and limited conversation to collaborators Oct 11, 2023
@davep davep converted this issue into discussion #3505 Oct 11, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant