From bde7ac5023ff634fb8bb282e16deab3fd477dcdf Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 3 May 2012 15:05:53 +0200 Subject: truncates the output to the width of stderr --- Truncater.java | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 Truncater.java diff --git a/Truncater.java b/Truncater.java new file mode 100644 index 0000000..a5eb99d --- /dev/null +++ b/Truncater.java @@ -0,0 +1,150 @@ +import java.io.*; + +public class Truncater +{ + public static void main(final String... args) throws IOException + { + final int width; + if ((width = getWidth()) > 15) //sanity + { + final OutputStream stdout = new BufferedOutputStream(System.out); + OutputStream out = new OutputStream() + { + /** + * The number of column on the current line + */ + private int x = 0; + + /** + * Escape sequence state + */ + private int esc = 0; + + /** + * Last bytes as written + */ + private boolean ok = true; + + + /** + * {@inheritDoc} + */ + @Override + public void write(final int b) throws IOException + { + if (this.esc == 0) + { + if (b == '\n') + { + if (x >= width) + { + write('\033'); + write('['); + write('4'); + write('9'); + write('m'); + } + this.x = -1; + } + else if (b == '\t') + { + int nx = 8 - (x & 7); + for (int i = 0; i < nx; i++) + write(' '); + return; //(!) + } + else if (b == '\033') + this.esc = 1; + } + else if (this.esc == 1) + { + if (b == '[') this.esc = 2; + else if (b == ']') this.esc = 3; + else this.esc = 10; + } + else if (this.esc == 2) + { + if ((('a' <= b) && (b <= 'z')) || (('A' <= b) && (b <= 'Z'))) + this.esc = 10; + } + else if ((this.esc == 3) && (b == 'P')) + { + this.esc = ~0; + } + else if (this.esc < 0) + { + this.esc--; + if (this.esc == ~7) + this.esc = 10; + } + else + this.esc = 10; + + if ((x < width) || (this.esc != 0) || (ok && ((b & 0xC0) == 0x80))) + { + stdout.write(b); + if (this.esc == 0) + if ((b & 0xC0) != 0x80) + x++; + ok = true; + } + else + ok = false; + if (this.esc == 10) + this.esc = 0; + } + + /** + * {@inheritDoc} + */ + @Override + public void flush() throws IOException + { + stdout.flush(); + } + }; + + System.setOut(new PrintStream(out)); + } + + + InputStream in = System.in; + OutputStream out = System.out; + + for (int d; (d = in.read()) != -1;) + out.write(d); + out.flush(); + } + + /** + * Gets the width of the terminal + * + * @return The width of the terminal + */ + public static int getWidth() + { + try + { + Process process = (new ProcessBuilder("/bin/sh", "-c", "tput cols 2> " + (new File("/dev/stderr")).getCanonicalPath())).start(); + String rcs = new String(); + InputStream stream = process.getInputStream(); + int c; + while (((c = stream.read()) != '\n') && (c != -1)) + rcs += (char)c; + try + { + stream.close(); + } + catch (final Throwable err) + { + //Ignore + } + return Integer.parseInt(rcs); + } + catch (final Throwable err) + { + return -1; + } + } +} + -- cgit From 809cbd3666abe5eb52e25d9fed49660f7d4b4565 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 3 May 2012 16:09:53 +0200 Subject: more ponies --- ponies/allie.pony | 30 ++++++++++++++++++++++++++++++ ponies/archer.pony | 22 ++++++++++++++++++++++ ponies/boxxy.pony | 29 +++++++++++++++++++++++++++++ ponies/carecake.pony | 30 ++++++++++++++++++++++++++++++ ponies/cupcake.pony | 28 ++++++++++++++++++++++++++++ ponies/daringdo.pony | 27 +++++++++++++++++++++++++++ ponies/davenport.pony | 25 +++++++++++++++++++++++++ ponies/fancypants.pony | 31 +++++++++++++++++++++++++++++++ ponies/ironwillwalk.pony | 40 ++++++++++++++++++++++++++++++++++++++++ ponies/lily.pony | 26 ++++++++++++++++++++++++++ ponies/maredowellfly.pony | 25 +++++++++++++++++++++++++ ponies/maredowellgallop.pony | 24 ++++++++++++++++++++++++ ponies/master.pony | 25 +++++++++++++++++++++++++ ponies/mjolna.pony | 26 ++++++++++++++++++++++++++ ponies/orange.pony | 25 +++++++++++++++++++++++++ ponies/raritysdad.pony | 27 +++++++++++++++++++++++++++ ponies/raritysmom.pony | 29 +++++++++++++++++++++++++++++ ponies/royalnightguard.pony | 26 ++++++++++++++++++++++++++ ponies/ruby.pony | 22 ++++++++++++++++++++++ ponies/sparkler.pony | 26 ++++++++++++++++++++++++++ ponies/violet.pony | 26 ++++++++++++++++++++++++++ 21 files changed, 569 insertions(+) create mode 100644 ponies/allie.pony create mode 100644 ponies/archer.pony create mode 100644 ponies/boxxy.pony create mode 100644 ponies/carecake.pony create mode 100644 ponies/cupcake.pony create mode 100644 ponies/daringdo.pony create mode 100644 ponies/davenport.pony create mode 100644 ponies/fancypants.pony create mode 100644 ponies/ironwillwalk.pony create mode 100644 ponies/lily.pony create mode 100644 ponies/maredowellfly.pony create mode 100644 ponies/maredowellgallop.pony create mode 100644 ponies/master.pony create mode 100644 ponies/mjolna.pony create mode 100644 ponies/orange.pony create mode 100644 ponies/raritysdad.pony create mode 100644 ponies/raritysmom.pony create mode 100644 ponies/royalnightguard.pony create mode 100644 ponies/ruby.pony create mode 100644 ponies/sparkler.pony create mode 100644 ponies/violet.pony diff --git a/ponies/allie.pony b/ponies/allie.pony new file mode 100644 index 0000000..7bd66d2 --- /dev/null +++ b/ponies/allie.pony @@ -0,0 +1,30 @@ +$the_cow =< Date: Fri, 4 May 2012 20:25:38 +0200 Subject: adding pony: lunafly --- ponies/lunafly.pony | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ponies/lunafly.pony diff --git a/ponies/lunafly.pony b/ponies/lunafly.pony new file mode 100644 index 0000000..d787ec9 --- /dev/null +++ b/ponies/lunafly.pony @@ -0,0 +1,41 @@ +$the_cow =<