-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
106 additions
and
4 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
20 changes: 20 additions & 0 deletions
20
kotter/src/main/kotlin/com/varabyte/kotter/foundation/text/LinkSupport.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,20 @@ | ||
package com.varabyte.kotter.foundation.text | ||
|
||
import com.varabyte.kotter.runtime.internal.ansi.commands.LinkCommand | ||
import com.varabyte.kotter.runtime.render.RenderScope | ||
import java.net.URI | ||
|
||
/** | ||
* Render text backed by a link, so it can be clicked to navigate to some URI. | ||
* | ||
* Note: It is not guaranteed that this feature is supported in every terminal, so you may not want to use it if it's | ||
* really important for the user to be able to click on the URL. If the feature isn't supported, [displayText] will | ||
* be rendered as plain text. | ||
*/ | ||
fun RenderScope.link(uri: URI, displayText: String = uri.toString()) { | ||
applyCommand(LinkCommand(uri, displayText, emptyMap())) | ||
} | ||
|
||
fun RenderScope.link(uri: String, displayText: String = uri) { | ||
link(URI.create(uri), displayText) | ||
} |
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
5 changes: 4 additions & 1 deletion
5
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,10 @@ | ||
package com.varabyte.kotter.runtime.internal.ansi.commands | ||
|
||
import com.varabyte.kotter.runtime.internal.TerminalCommand | ||
import com.varabyte.kotter.runtime.internal.ansi.Ansi | ||
import com.varabyte.kotter.runtime.internal.ansi.Ansi.Csi | ||
import com.varabyte.kotter.runtime.internal.ansi.Ansi.Osc | ||
|
||
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()) |
15 changes: 15 additions & 0 deletions
15
kotter/src/main/kotlin/com/varabyte/kotter/runtime/internal/ansi/commands/LinkCommand.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,15 @@ | ||
package com.varabyte.kotter.runtime.internal.ansi.commands | ||
|
||
import com.varabyte.kotter.runtime.internal.CompositeTerminalCommand | ||
import com.varabyte.kotter.runtime.internal.ansi.Ansi | ||
import java.net.URI | ||
|
||
/** | ||
* A console command which displays a clickable link in the terminal. | ||
*/ | ||
@Suppress("FunctionName") // Function designed to look like a constructor | ||
internal fun LinkCommand(uri: URI, displayText: String, params: Map<String, String>) = CompositeTerminalCommand( | ||
AnsiOscCommand(Ansi.Osc.Codes.openLink(uri, params)), | ||
TextCommand(displayText), | ||
AnsiOscCommand(Ansi.Osc.Codes.CLOSE_LINK) | ||
) |