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

[#13] Add MediaType ^MT command #26

Merged
merged 3 commits into from
Oct 31, 2024
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
30 changes: 30 additions & 0 deletions src/main/kotlin/com/sainsburys/k2zpl/command/MediaType.kt
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
@@ -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
}
}
44 changes: 44 additions & 0 deletions src/test/kotlin/com/sainsburys/k2zpl/command/MediaTypeTest.kt
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
})