Skip to content

failing to get term width for wrapping shouldn't be fatalΒ #39

@avivklas

Description

@avivklas

hello! I encountered an issue using this lib, looked for the source of it, and found out something that might be a wrong decision.

here's what happened to me:

  • I tried to print a box with this code:
box.New(box.Config{
	Py:            0,
	Px:            5,
	ContentAlign:  "Center",
	Type:          "Double",
	TitlePos:      "Inside",
	AllowWrapping: true,
}).Println(title, msg)
  • I started my app in a container started by docker-compose.
  • my app fataled with the message inappropriate ioctl for device
  • I looked in the code and found out that if I'm setting AllowWrapping to true and an error is returned from term.GetSize,the code calls to log.Fatal:
	// Allow Wrapping according to the user
	if b.AllowWrapping {
		// If limit not provided then use 2*TermWidth/3 as limit else
		// use the one provided
		if b.WrappingLimit != 0 {
			lines = wrap.String(lines, b.WrappingLimit)
		} else {
			width, _, err := term.GetSize(int(os.Stdout.Fd()))
			if err != nil {
				log.Fatal(err)
			}
			lines = wrap.String(lines, 2*width/3)
		}
	}

IMO, a library of such kind should not panic but return an error instead. let the user decide what to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions