Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 470631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:54:16+00:00 2026-05-12T23:54:16+00:00

How do I get the terminal size in Go. In C it would look

  • 0

How do I get the terminal size in Go. In C it would look like this:

struct ttysize ts; 
ioctl(0, TIOCGWINSZ, &ts);

But how to i access TIOCGWINSZ in Go

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:54:16+00:00Added an answer on May 12, 2026 at 11:54 pm

    The cgo compiler can’t handle variable arguments in a c function and macros in c header files at present, so you can’t do a simple

    // #include <sys/ioctl.h>
    // typedef struct ttysize ttysize;
    import "C"
    
    func GetWinSz() {
        var ts C.ttysize;
        C.ioctl(0,C.TIOCGWINSZ,&ts)
    }
    

    To get around the macros use a constant, so

    // #include <sys/ioctl.h>
    // typedef struct ttysize ttysize;
    import "C"
    
    const TIOCGWINSZ C.ulong = 0x5413; // Value from Jed Smith's answer
    
    func GetWinSz() {
        var ts C.ttysize;
        C.ioctl(0,TIOCGWINSZ,&ts)
    }
    

    However cgo will still barf on the … in ioctl’s prototype. Your best bet would be to wrap ioctl with a c function taking a specific number of arguments and link that in. As a hack you can do that in the comment above import “C”

    // #include <sys/ioctl.h>
    // typedef struct ttysize ttysize;
    // void myioctl(int i, unsigned long l, ttysize * t){ioctl(i,l,t);}
    import "C"
    
    const TIOCGWINSZ C.ulong = 0x5413; // Value from Jed Smith's answer
    
    func GetWinSz() {
        var ts C.ttysize;
        C.myioctl(0,TIOCGWINSZ,&ts)
    }
    

    I’ve not tested this, but something similar should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Mechanize gem to parse html content. Firing this on terminal, agent.get(http://www.example.com/).search(.sidebar-deal-excerpt).first
I want to get the size of the current terminal, i.e. the terminal my
I have Perl code which relies on Term::ReadKey to get the terminal width. My
How can I get a single keyboard character from the terminal with Ruby without
Using Terminal.app on OS X 10.5, often you see the commands get garbled when
What is the terminal command, or where is a good resource to get them,
when compiling some projects on linux terminal, I get usually a long output consisting
I aim to filter my Google results right at terminal such that I get
I've run the following command in the Ubuntu terminal - sudo apt-get install mono-develop
I realized this sort of question is scattered all over the Internet, but nothing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.