Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/mikebrock/core
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Nov 21, 2011
2 parents 34b5134 + ef8433b commit fca564d
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 110 deletions.
Expand Up @@ -78,7 +78,6 @@ public synchronized void flushBuffer()
@Override
public synchronized void write(int b)
{

if (bufferSize + 1 >= maxBufferSize)
{
flushBuffer();
Expand All @@ -92,7 +91,6 @@ public synchronized void write(int b)
@Override
public synchronized void write(byte b)
{

if (bufferSize + 1 >= maxBufferSize)
{
flushBuffer();
Expand Down
227 changes: 119 additions & 108 deletions shell/src/main/java/org/jboss/forge/shell/plugins/builtin/MorePlugin.java
Expand Up @@ -35,6 +35,7 @@
import java.util.regex.Pattern;

import static org.jboss.forge.shell.util.GeneralUtils.pad;
import static org.jboss.forge.shell.util.GeneralUtils.printOutColumns;

/**
* Implementation of more & less, but called more. "More is less".
Expand All @@ -55,6 +56,7 @@ public class MorePlugin implements Plugin
private static final String RES_POS = new String(new char[]{27, '8'});
private static final String HOME = new String(new char[]{27, '[', 'H'});
private static final String ERASE_TO_END = new String(new char[]{27, '[', 'K'});
private static final String ERASE_TO_END_AND_CR = new String(new char[]{27, '[', 'K', '\n'});

private final Shell shell;

Expand Down Expand Up @@ -95,114 +97,118 @@ else if (pipeIn != null)

void more(final InputStream stream, final PipeOut out, boolean noAutoExit) throws IOException
{
try
{
byte[] buffer = new byte[128];
int read;

byte c;
byte[] buffer = new byte[2048];
int read;

byte[] outBuffer = new byte[128];
byte c;

int height = shell.getHeight() - 1;
int width = shell.getWidth();
int height = shell.getHeight() - 1;
int width = shell.getWidth();

int lCounter = width;
int y = 0;
int lCounter = width;
int y = 0;

if (noAutoExit) {
shell.clear();
}
if (noAutoExit)
{
shell.clear();
}

shell.bufferingMode();
shell.bufferingMode();

LineBuffer lineBuffer = new LineBuffer(stream, width);
StringBuilder lastPattern = new StringBuilder();
LineBuffer lineBuffer = new LineBuffer(stream, width);
StringBuilder lastPattern = new StringBuilder();

do
do
{
Mainloop:
while ((read = lineBuffer.read(buffer)) != -1)
{
Mainloop:
while ((read = lineBuffer.read(buffer)) != -1)
Bufferloop:
for (int i = 0; i < read; i++)
{
Bufferloop:
for (int i = 0; i < read; i++)
if (--lCounter <= -1)
{
if (--lCounter <= -1)
{
lineBuffer.seenLine();
lCounter = width;
++y;
}

switch (c = buffer[i])
{
case '\r':
continue Bufferloop;
case '\n':
lineBuffer.seenLine();
lCounter = width;
++y;
}
if (++y == 1) {
shell.print(ERASE_TO_END);
}

switch (c = buffer[i])
{
case '\r':
continue Bufferloop;
case '\n':
lineBuffer.seenLine();
lCounter = width;
++y;

default:
if (y >= height)
default:
if (y >= height)
{
y = height;
height = shell.getHeight() - 1;

if (statusBarCache != null)
{
y = height;
height = shell.getHeight() - 1;

shell.println();
shell.print(ERASE_TO_END);

switch (prompt(lineBuffer, out, lastPattern))
{
case -1:
y = 0;
continue Mainloop;
case -2:
y--;
continue Bufferloop;
case -3:
y = 0;
continue Bufferloop;
case 0:
noAutoExit = false;
break Mainloop;
}
shell.print(ERASE_TO_END_AND_CR + statusBarCache);
shell.flush();
}
else
{
shell.print(ERASE_TO_END_AND_CR);
}

switch (prompt(lineBuffer, out, lastPattern))
{
case -1:
y = 0;
continue Mainloop;
case -2:
y--;
continue Bufferloop;
case -3:
y = 0;
continue Bufferloop;
case 0:
noAutoExit = false;
break Mainloop;
}
}

shell.write(c);
}
}

shell.write(c);
}
}

if (noAutoExit)
if (noAutoExit)
{
switch (prompt(lineBuffer, out, lastPattern))
{
switch (prompt(lineBuffer, out, lastPattern))
{
case -1:
y = 0;
break;
case -2:
y--;
break;
case -3:
y = 0;
break;
case 0:
noAutoExit = false;
break;
}
case -1:
y = 0;
break;
case -2:
y--;
break;
case -3:
y = 0;
break;
case 0:
noAutoExit = false;
break;
}

}
while (noAutoExit);
}
finally
{
shell.directWriteMode();

}
while (noAutoExit);

}

private String statusBarCache;

private int prompt(final LineBuffer lineBuffer, final PipeOut out, final StringBuilder lastPattern)
throws IOException
Expand Down Expand Up @@ -231,20 +237,18 @@ else if (lineBuffer.atEnd())

String bottomLineReset = new Ansi().cursor(shell.getAbsoluteHeight(), 0).toString();

shell.print(bottomLineReset);
shell.print(attr(47, 30));
shell.print(prompt);
shell.print(pad(shell.getWidth() - prompt.length()));
shell.print(attr(0));
shell.print(bottomLineReset);
shell.print(attr(0));
shell.print(statusBarCache = new StringBuilder(bottomLineReset)
.append(attr(47, 30))
.append(prompt)
.append(pad(shell.getWidth() - prompt.length()))
.append(attr(0))
.append(bottomLineReset)
.append(attr(0)).toString());

shell.flush();

int scanCode = shell.scan();

shell.clearLine();

// shell.clearLine();

switch (scanCode)
{
case 'e':
Expand All @@ -269,7 +273,6 @@ else if (lineBuffer.atEnd())
case 14:
case '\n':
lineBuffer.setLineWidth(shell.getWidth());

return -2;
case ' ':
lineBuffer.setLineWidth(shell.getWidth());
Expand Down Expand Up @@ -348,15 +351,15 @@ else if (lineBuffer.atEnd())
return -1;
}
break;

case 'a':
case 'A':
shell.print(bottomLineReset);
shell.print(ShellColor.BOLD, "Less&More for JBoss Forge by Mike Brock. Copyright (c) 2011 Red Hat [Press a Key]");
shell.flush();
shell.scan();
break;

default:
shell.clearLine();
shell.cursorLeft(prompt.length());
Expand All @@ -367,7 +370,10 @@ else if (lineBuffer.atEnd())
shell.cursorLeft(INVALID_COMMAND.length() + 1);

}


}

while (true);
}

Expand Down Expand Up @@ -594,22 +600,27 @@ public boolean atEnd()
{
return bufferLine >= totalLines;
}

}

private static String attr(int... code) {
return new String(new char[]{27, '['}) + _attr(code) + "m";
private static String attr(int... code)
{
return new String(new char[]{27, '['}) + _attr(code) + "m";
}

private static String _attr(int... code) {
StringBuilder b = new StringBuilder();
boolean first = true;
for (int c : code) {
if (!first) {
b.append(';');
}
first = false;
b.append(c);
}
return b.toString();
private static String _attr(int... code)
{
StringBuilder b = new StringBuilder();
boolean first = true;
for (int c : code)
{
if (!first)
{
b.append(';');
}
first = false;
b.append(c);
}
return b.toString();
}
}

0 comments on commit fca564d

Please sign in to comment.