console

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

Console Fyne Widget

Console is a simple fyne Widget intended for logging messages to a window.

Go Reference

Screenshot

Example

A very simple usage example:

package main
import (
    "fmt"
    "time"

    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "github.com/borud/console"
)

func main() {
    app := app.New()
    win := app.NewWindow("Console test")
    win.Resize(fyne.NewSize(1000, 1000))
    
    console := console.NewConsole()
    console.ScrollToBottom = true
    console.MaxLines = 1000

    go func() {
        for i := 0; ; i++ {
            console.Append(fmt.Sprintf("This is log message %d at %s", i, time.Now().Format(time.RFC3339)))
           time.Sleep(500 * time.Millisecond)
        }
    }()

    win.SetContent(console)
    win.ShowAndRun()
}

Building example

There is a slightly more elaborate example included in cmd/console which you can build by running

make

This will produce the binary bin/console.

Caveats

Note that I'm very new to Fyne so this widget does not seem to be very performant. But if you can live with that (at least until I learn more about Fyne), by all means, use it. If you have ideas on how to improve it, I'd love to hear from you and learn. I made this mostly because I needed the functionality in an application.

You can find me on the Gophers Slack

Documentation

Overview

Package console is a simple Fyne widget for scrolling log messages. The intended use for this is

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Console

type Console struct {
	widget.BaseWidget

	// MaxLines is the maximum number of messages to keep.  Once we hit this
	// number of messages, older messages are removed.
	MaxLines int
	// ScrollToBottom will scroll the window to the latest message (bottom) when
	// a new message is appended. The default number of lines is 1000.
	ScrollToBottom bool
	// BackgroundColor is the default background color of messages.
	BackgroundColor color.Color
	// contains filtered or unexported fields
}

Console widget

func NewConsole

func NewConsole() *Console

NewConsole creates a new console widget with default MaxLines and the default message background color.

func (*Console) Append

func (c *Console) Append(msg string)

Append appends a message to the console.

func (*Console) AppendWithColor

func (c *Console) AppendWithColor(msg string, bgColor color.Color)

AppendWithColor appends a message and applies specified color to the message background.

func (*Console) Clear

func (c *Console) Clear()

Clear the console.

func (*Console) CreateRenderer

func (c *Console) CreateRenderer() fyne.WidgetRenderer

CreateRenderer returns a new renderer. Uses SimpleRenderer for now since we don't do anything fancy.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳