[GH-ISSUE #881] Is it possible to increase the fontSize ? #640

Closed
opened 2026-03-04 01:06:41 +03:00 by kerem · 6 comments
Owner

Originally created by @vaibhav135 on GitHub (Sep 4, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/881

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
Originally created by @vaibhav135 on GitHub (Sep 4, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/881 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? <img width="424" alt="image" src="https://github.com/rivo/tview/assets/39329182/369c82f3-2bb1-44fe-b93b-cedb230f9593">
kerem closed this issue 2026-03-04 01:06:42 +03:00
Author
Owner

@vaibhav135 commented on GitHub (Sep 7, 2023):

@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

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 -> github.com/vilmibm/gh-chat@1112f5c5d7/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.

<!-- gh-comment-id:1709627787 --> @vaibhav135 commented on GitHub (Sep 7, 2023): @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 <img width="1440" alt="image" src="https://github.com/rivo/tview/assets/39329182/4dd6c52d-4bd5-462f-9049-ed1e1093ff95"> <details> <summary> Here is my code </summary> ```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) } } ``` </details> 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.
Author
Owner

@rivo commented on GitHub (Sep 7, 2023):

I guess you'll want to disable wrapping.

<!-- gh-comment-id:1709698932 --> @rivo commented on GitHub (Sep 7, 2023): I guess you'll want to [disable wrapping](https://pkg.go.dev/github.com/rivo/tview#TextView.SetWrap).
Author
Owner

@vaibhav135 commented on GitHub (Sep 7, 2023):

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

<!-- gh-comment-id:1710268904 --> @vaibhav135 commented on GitHub (Sep 7, 2023): @rivo unfortunately disabling wrapping didn't work. Can you show me an example of how I can use it with textview if possible.
Author
Owner

@vaibhav135 commented on GitHub (Sep 8, 2023):

@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

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
<!-- gh-comment-id:1711038527 --> @vaibhav135 commented on GitHub (Sep 8, 2023): @rivo @digitallyserviced So I was able to show the figlet text in cli using [this](https://github.com/mbndr/figlet4go) 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? <details> <summary> Here is my new code </summary> ```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) } } ``` </details> ### Here are the results :- **For simple words** :- <img width="1432" alt="image" src="https://github.com/rivo/tview/assets/39329182/72824593-a0b6-4e75-88aa-88389f7ec214"> **For long Sentences (wrapping enabled)** :- <img width="1432" alt="image" src="https://github.com/rivo/tview/assets/39329182/b853dedd-0b1a-4844-a050-37c89f9cdba3"> **For long Sentences (wrapping disabled)** :- <img width="1432" alt="image" src="https://github.com/rivo/tview/assets/39329182/b8c7d17d-2fe1-44ba-a50e-26ecf226a2a9">
Author
Owner

@rivo commented on GitHub (Sep 8, 2023):

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.

<!-- gh-comment-id:1711101123 --> @rivo commented on GitHub (Sep 8, 2023): 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.
Author
Owner

@vaibhav135 commented on GitHub (Sep 8, 2023):

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

<!-- gh-comment-id:1711164828 --> @vaibhav135 commented on GitHub (Sep 8, 2023): Got it, thanks for the info. I will close this issue now
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#640
No description provided.