|
From: SVN by r. <sv...@ca...> - 2008-07-31 07:59:19
|
Author: roy
Date: 2008-07-31 09:59:08 +0200 (Thu, 31 Jul 2008)
New Revision: 275
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
Log:
some threading fixes
fix 'case sensitive table names' when using tabcompletion
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-07-28 20:59:50 UTC (rev 274)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-07-31 07:59:08 UTC (rev 275)
@@ -403,6 +403,7 @@
@Override
void execute() {
output(getCommand().execute(cmd.sql));
+ repaint();
}
};
commandThread.start();
@@ -421,10 +422,12 @@
public abstract int getScreenWidth();
public abstract int getScreenHeight();
- protected synchronized void repaint() {
+ protected void repaint() {
if (paint) {
try {
- paint(screen);
+ synchronized(this) {
+ paint(screen);
+ }
} catch(Throwable t) {
error(t);
}
@@ -645,25 +648,29 @@
* Output data to the screen.
* @param data the data to print to the screen.
*/
- protected synchronized void output(List<? extends CharSequence> data) {
- for(CharSequence c : data) {
- output(c);
+ protected void output(List<? extends CharSequence> data) {
+ synchronized(this) {
+ for(CharSequence c : data) {
+ output(c);
+ }
}
}
/**
* Output data to the screen.
* @param data the data to print to the screen.
*/
- protected synchronized void output(CharSequence data) {
- List<CharSequence> screenBuffer = screen.getScreenBuffer();
- screenBuffer.addAll(getLines(data));
- if (spoolWriter != null) {
- try {
- spoolWriter.write(data.toString());
- spoolWriter.write("\n");
- } catch(IOException e) {
- screenBuffer.add("WARNING: Could not write to spool file");
- error(e);
+ protected void output(CharSequence data) {
+ synchronized(this) {
+ List<CharSequence> screenBuffer = screen.getScreenBuffer();
+ screenBuffer.addAll(getLines(data));
+ if (spoolWriter != null) {
+ try {
+ spoolWriter.write(data.toString());
+ spoolWriter.write("\n");
+ } catch(IOException e) {
+ screenBuffer.add("WARNING: Could not write to spool file");
+ error(e);
+ }
}
}
}
@@ -759,13 +766,15 @@
output("\n"+toColumns(matches));
}
if (match != null) {
- if (sub.length() > 0) {
- /*if (Character.isUpperCase(sub.charAt(0))) {
- match = match.toUpperCase();
- } else {
- match = match.toLowerCase();
- }*/
- match = DBConnector.getInstance().translateDbVar(match);
+ match = DBConnector.getInstance().translateDbVar(match);
+ if (sub.length() > 0 && !match.startsWith(sub)) { // case insensitive change
+ Point cursorPosition = screen.getCursorPosition();
+ List<StringBuilder> lines = getEditableCommand().getEditableLines();
+ if (lines.get(cursorPosition.y).length() >=sub.length()) {
+ cursorPosition.x-=sub.length();
+ lines.get(cursorPosition.y).delete(cursorPosition.x, cursorPosition.x + sub.length());
+ return match;
+ }
}
return match.substring(sub.length());
}
Modified: src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-07-28 20:59:50 UTC (rev 274)
+++ src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-07-31 07:59:08 UTC (rev 275)
@@ -39,8 +39,7 @@
private Window window;
public SQLShellWindow() {
- //super(getScreenWidth(),getScreenHeight(), true, "SQLShell");
- commands.register("WINDOW[\\s]+[A-Z]+", new WindowCommand());
+ //commands.register("WINDOW[\\s]+[A-Z]+", new WindowCommand());
}
@@ -54,9 +53,12 @@
return Toolkit.getScreenHeight();
}
+ @Override
public void debug(String debug) {
- CharColor color = new CharColor(CharColor.BLUE, CharColor.YELLOW);
- Toolkit.printString(debug, 1, getScreenHeight()-1, color);
+ synchronized(this) {
+ CharColor color = new CharColor(CharColor.BLUE, CharColor.YELLOW);
+ Toolkit.printString(debug, 1, getScreenHeight()-1, color);
+ }
}
@@ -72,60 +74,6 @@
*/
@Override
protected synchronized void paint() {
- /*
- CharColor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.BOLD, CharColor.BOLD);
-
- List<CharSequence> tmpList = new ArrayList<CharSequence>();
- tmpList.addAll(screenBuffer);
-
- //add prompt
- List<? extends CharSequence> currentLines = commandLines.getLines();
- for (int i = 0; i < currentLines.size(); i++) {
- if (i == 0 && showPrompt) {
- tmpList.add(PROMPT+"> "+currentLines.get(i));
- } else {
- String nrI = Integer.toString(i+1);
- tmpList.add(emptyLine.substring(0,PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i));
- }
- }
- int startLine;
- if (tmpList.size() > getScreenHeight()-1) {
- startLine = tmpList.size() - (getScreenHeight()-1);
- if (pageUpCount > 0) {
- startLine -= (pageUpCount * getScreenHeight()/2);
- if (startLine < 0) {
- startLine = 0;
- }
- }
- } else {
- startLine = 0;
- }
- int lineNr;
- for (lineNr = startLine;lineNr < tmpList.size() && lineNr - startLine < getScreenHeight()-1; lineNr++) {
- CharSequence linePart = tmpList.get(lineNr);
- String line = linePart.length() >= emptyLine.length() ? linePart.toString() : linePart + emptyLine.substring(linePart.length());
- Toolkit.printString(line
- , 0, lineNr-startLine, color);
- }
- for (int lNr = lineNr; lNr < getScreenHeight(); lNr++) {
- Toolkit.printString(emptyLine, 0, lNr, color);
- }
-
- // paint cursor
- color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.REVERSE, CharColor.REVERSE);
- String cursorChar = " ";
- if (commandLines.getLines().size() > 0) {
- String tmp = commandLines.getLines().get(cursorPosition.y).toString();
- if (cursorPosition.x < 0) {
- //debug("Cursor position was: "+ cursorPosition +" fixing");
- cursorPosition.x = 0;
- }
- if (cursorPosition.x < tmp.length()) {
- cursorChar = tmp.substring(cursorPosition.x, cursorPosition.x+1);
- }
- }
- Toolkit.printString(cursorChar, PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(commandLines.getLines().size() -cursorPosition.y)-startLine, color);
- * */
SQLShellWindow.this.repaint();
}
@@ -234,60 +182,62 @@
@Override
public void paint(Screen screen) {
- CharColor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.BOLD, CharColor.BOLD);
+ synchronized(this) {
+ CharColor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.BOLD, CharColor.BOLD);
- List<CharSequence> tmpList = new ArrayList<CharSequence>();
- List<CharSequence> screenBuffer = screen.getScreenBuffer();
- tmpList.addAll(screenBuffer);
+ List<CharSequence> tmpList = new ArrayList<CharSequence>();
+ List<CharSequence> screenBuffer = screen.getScreenBuffer();
+ tmpList.addAll(screenBuffer);
- //add prompt
- List<? extends CharSequence> currentLines = commandLines.getLines();
- for (int i = 0; i < currentLines.size(); i++) {
- if (i == 0 && screen.getShowPrompt()) {
- tmpList.add(Screen.PROMPT+"> "+currentLines.get(i));
- } else {
- String nrI = Integer.toString(i+1);
- tmpList.add(screen.getEmptyLine().substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i));
+ //add prompt
+ List<? extends CharSequence> currentLines = commandLines.getLines();
+ for (int i = 0; i < currentLines.size(); i++) {
+ if (i == 0 && screen.getShowPrompt()) {
+ tmpList.add(Screen.PROMPT+"> "+currentLines.get(i));
+ } else {
+ String nrI = Integer.toString(i+1);
+ tmpList.add(screen.getEmptyLine().substring(0,Screen.PROMPT.length() - nrI.length()) + nrI+"> "+currentLines.get(i));
+ }
}
- }
- int startLine;
- if (tmpList.size() > Toolkit.getScreenHeight()-1) {
- startLine = tmpList.size() - (Toolkit.getScreenHeight()-1);
- if (screen.getPageUpCount() > 0) {
- startLine -= (screen.getPageUpCount() * Toolkit.getScreenHeight()/2);
- if (startLine < 0) {
- startLine = 0;
+ int startLine;
+ if (tmpList.size() > Toolkit.getScreenHeight()-1) {
+ startLine = tmpList.size() - (Toolkit.getScreenHeight()-1);
+ if (screen.getPageUpCount() > 0) {
+ startLine -= (screen.getPageUpCount() * Toolkit.getScreenHeight()/2);
+ if (startLine < 0) {
+ startLine = 0;
+ }
}
+ } else {
+ startLine = 0;
}
- } else {
- startLine = 0;
- }
- int lineNr;
- for (lineNr = startLine;lineNr < tmpList.size() && lineNr - startLine < Toolkit.getScreenHeight()-1; lineNr++) {
- CharSequence linePart = tmpList.get(lineNr);
- String line = linePart.length() >= screen.getEmptyLine().length() ? linePart.toString() : linePart + screen.getEmptyLine().substring(linePart.length());
- Toolkit.printString(line
- , 0, lineNr-startLine, color);
- }
- for (int lNr = lineNr; lNr < Toolkit.getScreenHeight(); lNr++) {
- Toolkit.printString(screen.getEmptyLine(), 0, lNr, color);
- }
-
- // paint cursor
- color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.REVERSE, CharColor.REVERSE);
- String cursorChar = " ";
- Point cursorPosition = screen.getCursorPosition();
- if (commandLines.getLines().size() > 0) {
- String tmp = commandLines.getLines().get(cursorPosition.y).toString();
- if (cursorPosition.x < 0) {
- debug("Cursor position was: "+ cursorPosition +" fixing");
- cursorPosition.x = 0;
+ int lineNr;
+ for (lineNr = startLine;lineNr < tmpList.size() && lineNr - startLine < Toolkit.getScreenHeight()-1; lineNr++) {
+ CharSequence linePart = tmpList.get(lineNr);
+ String line = linePart.length() >= screen.getEmptyLine().length() ? linePart.toString() : linePart + screen.getEmptyLine().substring(linePart.length());
+ Toolkit.printString(line
+ , 0, lineNr-startLine, color);
}
- if (cursorPosition.x < tmp.length()) {
- cursorChar = tmp.substring(cursorPosition.x, cursorPosition.x+1);
+ for (int lNr = lineNr; lNr < Toolkit.getScreenHeight(); lNr++) {
+ Toolkit.printString(screen.getEmptyLine(), 0, lNr, color);
}
+
+ // paint cursor
+ color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.REVERSE, CharColor.REVERSE);
+ String cursorChar = " ";
+ Point cursorPosition = screen.getCursorPosition();
+ if (commandLines.getLines().size() > 0) {
+ String tmp = commandLines.getLines().get(cursorPosition.y).toString();
+ if (cursorPosition.x < 0) {
+ debug("Cursor position was: "+ cursorPosition +" fixing");
+ cursorPosition.x = 0;
+ }
+ if (cursorPosition.x < tmp.length()) {
+ cursorChar = tmp.substring(cursorPosition.x, cursorPosition.x+1);
+ }
+ }
+ Toolkit.printString(cursorChar, Screen.PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(commandLines.getLines().size() -cursorPosition.y)-startLine, color);
}
- Toolkit.printString(cursorChar, Screen.PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(commandLines.getLines().size() -cursorPosition.y)-startLine, color);
}
public static void main(String[] args) {
|