How ajalt/mordant works
This project is a Kotlin multiplatform library called Mordant, whose purpose is to provide a comprehensive set of tools for rendering styled text in terminal environments. It includes ANSI colorful output, Markdown rendering, terminal widgets (such as tables, panels, animations, etc.), and even extensions for coroutine-based animations. The source tree shows that the project is highly modular, with several submodules (for different platforms and functionalities), a dedicated build configuration (using Gradle with Kotlin DSL), build convention scripts in buildSrc, extensive tests, samples, and CI/CD configurations.
Main Components
• Build and Infrastructure Layer:
• The Gradle build system (build.gradle.kts, gradle.properties, settings.gradle.kts) and the buildSrc folder, which contains convention scripts and custom Gradle configuration files.
• CI/CD workflows located in the .github/workflows directory, as well as auxiliary files like mkdocs.yml (documentation) and scripts (for generating tables, etc.).
• Core Library Modules:
• The primary library module “mordant”, which contains the multiplatform core code (organized into commonMain, jvmMain, iosMain, jsMain, nativeMain, etc.).
• Other submodules such as “mordant-coroutines”, “mordant-markdown”, “mordant-omnibus”, and various JVM-specific modules (mordant-jvm-ffm, mordant-jvm-graal-ffi, mordant-jvm-jna) – each implemented as separate Gradle projects with their own source sets.
• Platform-Specific Implementations:
• Within the “mordant” and other modules, note the division into source sets for different targets (jvmMain, iosMain, jsMain, linuxMain, macosMain, mingwMain, and more). These represent the platform-specific implementations or adaptations.
• API and Internal Layers:
• Each module generally contains an API definition (often in an “api” directory) and the implementation. You may want to display this as a separation between public interfaces and platform-specific or internal implementations.
• Sample Applications and Tests:
• The “samples” folder contains various demonstrator projects (detection, drawing, hexviewer, markdown, progress, select, table, tour) that illustrate how to use the library.
• The “test” folder (and tests within each module) highlight the testing infrastructure, including specific CI tests for GraalVM and Proguard.
Relationships and Interactions
• For example, the samples depend on the libraries (mordant and its extensions).
• Platform-specific source sets inherit from commonMain, indicating the flow of cross-platform code to specific implementations.
• The build system and CI/CD configuration drive the entire build and deployment process.
• That several modules share a common API and are interrelated by naming conventions; for instance, “mordant-coroutines” and “mordant-markdown” extend the functionality of the core module.
Architectural Patterns and Design Principles
• Modularity: The project cleanly separates concerns across multiple Gradle subprojects and source sets (common vs. platform-specific).
• Multiplatform Strategy: The use of numerous source sets under each module illustrates how shared (commonMain) code interacts with platform-specific implementations.
• Layer Separation: Distinguish between the public API (the exported API files) and the internal implementation details, such as rendering, input handling, and terminal abstractions.
• Extensibility: Additional functionalities (like animations and Markdown rendering) are separated into their own modules, making the library extensible.
Relevant Technologies and Tools
• Kotlin Multiplatform tools, Gradle (with Kotlin DSL), and GitHub Actions for CI/CD.
• Mention the use of external repositories (e.g., Maven Central, Sonatype for snapshots) and tools for documentation (MkDocs).
• Build infrastructure (e.g., Gradle scripts, CI/CD configurations),
• Core modules (shared code),
• Platform-specific modules,
• Samples and tests.
• Optionally, include details such as API vs. internal implementations inside the modules if desired.
Final Assembly
• Next, illustrate the core library modules along with their shared common code and platform splits.
• Extension modules that further enhance functionalities (e.g., Markdown, coroutines).