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

Bottom line in box takes the FG color of the last line in table #221

Closed
jeanfrancoisgratton opened this issue Aug 21, 2022 · 7 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@jeanfrancoisgratton
Copy link

jeanfrancoisgratton commented Aug 21, 2022

Description
When changing the fore/background colors of rows in a table, the bottom line in the box enclosing the table takes that FG+BG value

To Reproduce
See code way below, with explanations

Expected behavior
Bottom border should be the same as the rest of the borders

Screenshots
image

Software (please complete the following information):

  • OS: Linux (Ubuntu 22.04.01, fully updated)
  • GoLang Version 1.19 (manual install, not taking the .deb package from distro)

Additional context
A simple libvirtd client; a port of my Python3 current client. I want the "Running" VMs to be displayed in green, at the bottom of the list, but the bottom border keeps the last line's colors.

Here's my function that displays the VMs with their various states. The struct vmspecs holds all of the various VMs stats (I've snipped part of the code where not pertinent to issue)

func VM_List() {
	var vmspecs = collectInfo()

	t := table.NewWriter()
	t.SetOutputMirror(os.Stdout)
	t.AppendHeader((table.Row{"ID", "VM name", "State", "vMemory", "vCPUs", "Snapshots", "Curr snapshot", "iface name", "IP address"}))
	for _, vmspec := range vmspecs {
		sID := ""
		if vmspec.viId > 0 && vmspec.viId < 10 {
			sID = fmt.Sprintf("000%d", vmspec.viId)
		
		<SNIP>
		
		t.AppendRow([]interface{}{sID, vmspec.viName, vmspec.viState, vmspec.viMem, vmspec.viCpu, vmspec.viSnapshot, vmspec.viCurrentSnapshot, vmspec.viInterfaceName, vmspec.viIPaddress})
	}
	t.SortBy([]table.SortBy{
		{Name: "ID", Mode: table.Asc},
		{Name: "VM name", Mode: table.Asc},
	})
	t.SetStyle(table.StyleBold)
	//t.Style().Options.DrawBorder = false
	//t.Style().Options.SeparateColumns = false
	t.Style().Format.Header = text.FormatDefault
	t.SetRowPainter(table.RowPainter(func(row table.Row) text.Colors {
		switch row[2] {
		case "Running":
			return text.Colors{text.BgBlack, text.FgHiGreen}
		case "Crashed":
			return text.Colors{text.BgBlack, text.FgHiRed}
		case "Blocked":
		case "Suspended":
		case "Paused":
			return text.Colors{text.BgHiBlack, text.FgHiYellow}
		}
		return nil
	}))
	t.Render()
}

This is my very first Go software; to learn a language you need your own project, right, so I'm porting my Python3 tool to Go, so bear with me if you see glaring coding errors.
For all I know, I might be missing something obvious in your package usage.

@jedib0t
Copy link
Owner

jedib0t commented Aug 21, 2022

Thanks for the bug report and the compliments. Sounds like the Row Painter is being invoked for the separator/border incorrectly. I'll look into this tomorrow.

@jeanfrancoisgratton
Copy link
Author

jeanfrancoisgratton commented Aug 21, 2022

Looks like I've erased the compliment (I wanted to put it in the main report). You got it, that's all that matters.

No worry, I can live with the issue for now. Let me know if my report needs more info.

@jedib0t
Copy link
Owner

jedib0t commented Aug 21, 2022

Hey @jeanfrancoisgratton --- the latest code in the main branch has the fix. If you can verify with it, I can cut a tag for you.

@jeanfrancoisgratton
Copy link
Author

jeanfrancoisgratton commented Aug 21, 2022

@jedib0t , this might seem a bit of a stupid question, but remember, this is about my first full-fledged GO software.

How do I go about removing earlier versions of github.com/jedib0t/go-pretty/v6 from go.mod ?
I've erased go.{mod,sum} and $HOME/go/pkg/, go mod init vmman3, go mod tidy, it comes back with the "old" code when I build.

Thanks for your patience... I feel dumb.

@jedib0t jedib0t added the bug Something isn't working label Aug 22, 2022
@jedib0t jedib0t self-assigned this Aug 22, 2022
@jedib0t
Copy link
Owner

jedib0t commented Aug 22, 2022

@jedib0t
Copy link
Owner

jedib0t commented Aug 22, 2022

@jedib0t , this might seem a bit of a stupid question, but remember, this is about my first full-fledged GO software.

How do I go about removing earlier versions of github.com/jedib0t/go-pretty/v6 from go.mod ? I've erased go.{mod,sum} and $HOME/go/pkg/, go mod init vmman3, go mod tidy, it comes back with the "old" code when I build.

Thanks for your patience... I feel dumb.

Hey! Don't feel bad. go mod is not straightforward... Try using the following command:

go get github.com/jedib0t/go-pretty/v6@v6.3.7

This should fix go.mod to have just one version of go-pretty, and a go mod tidy should clean up your go.sum file.

@jeanfrancoisgratton
Copy link
Author

Well, I was expecting the update to show up before you tagged the version, so I was a bit dumb :)

Changed v6.3.6 to v6.3.7 in go.mod once you tagged the repo, go mod tidy, go build and here we go, I can confirm the fix.
Thanks for the quick replies+fix.

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

No branches or pull requests

2 participants