
Terminal manipulation toolkit: cursor control, rich color/styling (16/256/RGB) and attributes, screen/raw-mode management, event polling (keyboard, mouse, resize), command-pattern ANSI batching.
Cross-platform terminal manipulation for Kotlin Multiplatform
Installation | Quick Start | Platforms | API Reference | License
Crossterm-Kotlin is a Kotlin Multiplatform library for terminal manipulation. It is a faithful port of the Rust crossterm crate, providing cross-platform APIs for cursor control, styling, terminal management, and event handling.
| Platform | Status | Notes |
|---|---|---|
| macOS (arm64, x64) | Full | Native terminal via POSIX |
| Linux (x64) | Full | Native terminal via POSIX |
| Windows (x64) | Full | Native console API via MinGW |
| iOS | Partial | Styling only (no TTY) |
| Android | Partial | Styling only (no TTY) |
| JS/Browser | Partial | ANSI output only |
| WasmJS | Partial | ANSI output only |
dependencies {
implementation("io.github.kotlinmania:crossterm-kotlin:0.1.3")
}dependencies {
implementation 'io.github.kotlinmania:crossterm-kotlin:0.1.3'
}import io.github.kotlinmania.crossterm.cursor.*
import io.github.kotlinmania.crossterm.execute
// Move cursor to column 10, row 5
print(MoveTo(10u, 5u).ansiString())
// Hide and show cursor
print(Hide.ansiString())
print(Show.ansiString())
// Save and restore position
print(SavePosition.ansiString())
print(MoveTo(0u, 0u).ansiString())
print(RestorePosition.ansiString())import io.github.kotlinmania.crossterm.style.*
import io.github.kotlinmania.crossterm.style.types.*
// Basic colors
print(SetForegroundColor(Color.Red).ansiString())
print("Red text")
print(ResetColor.ansiString())
// RGB colors
print(SetForegroundColor(Color.Rgb(255u, 128u, 0u)).ansiString())
print("Orange text")
// 256-color palette
print(SetBackgroundColor(Color.AnsiValue(220u)).ansiString())
// Text attributes
print(SetAttribute(Attribute.Bold).ansiString())
print(SetAttribute(Attribute.Italic).ansiString())
print("Bold and italic")
print(SetAttribute(Attribute.Reset).ansiString())
// Styled content (chainable)
val styled = "Hello".stylize()
.with(Color.Cyan)
.on(Color.DarkBlue)
.bold()
.italic()import io.github.kotlinmania.crossterm.terminal.*
// Enter alternate screen buffer (like vim/less)
print(EnterAlternateScreen.ansiString())
// Clear screen
print(Clear(ClearType.All).ansiString())
// Set window title
print(SetTitle("My App").ansiString())
// Enable raw mode for character-by-character input
enableRawMode()
// ... handle input ...
disableRawMode()
// Leave alternate screen
print(LeaveAlternateScreen.ansiString())import io.github.kotlinmania.crossterm.event.*
// Enable mouse capture
print(EnableMouseCapture.ansiString())
// Poll for events with timeout
if (poll(100.milliseconds)) {
when (val event = read()) {
is Event.Key -> {
val key = event.keyEvent
when (key.code) {
is KeyCode.Char -> println("Key: ${(key.code as KeyCode.Char).char}")
KeyCode.Enter -> println("Enter pressed")
KeyCode.Esc -> println("Escape pressed")
else -> {}
}
}
is Event.Mouse -> {
val mouse = event.mouseEvent
println("Mouse ${mouse.kind} at (${mouse.column}, ${mouse.row})")
}
is Event.Resize -> {
println("Terminal resized to ${event.columns}x${event.rows}")
}
Event.FocusGained -> println("Focus gained")
Event.FocusLost -> println("Focus lost")
is Event.Paste -> println("Pasted: ${event.content}")
}
}
// Disable mouse capture
print(DisableMouseCapture.ansiString())| Module | Description |
|---|---|
io.github.kotlinmania.crossterm.cursor |
Cursor movement and visibility |
io.github.kotlinmania.crossterm.style |
Colors, attributes, and styled content |
io.github.kotlinmania.crossterm.terminal |
Screen control, raw mode, terminal info |
io.github.kotlinmania.crossterm.event |
Keyboard, mouse, and system events |
All terminal commands implement a common pattern:
interface Command {
fun ansiString(): String // Get ANSI escape sequence
fun writeAnsi(writer: Writer) // Write to a writer
}Commands can be executed individually or batched:
// Individual
print(MoveTo(0u, 0u).ansiString())
// Batched
print(execute(
MoveTo(0u, 0u),
Clear(ClearType.All),
SetForegroundColor(Color.Green)
))# Clone the repository
git clone https://github.com/KotlinMania/crossterm-kotlin.git
cd crossterm-kotlin
# Build all targets
./gradlew assemble
# Run tests
./gradlew allTests
# Build for specific platform
./gradlew macosArm64MainKlibrary
./gradlew linuxX64MainKlibrary
./gradlew mingwX64MainKlibraryContributions are welcome! Please feel free to submit issues and pull requests.
This project uses:
This Kotlin Multiplatform library is a port of the excellent crossterm Rust crate. Special thanks to Timon and the crossterm-rs maintainers for creating such a well-designed cross-platform terminal library.
This project is licensed under the MIT License.
Copyright (c) 2019 Timon (crossterm-rs)
Copyright (c) 2024-2026 Sydney Renee, The Solace Project
Maintained by Sydney Renee of The Solace Project
Part of the KotlinMania organization
Cross-platform terminal manipulation for Kotlin Multiplatform
Installation | Quick Start | Platforms | API Reference | License
Crossterm-Kotlin is a Kotlin Multiplatform library for terminal manipulation. It is a faithful port of the Rust crossterm crate, providing cross-platform APIs for cursor control, styling, terminal management, and event handling.
| Platform | Status | Notes |
|---|---|---|
| macOS (arm64, x64) | Full | Native terminal via POSIX |
| Linux (x64) | Full | Native terminal via POSIX |
| Windows (x64) | Full | Native console API via MinGW |
| iOS | Partial | Styling only (no TTY) |
| Android | Partial | Styling only (no TTY) |
| JS/Browser | Partial | ANSI output only |
| WasmJS | Partial | ANSI output only |
dependencies {
implementation("io.github.kotlinmania:crossterm-kotlin:0.1.3")
}dependencies {
implementation 'io.github.kotlinmania:crossterm-kotlin:0.1.3'
}import io.github.kotlinmania.crossterm.cursor.*
import io.github.kotlinmania.crossterm.execute
// Move cursor to column 10, row 5
print(MoveTo(10u, 5u).ansiString())
// Hide and show cursor
print(Hide.ansiString())
print(Show.ansiString())
// Save and restore position
print(SavePosition.ansiString())
print(MoveTo(0u, 0u).ansiString())
print(RestorePosition.ansiString())import io.github.kotlinmania.crossterm.style.*
import io.github.kotlinmania.crossterm.style.types.*
// Basic colors
print(SetForegroundColor(Color.Red).ansiString())
print("Red text")
print(ResetColor.ansiString())
// RGB colors
print(SetForegroundColor(Color.Rgb(255u, 128u, 0u)).ansiString())
print("Orange text")
// 256-color palette
print(SetBackgroundColor(Color.AnsiValue(220u)).ansiString())
// Text attributes
print(SetAttribute(Attribute.Bold).ansiString())
print(SetAttribute(Attribute.Italic).ansiString())
print("Bold and italic")
print(SetAttribute(Attribute.Reset).ansiString())
// Styled content (chainable)
val styled = "Hello".stylize()
.with(Color.Cyan)
.on(Color.DarkBlue)
.bold()
.italic()import io.github.kotlinmania.crossterm.terminal.*
// Enter alternate screen buffer (like vim/less)
print(EnterAlternateScreen.ansiString())
// Clear screen
print(Clear(ClearType.All).ansiString())
// Set window title
print(SetTitle("My App").ansiString())
// Enable raw mode for character-by-character input
enableRawMode()
// ... handle input ...
disableRawMode()
// Leave alternate screen
print(LeaveAlternateScreen.ansiString())import io.github.kotlinmania.crossterm.event.*
// Enable mouse capture
print(EnableMouseCapture.ansiString())
// Poll for events with timeout
if (poll(100.milliseconds)) {
when (val event = read()) {
is Event.Key -> {
val key = event.keyEvent
when (key.code) {
is KeyCode.Char -> println("Key: ${(key.code as KeyCode.Char).char}")
KeyCode.Enter -> println("Enter pressed")
KeyCode.Esc -> println("Escape pressed")
else -> {}
}
}
is Event.Mouse -> {
val mouse = event.mouseEvent
println("Mouse ${mouse.kind} at (${mouse.column}, ${mouse.row})")
}
is Event.Resize -> {
println("Terminal resized to ${event.columns}x${event.rows}")
}
Event.FocusGained -> println("Focus gained")
Event.FocusLost -> println("Focus lost")
is Event.Paste -> println("Pasted: ${event.content}")
}
}
// Disable mouse capture
print(DisableMouseCapture.ansiString())| Module | Description |
|---|---|
io.github.kotlinmania.crossterm.cursor |
Cursor movement and visibility |
io.github.kotlinmania.crossterm.style |
Colors, attributes, and styled content |
io.github.kotlinmania.crossterm.terminal |
Screen control, raw mode, terminal info |
io.github.kotlinmania.crossterm.event |
Keyboard, mouse, and system events |
All terminal commands implement a common pattern:
interface Command {
fun ansiString(): String // Get ANSI escape sequence
fun writeAnsi(writer: Writer) // Write to a writer
}Commands can be executed individually or batched:
// Individual
print(MoveTo(0u, 0u).ansiString())
// Batched
print(execute(
MoveTo(0u, 0u),
Clear(ClearType.All),
SetForegroundColor(Color.Green)
))# Clone the repository
git clone https://github.com/KotlinMania/crossterm-kotlin.git
cd crossterm-kotlin
# Build all targets
./gradlew assemble
# Run tests
./gradlew allTests
# Build for specific platform
./gradlew macosArm64MainKlibrary
./gradlew linuxX64MainKlibrary
./gradlew mingwX64MainKlibraryContributions are welcome! Please feel free to submit issues and pull requests.
This project uses:
This Kotlin Multiplatform library is a port of the excellent crossterm Rust crate. Special thanks to Timon and the crossterm-rs maintainers for creating such a well-designed cross-platform terminal library.
This project is licensed under the MIT License.
Copyright (c) 2019 Timon (crossterm-rs)
Copyright (c) 2024-2026 Sydney Renee, The Solace Project
Maintained by Sydney Renee of The Solace Project
Part of the KotlinMania organization