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

🖨️ A more flexible API to specify output target #150

Open
kentookura opened this issue Aug 7, 2024 · 10 comments
Open

🖨️ A more flexible API to specify output target #150

kentookura opened this issue Aug 7, 2024 · 10 comments

Comments

@kentookura
Copy link

I am experimenting with Nottui and would like to display diagnostics in my application. I am aware that terminal rendering used to be handled with notty.

From looking at the code in Tty, maybe this can be achieved by just exposing function that is a bit more flexible than display?
I'd just like to pass my own formatter here:

DiagnosticRenderer.render_diagnostic ~param fmt d;

What I tried so far:

My best guess is to write a function display : Message.t Diagnostic.t -> ui, where ui is a wrapper around the image type of Notty. I could use the optional output argument of display, but it is not obvious to me how to hook the out_channel into my application. The toplevel of the UI is started by Ui_loop.run... which takes a Notty_unix.Term.t... into which I can pass an out_channel... This seems messy.

@kentookura
Copy link
Author

I might drop Notty as well, but I am still interested in a slightly more flexible API.

@favonia
Copy link
Contributor

favonia commented Aug 8, 2024

@kentookura I agree the API is not great. The fundamental design headache is that OCaml does not provide a "universal I/O streams". Therefore, many libraries are forced to come up with their own interface to accept standard out_channel, buffers, etc. For example, the dst type in the uutf library:

https://erratique.ch/software/uutf/doc/Uutf/index.html#type-dst

I suppose we could generalize out the output in the same spirit, maybe even treating the Format.formatter as some form of (inefficient) "universal I/O streams".

@favonia
Copy link
Contributor

favonia commented Aug 8, 2024

@kentookura BTW, I don't immediately see how this can help your integration with Notty. Notty's formatter does not accept control characters at all, but we are sending out control characters directly. Therefore, if you plug Notty's formatter into the display function, it will complain about the control characters we output. Notty really wants to manage all control characters and ANSI coloring sequences does contain control characters.

@kentookura
Copy link
Author

kentookura commented Aug 8, 2024

I am no longer using Notty, so that whole headache is gone.

@favonia
Copy link
Contributor

favonia commented Aug 8, 2024

@kentookura Alright, I'm closing this as "WONTFIX" then.

@favonia favonia closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2024
@kentookura
Copy link
Author

Sure, but I am still interested in discussing a more flexible API in general.

@favonia favonia changed the title ❓ How can I display diagnostics in a Notty/Nottui application? 🖨️ A more flexible API to specify output target Aug 8, 2024
@favonia
Copy link
Contributor

favonia commented Aug 8, 2024

@kentookura Alright. In general, the difficulty is to choose this "universal output stream" type. Some libraries define their own solutions. Sadly the standard library lacks one.

@favonia favonia reopened this Aug 8, 2024
@kentookura
Copy link
Author

@jonsterling

@mikeshulman
Copy link
Collaborator

I thought I might have another use case for this, namely compiling with js_of_ocaml and hooking the output into xterm.js to run in a browser. But it turned out to work fine to just use Sys_js.set_channel_flusher on stdout.

(End result: https://mikeshulman.github.io/jsnarya/. As you can see, the ANSI colors and highlighting work fine too.)

@kentookura
Copy link
Author

Thought of this issue when reading this:

https://discuss.ocaml.org/t/an-amusing-use-of-first-class-modules-reading-from-plaintext-and-compressed-files/10073/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants