Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Last active May 3, 2020 17:34
Show Gist options
  • Save jcoglan/4454009 to your computer and use it in GitHub Desktop.
Save jcoglan/4454009 to your computer and use it in GitHub Desktop.
// When I run `tput cols` in the shell, it prints '270'.
// When I run `tput cols` inside a Ruby program, it returns '270'.
// When I run this program, is prints '80'.
// WTF?
import java.lang.*;
import java.io.*;
public class Tput {
public static void main(String[] args) throws IOException {
ProcessBuilder pb = new ProcessBuilder("tput", "cols");
InputStream is = pb.start().getInputStream();
int bite = 0;
StringBuffer buffer = new StringBuffer();
while (bite != -1) {
bite = is.read();
buffer.append((char)bite);
}
System.out.println(buffer.toString());
}
}
@krainboltgreene
Copy link

One of the things I learned from my younger years of writing code for MUD/MUSHes is that the client WILL lie about it's width. It's just one of those things that only telnet got right, mainly because telnet was the one deciding the API for this sort of shit.

@madbonkey
Copy link

For anyone coming across this, the ProcessBuilder has an .inheritIO method on it which your can call before .start(). This will cause the documented behavior which in turn will make tput return the expected dimensions.

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