/ktor-banner

Add a banner for ktor.

Primary LanguageKotlinMIT LicenseMIT

ktor-banner

Build Status GitHub release (latest by date) Maven Central Kotlin Semantic Versioning 2.0.0 Conventional Commits GitHub

ktor-banner

Add a banner for ktor.

Quick Start

fun main() {
    embeddedServer(Netty, port = 8000) {
        banner {
            bannerText = "Ktor Banner"
        }

        routing {
            get("/") {
                call.respondText("Hello, world!")
            }
        }
    }.start(wait = true)
}

This will print:

  _  ___               ____                              
 | |/ / |_ ___  _ __  | __ )  __ _ _ __  _ __   ___ _ __ 
 | ' /| __/ _ \| '__| |  _ \ / _` | '_ \| '_ \ / _ \ '__|
 | . \| || (_) | |    | |_) | (_| | | | | | | |  __/ |   
 |_|\_\\__\___/|_|    |____/ \__,_|_| |_|_| |_|\___|_|   
                                                         

Advanced usage

Fully customizable

banner {
    bannerText = "Ktor Banner"

    // custom font
    loadFigFont = {
        val inputStream = ::main.javaClass.classLoader.getResourceAsStream("starwars.flf")

        FigFont.loadFigFont(inputStream)
    }

    // custom render
    render {
        println(it.text)
    }

    // append custom footer
    beforeBanner { banner ->
        println("".padEnd(banner.width, '-'))
    }

    // append custom footer
    afterBanner { banner ->
        val title = " MyKtorApp v1.2.3 "
        val homepage = "https://yi.team/"
        val filling = "".padEnd(banner.width - title.length - homepage.length, ' ')

        println("".padEnd(banner.width, '-'))
        println("$title$filling$homepage")
    }
}

This will print:

-------------------------------------------------------------------------------------------------------------------
 __  ___ .___________.  ______   .______         .______        ___      .__   __. .__   __.  _______ .______      
|  |/  / |           | /  __  \  |   _  \        |   _  \      /   \     |  \ |  | |  \ |  | |   ____||   _  \     
|  '  /  `---|  |----`|  |  |  | |  |_)  |       |  |_)  |    /  ^  \    |   \|  | |   \|  | |  |__   |  |_)  |    
|    <       |  |     |  |  |  | |      /        |   _  <    /  /_\  \   |  . `  | |  . `  | |   __|  |      /     
|  .  \      |  |     |  `--'  | |  |\  \----.   |  |_)  |  /  _____  \  |  |\   | |  |\   | |  |____ |  |\  \----.
|__|\__\     |__|      \______/  | _| `._____|   |______/  /__/     \__\ |__| \__| |__| \__| |_______|| _| `._____|
                                                                                                                   
-------------------------------------------------------------------------------------------------------------------
 MyKtorApp v1.2.3                                                                                  https://yi.team/

Colored

fun main() {
    embeddedServer(Netty, port = 8000) {
        banner {
            bannerText = "Ktor Banner"
        }

        routing {
            get("/") {
                call.respondText("Hello, world!")
            }
        }
    }.start(wait = true)
}

This will print:

snapshot-colored.png

More fonts

see: http://www.figlet.org/

Author

@ymind, full stack engineer.

License

This is open-sourced software licensed under the MIT license.