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

Add a detection sample #126

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import com.github.ajalt.mordant.rendering.AnsiLevel
* [width] and [height] don't automatically change if the terminal is resized. Call
* [updateTerminalSize] to get the latest values.
*/
class TerminalInfo(
data class TerminalInfo(
/** The terminal width, in cells */
width: Int,
var width: Int,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change in API, but I don't see any harm in it, and I like using the data class for toString.

/** The terminal height, in cells */
height: Int,
var height: Int,
/** The level of ANSI codes to use when printing to the terminal */
var ansiLevel: AnsiLevel,
/** If true, ANSI hyperlink codes can be used */
Expand All @@ -34,14 +34,6 @@ class TerminalInfo(
*/
val crClearsLine: Boolean,
) {
/** The terminal width, in cells */
var width: Int = width
private set
/** The terminal height, in cells */
var height: Int = height
private set


/** Return true if both input and output are interactive */
val interactive: Boolean get() = inputInteractive && outputInteractive

Expand Down
3 changes: 3 additions & 0 deletions samples/detection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Detection Sample

This sample shows the detected terminal, e.g. to collect information for issue reports.
35 changes: 35 additions & 0 deletions samples/detection/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
kotlin("multiplatform")
application
}

kotlin {
jvm {
withJava()
}

macosX64()
linuxX64()
mingwX64()

targets.filterIsInstance<KotlinNativeTarget>().forEach { target ->
target.binaries.executable {
entryPoint = "com.github.ajalt.mordant.samples.main"
}
}

sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":mordant"))
}
}
}
}

application {
mainClass.set("com.github.ajalt.mordant.samples.MainKt")
applicationDefaultJvmArgs = listOf("-Dfile.encoding=utf-8")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.ajalt.mordant.samples

import com.github.ajalt.mordant.rendering.Theme
import com.github.ajalt.mordant.terminal.Terminal

fun main() {
val terminal = Terminal()
terminal.println(Theme.Default.info(terminal.info.toString()))
terminal.println(
"Theme colors: " +
"${Theme.Default.success("success")}, " +
"${Theme.Default.danger("danger")}, " +
"${Theme.Default.warning("warning")}, " +
"${Theme.Default.info("info")}, " +
"${Theme.Default.muted("muted")}"
)
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("mordant")
include("samples:detection")
include("samples:markdown")
include("samples:progress")
include("samples:table")
Expand Down