Skip to content
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

Bypassing text view and printing directly on screen using fmt.Print #914

Open
ArthurD3nt opened this issue Nov 7, 2023 · 2 comments
Open

Comments

@ArthurD3nt
Copy link

ArthurD3nt commented Nov 7, 2023

I have a simple Flex view with two panes, a sort of file explorer on the left and a markdown renderer view on the right

image

I want to use a custom renderer called glamour and (ideally) simply fmt.Print() the output of the render like it's indicated on the library's wiki.

So I basically want to avoid translating the output from ANSI to TextView using the TranslateANSI() function that defeats the purpose of using this render, is there any way I can do that?

Thanks

@rivo
Copy link
Owner

rivo commented Nov 7, 2023

So I basically want to avoid translating the output from ANSI to TextView using the TranslateANSI() function that defeats the purpose of using this render, is there any way I can do that?

This part I don't understand. It seems to me that glamour outputs ANSI escape codes. To display them in a TextView, you'll have to use TranslateANSI(). Or the ANSIWriter if you're dealing with a continuous stream of text.

@ArthurD3nt
Copy link
Author

ArthurD3nt commented Nov 7, 2023

That's what I thought at first but it seems that I lose some formatting by doing so.
By using the TranslateAnsi() function like this:

func render() *tview.TextView {

	in := `# Hello World

This is a simple example of Markdown rendering with Glamour!
Check out the [other examples](https://github.com/charmbracelet/glamour/tree/master/examples) too.

Bye!
`

	out, err := glamour.Render(string(in), "dark")
	if err != nil {
		log.Fatal(err)
	}

	view := tview.NewTextView().SetText(tview.TranslateANSI(out)).SetDynamicColors(true)

	return view
}

I get this output:
image

While I want to get this:

I read the docs of the function TranslateANSI() and as the name rightly suggests it translates the string while I want to preserve the original formatting.
Is there any way I can avoid to use textView to display the rendered result?

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

No branches or pull requests

2 participants