FXMisc / RichTextFX

Rich-text area for JavaFX
BSD 2-Clause "Simplified" License
1.19k stars 236 forks source link

Add support for terminal like caret #1121

Open PavelTurk opened 2 years ago

PavelTurk commented 2 years ago

RichTextFX is also used for building terminal emulator applications. At the same time, currently it is not possible to style caret to look like in terminals. This problem was also discussed in https://github.com/FXMisc/RichTextFX/issues/397 , but later the issue was closed without resolving.

I suggest to support the following caret features:

  1. width
  2. height
  3. shape
  4. color
  5. inverse color (for example, the color of the letter that the caret is on)
  6. caret position (it is necessary to set caret over letter)
Jugen commented 2 years ago

PRs are welcome for new features :-)

PavelTurk commented 1 month ago

@Jugen I suggested to use RichTextFX for terminalFX - https://github.com/javaterminal/TerminalFX/issues/58 It seems to me, that this issue (caret support absence) can be the only problem.

Jugen commented 1 month ago

I had a quick look at terminalFX and I don't think it'll be able to use RichTextFX because it just uses JavaFX as a view wrapper for the Javascript hterm library.

PavelTurk commented 1 month ago

@Jugen Yes, you are right. I didn't expect that they use JavaScript. It seems that JS becomes more popular in Java project (for example https://github.com/nidi3/graphviz-java) but it is not what I like. Have you ever come across a JavaFX terminal with RichTextFX? It is what I need, and I don't want to do :)

Jugen commented 1 month ago

Sorry, haven't seen a JavaFX terminal :-(

PavelTurk commented 5 days ago

@Jugen This is a link to a pure JavaFX terminal. But it wasn't made with RichTextFX as it was found out it was impossible. The main component is .. Canvas

But this issue is still actual because setting caret shape, color etc can be used in many other situations.

Jugen commented 5 days ago

For anyone interested RichTextFX currently gets its caret shape from the JavaFX TextFlow control via the caretShape method:

https://github.com/FXMisc/RichTextFX/blob/57f70b27e3ae46217c6b281b4216aec10e5afe6f/richtextfx/src/main/java/org/fxmisc/richtext/TextFlowExt.java#L55-L57

This is invoked for each caret in ParagraphText updateSingleCaret, where the RichTextFX CaretNode is an extension of Path:

https://github.com/FXMisc/RichTextFX/blob/57f70b27e3ae46217c6b281b4216aec10e5afe6f/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java#L328-L331

This the place where the caret's visible shape could be altered depending on any caret features added to CaretNode.

Note that doing this may have side affects to how RichTextFX behaves as the main caret's bounds are used in other places.