All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jooby.banner.Banner Maven / Gradle / Ivy

There is a newer version: 1.6.9
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.jooby.banner;

import static com.github.lalyos.jfiglet.FigletFont.convertOneLine;
import static java.util.Objects.requireNonNull;

import java.util.Optional;

import org.jooby.Env;
import org.jooby.Jooby.Module;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Binder;
import com.typesafe.config.Config;

/**
 * 

banner

*

* Prints out an ASCII art banner on startup using * jfiglet. *

* *

usage

* *
{@code
 * package com.myapp;
 *
 * {
 *   use(new Banner());
 * }
 * }
* *

* Prints out the value of application.name which here is myapp. Or you * can specify the text to prints out: *

* *
{@code
 * package com.myapp;
 *
 * {
 *   use(new Banner("my awesome app"));
 * }
 * }
* *

font

*

* You can pick and use the font of your choice via {@link #font(String)} option: *

* *
{@code
 * package com.myapp;
 *
 * {
 *   use(new Banner("my awesome app").font("slant"));
 * }
 * }
* *

* Font are distributed within the library inside the /flf classpath folder. A full * list of fonts is available here. *

* * @author edgar * @since 1.0.0.CR3 */ public class Banner implements Module { private static final String FONT = "classpath:/flf/%s.flf"; private String font = "speed"; private final Optional text; public Banner(final String text) { this.text = Optional.of(text); } public Banner() { this.text = Optional.empty(); } @Override public void configure(final Env env, final Config conf, final Binder binder) { String name = conf.getString("application.name"); Logger log = LoggerFactory.getLogger(name); String v = conf.getString("application.version"); String text = this.text.orElse(name); env.onStart( () -> log.info("\n{} v{}\n", convertOneLine(String.format(FONT, font), text).trim(), v)); } public Banner font(final String font) { this.font = requireNonNull(font, "Font is required."); return this; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy