question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement "Log" Component

See original GitHub issue

Summary

A “Log” refers to a GUI component, often used in roguelike games to display information to the user about a variety of events.

A dedicated “Log” Component would be a useful way to easily provide this functionality in a GUI.

Example

The Orc’s attack hits! The Orc attacks you! You missed… You attacked the Orc!

Work Around

The current work around is to use a TextImage:

  1. Create TextImage for your preferred size
  2. Draw a box around it via BoxBuilder
  3. Update TextImage with each of your log messages via TextImage’s putText() method

For Example

public class Playground {

    public static void main(String[] args) {
        final Terminal terminal = TerminalBuilder.newBuilder()
                .font(CP437TilesetResource.REX_PAINT_20X20.toFont())
                .initialTerminalSize(Size.of(10, 5))
                .build();

        final TextImage img = TextImageBuilder.newBuilder()
                .size(Size.of(10, 5))
                .build(); // we create a new image to draw onto the terminal

        img.setForegroundColor(ANSITextColor.WHITE);
        img.setBackgroundColor(ANSITextColor.BLUE); // `putText` will use these

        BoxBuilder.newBuilder()
                .boxType(BoxType.DOUBLE)
                .size(Size.of(10, 5))
                .style(StyleSetBuilder.newBuilder()
                        .foregroundColor(ANSITextColor.CYAN)
                        .backgroundColor(ANSITextColor.BLUE)
                        .build())
                .build()
                .drawOnto(img, Position.DEFAULT_POSITION); // we create a box and draw it onto the image

        final List<String> logElements = new ArrayList<>();
        logElements.add("foo");
        logElements.add("bar"); // our log entries

        for(int i = 0; i < logElements.size(); i++) {
            img.putText(logElements.get(i), Position.OFFSET_1x1.withRelativeRow(i)); // we have to offset because of the box
        }

        terminal.draw(img, Position.DEFAULT_POSITION); // you have to draw each time the image changes

        terminal.flush();
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
William-Lakecommented, Oct 26, 2018

Hi All! Just saw the post on /r/roguelikedev and am so excited to see this control in Zircon! I know I’m preaching to the choir here but, great work- on everything!

0reactions
adam-aroldcommented, Oct 26, 2018

Thanks, you can now use it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Log - Apache Camel
The Log component logs message exchanges to the underlying logging mechanism. Camel uses SLF4J which allows you to configure logging via, among others:....
Read more >
Logging component
The Logging component can write to ASCII or Unicode files as well as database targets supported by OLE DB. The Logging component can...
Read more >
Adding the log component to an Angular application
ngx-logger is a simple log component library and allows messages to be displayed on the console and sent to the server using an...
Read more >
Logger in Java | Java Logging Basics with Log4j and util
The Java logging components help the developer to create logs, pass the logs to the respective destination and maintain an proper format.
Read more >
Getting Started with Logging in React - Meticulous
We all start with writing a bunch of console.log statements in our work-in-progress React components. But then, you find yourself tracking ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found