Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carriage Return (\r) is rendered as space #2456

Closed
TUSF opened this issue Sep 11, 2021 · 4 comments
Closed

Carriage Return (\r) is rendered as space #2456

TUSF opened this issue Sep 11, 2021 · 4 comments
Labels
bug Something isn't working Hacktoberfest

Comments

@TUSF
Copy link

TUSF commented Sep 11, 2021

Describe the bug:

I've only tested the entry and label widgets so far, but it appears that when Fyne comes across \r, it is rendered as a space. Ideally, the application would NOT render it at all, while still potentially having the option to use \r\n for linebreaks, for compatibility with other Windows applications.

To Reproduce:

In my case, I merely edited the textedit example, and inserted this line into the Show() function:

editor.entry.SetText("A test\nwith\rcarriage return,\r\nAnd if it understands?")

I also added a \n\r into the "Cursor Row" label (which is backwards from how Windows apps normally handle it, but still demonstrates how Fyne labels handle the carriage return)

Screenshots:

image

Device (please complete the following information):

  • OS: Windows
  • Version: 10
  • Go version: 1.17
  • Fyne version: 2.0.4
@TUSF TUSF added the unverified A bug that has been reported but not verified label Sep 11, 2021
@andydotxyz andydotxyz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Sep 12, 2021
stuartmscott added a commit to stuartmscott/fyne that referenced this issue Jan 13, 2022
stuartmscott added a commit to stuartmscott/fyne that referenced this issue Jan 13, 2022
stuartmscott added a commit to stuartmscott/fyne that referenced this issue Jan 28, 2022
@julieta-311
Copy link

julieta-311 commented Feb 5, 2022

I'm having issues with carriage return as well when executing a command in the background and writing the logs into a text grid. These logs contain a progress bar with carriage return at the beginning of each line. It prints out unexpected characters that are not printed out when writing to Stdout (prints out the outcome of fmt.Println("\u001b[1A")).

carriage_return

Here is minimal code to visualise it and compare to the output in the terminal:

package main

import (
	"fmt"
	"io"
	"os"
	"time"

	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Hello World")

	t := widget.NewTextGrid()
	b := widget.NewButton("read", func() {
		pipeToTextGrid(t)
	})

	w.SetContent(container.NewVBox(t, b))
	w.ShowAndRun()
}

func pipeToTextGrid(t *widget.TextGrid) {
	r, w := io.Pipe()
	go doRead(r, t)

	// Carriage return: \u001b[1A
	w.Write([]byte("Foo:\n"))
	for {
		w.Write([]byte("\u001b[1A Bar 1"))
		time.Sleep(time.Second)
		w.Write([]byte("\u001b[1A Bar 12"))
		time.Sleep(time.Second)
		w.Write([]byte("\u001b[1A Bar 123"))
		time.Sleep(time.Second)
		w.Write([]byte("\u001b[1A Bar 1234"))
		time.Sleep(time.Second)
		w.Write([]byte("\u001b[1A Bar 12345"))
		time.Sleep(time.Second)
		w.Write([]byte("\u001b[1A Bar 123456"))
		time.Sleep(time.Second)
		w.Write([]byte("\u001b[1A Bar 1234567\n"))
	}
}

func doRead(r *io.PipeReader, t *widget.TextGrid) {
	for {
		buf := make([]byte, 50)
		n, _ := r.Read(buf)
		line := string(buf[:n])
		t.SetText(line)
		fmt.Fprintf(os.Stdout, "\n%v", line)
	}
}

Device:
OS: Manjaro Linux.
Version: DISTRIB_RELEASE=21.2.2.
Go version: 1.17.6 linux/amd64
Fyne version: v2.1.2

@andydotxyz
Copy link
Member

Your terminal interprets these control characters @julieta-311, but a text renderer does not.
You should either tell the software you are logging not to include colour code/style information or you will have to filter it in your own code. This is not a bug of our text rendering - you are asking it to print the "escape" character - which the font does not contain.

@andydotxyz
Copy link
Member

This fix was landed for Bowmore

@julieta-311
Copy link

Your terminal interprets these control characters @julieta-311, but a text renderer does not.
You should either tell the software you are logging not to include colour code/style information or you will have to filter it in your own code. This is not a bug of our text rendering - you are asking it to print the "escape" character - which the font does not contain.

Thanks for the quick response! I'm filtering it out in my code at the moment, will try your other suggestion as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants