forked from varabyte/kotter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OSC support, add OSC 8 (anchor) support to the public api, add a …
…simple implementation in VirtualTerminal, and use in 'input' example. Fixes varabyte#84.
- Loading branch information
Showing
7 changed files
with
152 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
kotter/src/main/kotlin/com/varabyte/kotter/foundation/text/OscSupport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.varabyte.kotter.foundation.text | ||
|
||
import com.varabyte.kotter.runtime.internal.ansi.commands.AnchorCommand | ||
import com.varabyte.kotter.runtime.render.RenderScope | ||
import java.net.URI | ||
|
||
/** | ||
* Open an 'anchor' or hyperlink of [uri] in the current scope. Leaving the scope will close the anchor. | ||
*/ | ||
fun RenderScope.anchor(uri: URI) { | ||
applyCommand(AnchorCommand(uri)) | ||
} | ||
|
||
/** | ||
* Open and close an 'anchor' or hyperlink of [uri] with the given [displayText] | ||
*/ | ||
fun RenderScope.anchor(uri: URI, displayText: CharSequence) { | ||
applyCommand(AnchorCommand(uri)) | ||
text(displayText) | ||
applyCommand(AnchorCommand()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 25 additions & 1 deletion
26
kotter/src/main/kotlin/com/varabyte/kotter/runtime/internal/ansi/commands/AnsiCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
package com.varabyte.kotter.runtime.internal.ansi.commands | ||
|
||
import com.varabyte.kotter.runtime.SectionState | ||
import com.varabyte.kotter.runtime.internal.TerminalCommand | ||
import com.varabyte.kotter.runtime.internal.ansi.Ansi.Csi | ||
import com.varabyte.kotter.runtime.internal.ansi.Ansi.Osc | ||
import com.varabyte.kotter.runtime.render.Renderer | ||
import java.net.URI | ||
|
||
internal open class AnsiCommand(ansiCode: String) : TerminalCommand(ansiCode) | ||
internal open class AnsiCsiCommand(csiCode: Csi.Code) : AnsiCommand(csiCode.toFullEscapeCode()) | ||
internal open class AnsiCsiCommand(csiCode: Csi.Code) : AnsiCommand(csiCode.toFullEscapeCode()) | ||
|
||
internal open class AnsiOscCommand(oscCode: Osc.Code) : AnsiCommand(oscCode.toFullEscapeCode()) | ||
|
||
internal open class AnchorCommand(uri: URI? = null, params: Map<String, String>? = null) : | ||
AnsiOscCommand( | ||
Osc.Code( | ||
Osc.ANCHOR.id, | ||
Osc.Code.Parts( | ||
listOf( | ||
params?.map { "${it.key}=${it.value}" }?.joinToString(":") ?: "", | ||
uri?.toString() ?: "", | ||
) | ||
) | ||
) | ||
) { | ||
|
||
override fun applyTo(state: SectionState, renderer: Renderer<*>) { | ||
state.deferred.anchor = this | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters