roff-kotlin

Generate ROFF man pages programmatically using an abstract document model, inline styles, control directives, text-formatting helpers, and safe rendering with apostrophe handling.

Kotlin/Native
GitHub stars0
Open issues0
LicenseApache License 2.0
Creation date4 months ago

Last activity3 months ago
Latest release0.1.0 (4 months ago)

roff-kotlin

Kotlin License GitHub

A Kotlin Multiplatform Native library for generating documents in the ROFF format (man pages). This is a port of the Rust roff-rs library.

Overview

ROFF is a family of Unix text-formatting languages, implemented by the nroff, troff, and groff programs. This library provides an abstract representation of ROFF documents, making it easy to generate manual pages programmatically.

Supported Platforms

  • macOS (arm64, x64)
  • Linux (x64)
  • Windows (x64 via MinGW)

Installation

As a Git Submodule (Recommended)

This library is not yet published to Maven Central. The recommended approach is to include it as a git submodule or vendored dependency:

git submodule add https://github.com/KotlinMania/roff-kotlin.git

Then in your settings.gradle.kts:

include(":roff-kotlin")

And in your module's build.gradle.kts:

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(project(":roff-kotlin"))
            }
        }
    }
}

Quick Start

import roff.*

val page = Roff()
    .control("TH", "CORRUPT", "1")
    .control("SH", "NAME")
    .text(roman("corrupt - modify files by randomly changing bits"))
    .control("SH", "SYNOPSIS")
    .text(
        bold("corrupt"), " [".toInline(), bold("-n"), " ".toInline(),
        italic("BITS"), "] [".toInline(), bold("--bits"), " ".toInline(),
        italic("BITS"), "] ".toInline(), italic("FILE"), "...".toInline()
    )
    .control("SH", "DESCRIPTION")
    .text(bold("corrupt"), " modifies files by toggling a randomly chosen bit.".toInline())
    .control("SH", "OPTIONS")
    .control("TP")
    .text(bold("-n"), ", ".toInline(), bold("--bits"), "=".toInline(), italic("BITS"))
    .text(roman("Set the number of bits to modify. Default is one bit."))
    .render()

print(page)

API

Creating Documents

val doc = Roff()
    .control("TH", "NAME", "SECTION")  // Control line with arguments
    .text(roman("Plain text"))          // Text line
    .render()                            // Render with apostrophe handling

Inline Styles

  • roman("text") - Normal (roman) font
  • bold("text") - Bold font
  • italic("text") - Italic font
  • lineBreak() - Hard line break
  • "text".toInline() - Convert string to roman inline

Rendering

  • render() - Render with apostrophe preamble (recommended for man pages)
  • toRoff() - Render without apostrophe handling (for testing)

License

Licensed under either of:

at your option.


Acknowledgments

This Kotlin Multiplatform port was created by Sydney Renee of The Solace Project for KotlinMania.

Special thanks to the original authors:

Kotlin/Native
GitHub stars0
Open issues0
LicenseApache License 2.0
Creation date4 months ago

Last activity3 months ago
Latest release0.1.0 (4 months ago)

roff-kotlin

Kotlin License GitHub

A Kotlin Multiplatform Native library for generating documents in the ROFF format (man pages). This is a port of the Rust roff-rs library.

Overview

ROFF is a family of Unix text-formatting languages, implemented by the nroff, troff, and groff programs. This library provides an abstract representation of ROFF documents, making it easy to generate manual pages programmatically.

Supported Platforms

  • macOS (arm64, x64)
  • Linux (x64)
  • Windows (x64 via MinGW)

Installation

As a Git Submodule (Recommended)

This library is not yet published to Maven Central. The recommended approach is to include it as a git submodule or vendored dependency:

git submodule add https://github.com/KotlinMania/roff-kotlin.git

Then in your settings.gradle.kts:

include(":roff-kotlin")

And in your module's build.gradle.kts:

kotlin {
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(project(":roff-kotlin"))
            }
        }
    }
}

Quick Start

import roff.*

val page = Roff()
    .control("TH", "CORRUPT", "1")
    .control("SH", "NAME")
    .text(roman("corrupt - modify files by randomly changing bits"))
    .control("SH", "SYNOPSIS")
    .text(
        bold("corrupt"), " [".toInline(), bold("-n"), " ".toInline(),
        italic("BITS"), "] [".toInline(), bold("--bits"), " ".toInline(),
        italic("BITS"), "] ".toInline(), italic("FILE"), "...".toInline()
    )
    .control("SH", "DESCRIPTION")
    .text(bold("corrupt"), " modifies files by toggling a randomly chosen bit.".toInline())
    .control("SH", "OPTIONS")
    .control("TP")
    .text(bold("-n"), ", ".toInline(), bold("--bits"), "=".toInline(), italic("BITS"))
    .text(roman("Set the number of bits to modify. Default is one bit."))
    .render()

print(page)

API

Creating Documents

val doc = Roff()
    .control("TH", "NAME", "SECTION")  // Control line with arguments
    .text(roman("Plain text"))          // Text line
    .render()                            // Render with apostrophe handling

Inline Styles

  • roman("text") - Normal (roman) font
  • bold("text") - Bold font
  • italic("text") - Italic font
  • lineBreak() - Hard line break
  • "text".toInline() - Convert string to roman inline

Rendering

  • render() - Render with apostrophe preamble (recommended for man pages)
  • toRoff() - Render without apostrophe handling (for testing)

License

Licensed under either of:

at your option.


Acknowledgments

This Kotlin Multiplatform port was created by Sydney Renee of The Solace Project for KotlinMania.

Special thanks to the original authors: