gui-cs / Terminal.Gui

Cross Platform Terminal UI toolkit for .NET
MIT License
9.61k stars 686 forks source link

Support rendering web content in TUI apps - aka WebView support #2938

Open iSeiryu opened 11 months ago

iSeiryu commented 11 months ago

Is your feature request related to a problem? Please describe. View websites or render HTML strings inside a terminal. There are lots of potential uses for this feature. I'm not sure if it's even possible with the current state of dotnet without writing a whole new HTML rendering engine.

Describe the solution you'd like Either incorporate one of the existing WebView controls, e.g. https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebView/ or create a new one based on some existing engine.

Additional context Existing CLI based web browers: https://github.com/fathyb/carbonyl http://lynx.browser.org/ https://github.com/tats/w3m/tree/master/doc

tznind commented 11 months ago

This is certainly an ambitious feature.

Implementing from scratch is not really feasible, so there would need to be a library which did all the heavy lifting (web page -> ascii, scroll, request link etc). So probably a library wrapping chromium or something. Any library/binary that is directly writing to screen e.g. with curses is going to be harder to wrap.

This would make more sense as a seperate library:

The other way to deal with this would be to have your main app exit from the Terminal.Gui main loop and run a web browser (e.g. lynx) full screen in the terminal. Then on exit re-launch the terminal gui. But that would not allow you to embed

BDisp commented 11 months ago

If you want to have an idea on how to do this here is a Blazor API done for the Terminal.Gui v1. For Terminal.Gui v2 this will not be possible anymore because the ConsoleDriver and others API's isn't exposed anymore. So as @tznind said avoids any big dependencies to Terminal.Gui. Another solution is add a new project integrated with on the gui.cs and ask to tig if it's possible to do it. Good luck.

tig commented 11 months ago

If you want to have an idea on how to do this here is a Blazor API done for the Terminal.Gui v1. For Terminal.Gui v2 this will not be possible anymore because the ConsoleDriver and others API's isn't exposed anymore. So as @tznind said avoids any big dependencies to Terminal.Gui. Another solution is add a new project integrated with on the gui.cs and ask to tig if it's possible to do it. Good luck.

@bdisp the OP is not asking for Terminal.Gui apps in a browser. He/she is asking for a web browser within a Terminal.Gui app.

BDisp commented 11 months ago

@BDisp the OP is not asking for Terminal.Gui apps in a browser. He/she is asking for a web browser within a Terminal.Gui app.

Ops my bad, sorry for the misunderstand.

tig commented 11 months ago

This is certainly an ambitious feature.

Implementing from scratch is not really feasible, so there would need to be a library which did all the heavy lifting (web page -> ascii, scroll, request link etc). So probably a library wrapping chromium or something. Any library/binary that is directly writing to screen e.g. with curses is going to be harder to wrap.

This would make more sense as a seperate library:

  • Avoids adding any big dependencies to Terminal.Gui
  • Isolates issues relating to web behaviours
  • Provides dedicated channel for the work

The other way to deal with this would be to have your main app exit from the Terminal.Gui main loop and run a web browser (e.g. lynx) full screen in the terminal. Then on exit re-launch the terminal gui. But that would not allow you to embed

I have experience with .NET Html engines as part of https://github.com/tig/winprint.

I use LiteHtml to be able to print HTML files. See https://github.com/tig/winprint/tree/master/src/WinPrint.LiteHtml

99% of the cases users of WinPrint choose fixed-pitch fonts, and thus it would not be THAT hard to use LiteHtml to be able to render to a Terminal.Gui View.

iSeiryu commented 11 months ago

@tig just curious were those strings supposed to look like this or someone forgot to update them? https://github.com/tig/winprint/blob/master/src/WinPrint.LiteHtml/LibInterop.cs#L47

The rendered pages don't have to look fancy, just get a general idea of what a page looks like and to be able to read text. But rendering a single page is just a part of the problem. Being able to navigate between pages by clicking links is the bare minimum for the internet surfing.

Maybe the engine that https://github.com/fathyb/carbonyl uses could be an option? It seems very light-weight.

tig commented 11 months ago

@tig just curious were those strings supposed to look like this or someone forgot to update them? https://github.com/tig/winprint/blob/master/src/WinPrint.LiteHtml/LibInterop.cs#L47

Sorry, don't remember.

The rendered pages don't have to look fancy, just get a general idea of what a page looks like and to be able to read text. But rendering a single page is just a part of the problem. Being able to navigate between pages by clicking links is the bare minimum for the internet surfing.

Maybe the engine that https://github.com/fathyb/carbonyl uses could be an option? It seems very light-weight.

Wow. That's cool.

It's not clear to me if this is a PORT of Chromium or somehow uses Chromium??

a-usr commented 11 months ago

According to this carbonyl uses a modified version of the chromium headless shell

tig commented 10 months ago

According to this carbonyl uses a modified version of the chromium headless shell

Thinking about this more, I'm skeptical a Chromium-based solution will work well for many Terminal.Gui scenarios:

I'm back to the idea that WebView should be based on pure .NET based HTML engine like LiteHtml.

tznind commented 10 months ago

I wonder how feasible it would be to have a view that wrapped another console process (kind of like tmux). This would allow running w3c or lynx in a view as well as solving another asked for feature which is to run a full console surrounded by terminal gui components.

I know there has been work in the past on TerminalView e.g. https://github.com/migueldeicaza/XtermSharp/blob/master/GuiCsHost/TerminalView.cs which might allow something like this (see https://github.com/gui-cs/Terminal.Gui/discussions/1244#discussioncomment-671113).