rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
11.17k stars 574 forks source link

Is it possible to increase the fontSize ? #881

Closed vaibhav135 closed 1 year ago

vaibhav135 commented 1 year ago

Hi, I am new to golang and trying to build a simple cli application. I have a question, is it is possible to increase the font-size of the text ? I tried to find anything related to this, but couldn't find any.

P.S: I also looked at a lot of apps that are using tview. It seems like none of them are using any title or heading (as in big size text). but rather this box title thing. Is this the norm that we should follow while building cli-application?

image
digitallyserviced commented 1 year ago

@vaibhav135 The font size on your terminal is defined in you terminal settings. All characters will be that font size.

Add spaces around the title, and change the color to a more prominent contrasting color from the background to help your visibility.

It is usually dependant on how you utilize the colors, space and characters to make your layouts visibily usable. Need not increase font size.

Here is someone using a figlet font module to print large text using ASCII figlet fonts.

https://github.com/vilmibm/gh-chat/blob/1112f5c5d71fe3c0e508cf55724231150a1ddff7/main.go#L20

Here I use my tdfgo library and use tview.TranslateANSI to parse the output and write it into a textview.

image

vaibhav135 commented 1 year ago

@digitallyserviced @rivo So I tried to show figlet text in textview but couldn't do it properly

Here is the result that I am getting

image
Here is my code ```golang package main import ( "fmt" "io" "os" "embed" "github.com/rivo/tview" "github.com/lukesampson/figlet/figletlib" ) //go:embed figlet-fonts/* var font embed.FS func main() { app := tview.NewApplication() textView := tview.NewTextView(). SetDynamicColors(true). SetChangedFunc(func() { app.Draw() }) textView.SetBorder(true).SetTitle("Stdin") data, err := font.ReadFile("figlet-fonts/big.flf") if err != nil { fmt.Println(err.Error()) return } f, err := figletlib.ReadFontFromBytes(data) if err != nil { fmt.Println(err.Error()) return } _, _, width, _ := textView.GetRect() message := figletlib.SprintMsg("Git is Great", f, width, f.Settings(), "left") // textView.SetText(tview.TranslateANSI(message)) -_- Tried this also but same result... textView.SetText(message) go func() { w := tview.ANSIWriter(textView) if _, err := io.Copy(w, os.Stdin); err != nil { panic(err) } }() if err := app.SetRoot(textView, true).Run(); err != nil { panic(err) } } ```

I tried to follow this code from here -> https://github.com/vilmibm/gh-chat/blob/1112f5c5d71fe3c0e508cf55724231150a1ddff7/main.go#L20

Downloaded the fonts from here -> http://www.figlet.org/fontdb.cgi

P.S. : If possible, can you guys please give an example as to how I can show the figlet text in the cli-application.

rivo commented 1 year ago

I guess you'll want to disable wrapping.

vaibhav135 commented 1 year ago

@rivo unfortunately disabling wrapping didn't work. Can you show me an example of how I can use it with textview if possible.

vaibhav135 commented 1 year ago

@rivo @digitallyserviced So I was able to show the figlet text in cli using this library. But here is the problem if I print a long sentence (wrapping enabled) the words will crumble into each other and with wrapping enabled it will go out of the screen. How do I make it so that my sentence remain in the screen viewport and don't crumble. Is there anything I am missing?

Here is my new code ```golang package main import ( "embed" "io" "os" "github.com/mbndr/figlet4go" "github.com/rivo/tview" ) //go:embed figlet-fonts/* var font embed.FS func main() { app := tview.NewApplication() textView := tview.NewTextView(). SetDynamicColors(true). SetChangedFunc(func() { app.Draw() }) textView.SetBorder(true).SetTitle("Stdin") ascii := figlet4go.NewAsciiRender() options := figlet4go.NewRenderOptions() options.FontName = "contessa" ascii.LoadFont("./figlet-fonts/bigchief.flf") renderStr, _ := ascii.RenderOpts("Git is a type of VCS, created by Linus Torvalds also the creator of Linux.", options) textView.SetWrap(false) textView.SetText(renderStr) go func() { w := tview.ANSIWriter(textView) if _, err := io.Copy(w, os.Stdin); err != nil { panic(err) } }() if err := app.SetRoot(textView, true).Run(); err != nil { panic(err) } } ```

Here are the results :-

For simple words :-

image

For long Sentences (wrapping enabled) :-

image

For long Sentences (wrapping disabled) :-

image
rivo commented 1 year ago

You're creating big letters out of characters like slashes, backslashes, and underscores. If you turn on wrapping, tview will wrap your slashes, backslashes, and underscores. It has no concept of a "big font" like this. Wrapping will always lead to problems like this.

You might have some luck using the WordWrap() function:

https://pkg.go.dev/github.com/rivo/tview#WordWrap

Wrap your text before you convert it into big letters. But (A) you'll need to know beforehand how many letters can fit your screen and (B) it will fail in some cases because this seems to be a variable-width font so results will not be consistent. For example, the "i" is more narrow than the "G".

You're trying to do something that terminal UIs are not really made for. Maybe you'll want to look into graphical user interfaces? They are much more suited for variable font sizes.

vaibhav135 commented 1 year ago

Got it, thanks for the info. I will close this issue now