diff --git a/src/main/kotlin/com/sainsburys/k2zpl/command/MediaType.kt b/src/main/kotlin/com/sainsburys/k2zpl/command/MediaType.kt new file mode 100644 index 0000000..45005c0 --- /dev/null +++ b/src/main/kotlin/com/sainsburys/k2zpl/command/MediaType.kt @@ -0,0 +1,30 @@ +package com.sainsburys.k2zpl.command + +import com.sainsburys.k2zpl.builder.ZplBuilder +import com.sainsburys.k2zpl.command.options.ZplMediaType + +internal data class MediaType( + val type: ZplMediaType, +) : ZplCommand { + override val command = "^MT" + override val parameters: ZplParameters = zplParameters( + "t" to type + ) +} + +/** + * Sets the media type for the label. + * Allows to set thermal vs. ribbon. + * + * The ^MT command selects the type of media being used in the printer. + * + * @param type The media type of the printer. + * + * [ZplMediaType.THERMAL_TRANSFER] – this media uses a high-carbon black or colored ribbon. The ink on the ribbon is bonded to the media. + * + * [ZplMediaType.DIRECT_TRANSFER] – this media is heat sensitive and requires no ribbon. + * + */ +fun ZplBuilder.mediaType(type: ZplMediaType) { + command(MediaType(type)) +} \ No newline at end of file diff --git a/src/main/kotlin/com/sainsburys/k2zpl/command/options/ZplMediaType.kt b/src/main/kotlin/com/sainsburys/k2zpl/command/options/ZplMediaType.kt new file mode 100644 index 0000000..e882343 --- /dev/null +++ b/src/main/kotlin/com/sainsburys/k2zpl/command/options/ZplMediaType.kt @@ -0,0 +1,12 @@ +@file:Suppress("UNUSED") + +package com.sainsburys.k2zpl.command.options + +enum class ZplMediaType(val value: String) { + THERMAL_TRANSFER("T"), + DIRECT_TRANSFER("D"); + + override fun toString(): String { + return value + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/sainsburys/k2zpl/command/MediaTypeTest.kt b/src/test/kotlin/com/sainsburys/k2zpl/command/MediaTypeTest.kt new file mode 100644 index 0000000..2be1561 --- /dev/null +++ b/src/test/kotlin/com/sainsburys/k2zpl/command/MediaTypeTest.kt @@ -0,0 +1,44 @@ +package com.sainsburys.k2zpl.command + +import com.sainsburys.k2zpl.command.options.ZplMediaType +import com.sainsburys.k2zpl.k2zpl +import com.sainsburys.k2zpl.testBuildString +import io.kotest.core.spec.IsolationMode +import io.kotest.core.spec.style.DescribeSpec +import io.kotest.data.forAll +import io.kotest.data.headers +import io.kotest.data.row +import io.kotest.data.table +import io.kotest.matchers.shouldBe + +class MediaTypeTest : DescribeSpec({ + + isolationMode = IsolationMode.InstancePerLeaf + + describe("MediaType") { + + val subject = MediaType(type = ZplMediaType.DIRECT_TRANSFER) + + it("outputs correct command") { + table( + headers("media type"), + ZplMediaType.entries.map { row(it) } + ).forAll { type -> + subject.copy(type = type).testBuildString() shouldBe "^MT${type}" + } + } + } + describe("mediaType extension function") { + it("outputs correct command") { + table( + headers("media type"), + ZplMediaType.entries.map { row(it) } + ).forAll { type -> + val result = k2zpl { + mediaType(type) + } + result shouldBe "^MT${type}\n" + } + } + } +})