pterm / pterm

✨ #PTerm is a modern Go module to easily beautify console output. Featuring charts, progressbars, tables, trees, text input, select menus and much more 🚀 It's completely configurable and 100% cross-platform compatible.

Home Page:https://pterm.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for linux 'watch' command

xsilas opened this issue · comments

commented

The linux watch command is used to run a command at an interval and display the output of the command in a refreshing terminal.
In my case i try to display a table from the pterm lib using the watch command but it seems like something with the encoding is getting messed up.
My code looks somehow like this:

func test() error {
	tableData := pterm.TableData{
		{"Firstname", "Lastname", "Email"},
		{"Paul", "Dean", "paul.dean@example.com"},
	}
	err := pterm.DefaultTable.WithData(tableData).WithHasHeader(true).WithHeaderRowSeparator("─").WithRowSeparator("─").WithBoxed(true).Render()
	if err != nil {
		return err
	}
	return nil
}

func main() {
	if err := test(); err != nil {
		log.Fatal(err)
	}
}

with the expected output:
image
however using the watch command (for example to live fetch data from apis) i see something like this:
image

Would love to see support for this in pterm as its very useful in a lot of usecases.

Hi @xsilas, by default watch does not support color output. You can enable it with the -c flag (watch -c your_command). Let me know if this fixes your problem :)

Alternatively, you could also disable the colors in PTerm, but that's probably not what you want.

commented

Thanks for the fast response, indeed this fixes it. Did not know that flag - thanks man!