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

Stack cells #7

Open
aspyatkin opened this issue May 14, 2015 · 9 comments
Open

Stack cells #7

aspyatkin opened this issue May 14, 2015 · 9 comments

Comments

@aspyatkin
Copy link

I suppose cells should be stacked when terminal width is not sufficient for 4 cells of each day. Now in my terminal with 90 symbols width the output is a real mess.
notstacked

@schachmat
Copy link
Owner

Correct, that is a problem. I have not researched how to reliably and portably detect terminal width in go yet. If you have some hints/ideas, let me know.

@schachmat schachmat added the bug label May 14, 2015
@certifiedloud
Copy link

+1

@BrandonRomano
Copy link

@schachmat, here's a quick program showing how you can detect terminal width.

You might have to run go get golang.org/x/crypto/ssh/terminal before running if you haven't already got this installed.

package main

import (
    "fmt"
    "golang.org/x/crypto/ssh/terminal"
)

func main() {
    width, _, _ := terminal.GetSize(0)
    fmt.Println("Width:", width)
}

Outputs for me:

Width: 159

@philadams-zz
Copy link

👍

@pavel-main
Copy link

@schachmat Take a look at this package - tablewriter

@schachmat
Copy link
Owner

tablewriter does not seem to support correct connections for the vertical and horizontal lines. Also embedding the date between the „Noon“ and „Evening“ columns can't be done.

@giuscri
Copy link

giuscri commented May 25, 2015

Apparently you can elegantly solve the problem using the core package syscall and doing an ioctl — but check the parameters you pass, to truly achieve portability among Windows, Linux and OSX (the last two ones behave differently in this case).

Check here

http://stackoverflow.com/a/16576712/2219670

and here

http://unix.stackexchange.com/a/93174/47999

@philcali
Copy link

I don't know how compatible the renderings are, but you might be able to accomplish this with TermUI?

@marcofeltmann
Copy link

marcofeltmann commented Nov 10, 2024

The package golang.org/x/crypto/ssh/terminal is deprecated.
It moved to golang.org/x/term instead.

Sample:

package main

import (
	"log/slog"
	"os"

	"golang.org/x/term"
)

func main() {
	ttyFd := int(os.Stdin.Fd())
	if !term.IsTerminal(ttyFd) {
		slog.Default().Error("Current Stdin File Descriptor is no terminal, aborting")
		os.Exit(1)
	}
	width, height, err := term.GetSize(ttyFd)
	if err != nil {
		slog.Default().Error(
			"Unable to get terminal size, aborting.",
			slog.Any("error", err),
		)
		os.Exit(1)
	}

	slog.Default().Info(
		"Detected terminal size.",
		slog.Int("columns", width),
		slog.Int("rows", height),
	)
}

Output inside vim:

:!'go' 'run' '/code/own/playground/getenv/main.go' 2>&1| tee /tmp/nvim.mafe/TSXPrG/1
2024/11/10 18:34:17 ERROR Current Stdin File Descriptor is no terminal, aborting
exit status 1

Output from within xterm-kitty on 13" notebook:

/code/own/playground/getenv [ @v1.23.2][⏱ 36s]
💀 94% [18:35:05][ 24.11.0]fsh ♥ go run .
2024/11/10 18:35:07 INFO Detected terminal size. columns=140 rows=46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants