mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-16 13:35:22 +02:00
RESOLVED - bug 209746: [terminal] There are cases where some colors not displayed correctly
https://bugs.eclipse.org/bugs/show_bug.cgi?id=209746
This commit is contained in:
parent
50cff88f9a
commit
0d55051669
2 changed files with 72 additions and 42 deletions
|
@ -13,6 +13,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Michael Scharf (Wind River) - split into core, view and connector plugins
|
* Michael Scharf (Wind River) - split into core, view and connector plugins
|
||||||
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
||||||
|
* Michael Scharf (Wind River) - [209746] There are cases where some colors not displayed correctly
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.tm.internal.terminal.emulator;
|
package org.eclipse.tm.internal.terminal.emulator;
|
||||||
|
|
||||||
|
@ -777,7 +778,7 @@ public class VT100Emulator implements ControlListener {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 37:
|
case 37:
|
||||||
text.setStyle(style.setForground("WHITE")); //$NON-NLS-1$
|
text.setStyle(style.setForground("WHITE_FOREGROUND")); //$NON-NLS-1$
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 40:
|
case 40:
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Michael Scharf (Wind River) - initial API and implementation
|
* Michael Scharf (Wind River) - initial API and implementation
|
||||||
|
* Michael Scharf (Wind River) - [209746] There are cases where some colors not displayed correctly
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.tm.internal.terminal.textcanvas;
|
package org.eclipse.tm.internal.terminal.textcanvas;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.jface.resource.JFaceResources;
|
import org.eclipse.jface.resource.JFaceResources;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.graphics.Color;
|
import org.eclipse.swt.graphics.Color;
|
||||||
import org.eclipse.swt.graphics.Font;
|
import org.eclipse.swt.graphics.Font;
|
||||||
import org.eclipse.swt.graphics.GC;
|
import org.eclipse.swt.graphics.GC;
|
||||||
|
@ -26,6 +28,7 @@ import org.eclipse.tm.terminal.model.StyleColor;
|
||||||
public class StyleMap {
|
public class StyleMap {
|
||||||
private static final String BLACK = "black"; //$NON-NLS-1$
|
private static final String BLACK = "black"; //$NON-NLS-1$
|
||||||
private static final String WHITE = "white"; //$NON-NLS-1$
|
private static final String WHITE = "white"; //$NON-NLS-1$
|
||||||
|
private static final String WHITE_FOREGROUND = "white_foreground"; //$NON-NLS-1$
|
||||||
private static final String GRAY = "gray"; //$NON-NLS-1$
|
private static final String GRAY = "gray"; //$NON-NLS-1$
|
||||||
private static final String MAGENTA = "magenta"; //$NON-NLS-1$
|
private static final String MAGENTA = "magenta"; //$NON-NLS-1$
|
||||||
private static final String CYAN = "cyan"; //$NON-NLS-1$
|
private static final String CYAN = "cyan"; //$NON-NLS-1$
|
||||||
|
@ -37,76 +40,102 @@ public class StyleMap {
|
||||||
private static final String PREFIX = "org.eclipse.tm.internal."; //$NON-NLS-1$
|
private static final String PREFIX = "org.eclipse.tm.internal."; //$NON-NLS-1$
|
||||||
// TODO propagate the name of the font in the FontRegistry
|
// TODO propagate the name of the font in the FontRegistry
|
||||||
String fFontName="terminal.views.view.font.definition"; //$NON-NLS-1$
|
String fFontName="terminal.views.view.font.definition"; //$NON-NLS-1$
|
||||||
Map fColorMap=new HashMap();
|
Map fColorMapForeground=new HashMap();
|
||||||
|
Map fColorMapBackground=new HashMap();
|
||||||
Map fFontMap=new HashMap();
|
Map fFontMap=new HashMap();
|
||||||
private Point fCharSize;
|
private Point fCharSize;
|
||||||
private Style fDefaultStyle;
|
private final Style fDefaultStyle;
|
||||||
private boolean fInvertColors;
|
private boolean fInvertColors;
|
||||||
private boolean fProportional;
|
private boolean fProportional;
|
||||||
private final int[] fOffsets=new int[256];
|
private final int[] fOffsets=new int[256];
|
||||||
StyleMap() {
|
StyleMap() {
|
||||||
addColor(WHITE, 255,255,255);
|
initColors();
|
||||||
addColor(BLACK, 0,0,0);
|
|
||||||
addColor(RED, 255,128,128);
|
|
||||||
addColor(GREEN, 128,255,128);
|
|
||||||
addColor(BLUE, 128,128,255);
|
|
||||||
addColor(YELLOW, 255,255,0);
|
|
||||||
addColor(CYAN, 0,255,255);
|
|
||||||
addColor(MAGENTA, 255,255,0);
|
|
||||||
addColor(GRAY, 128,128,128);
|
|
||||||
fDefaultStyle=Style.getStyle(StyleColor.getStyleColor(BLACK),StyleColor.getStyleColor(WHITE));
|
fDefaultStyle=Style.getStyle(StyleColor.getStyleColor(BLACK),StyleColor.getStyleColor(WHITE));
|
||||||
updateFont();
|
updateFont();
|
||||||
}
|
}
|
||||||
private void addColor(String name, int r, int g, int b) {
|
private void initColors() {
|
||||||
String colorName=PREFIX+name;
|
initForegroundColors();
|
||||||
|
initBackgroundColors();
|
||||||
|
}
|
||||||
|
private void initForegroundColors() {
|
||||||
|
if(fInvertColors) {
|
||||||
|
setColor(fColorMapForeground, WHITE, 0, 0, 0);
|
||||||
|
setColor(fColorMapForeground, WHITE_FOREGROUND, 50, 50, 50);
|
||||||
|
setColor(fColorMapForeground, BLACK, 255, 255, 255);
|
||||||
|
} else {
|
||||||
|
setColor(fColorMapForeground, WHITE, 255, 255, 255);
|
||||||
|
setColor(fColorMapForeground, WHITE_FOREGROUND, 229, 229, 229);
|
||||||
|
setColor(fColorMapForeground, BLACK, 0, 0, 0);
|
||||||
|
}
|
||||||
|
setColor(fColorMapForeground, RED, 255, 128, 128);
|
||||||
|
setColor(fColorMapForeground, GREEN, 128, 255, 128);
|
||||||
|
setColor(fColorMapForeground, BLUE, 128, 128, 255);
|
||||||
|
setColor(fColorMapForeground, YELLOW, 255, 255, 0);
|
||||||
|
setColor(fColorMapForeground, CYAN, 0, 255, 255);
|
||||||
|
setColor(fColorMapForeground, MAGENTA, 255, 255, 0);
|
||||||
|
setColor(fColorMapForeground, GRAY, 128, 128, 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initBackgroundColors() {
|
||||||
|
if(fInvertColors) {
|
||||||
|
setColor(fColorMapBackground, WHITE, 0, 0, 0);
|
||||||
|
setColor(fColorMapBackground, WHITE_FOREGROUND, 50, 50, 50); // only used when colors are inverse
|
||||||
|
setColor(fColorMapBackground, BLACK, 255, 255, 255);
|
||||||
|
} else {
|
||||||
|
setColor(fColorMapBackground, WHITE, 255, 255, 255);
|
||||||
|
setColor(fColorMapBackground, WHITE_FOREGROUND, 229, 229, 229);
|
||||||
|
setColor(fColorMapBackground, BLACK, 0, 0, 0);
|
||||||
|
}
|
||||||
|
setColor(fColorMapBackground, RED, 255, 128, 128);
|
||||||
|
setColor(fColorMapBackground, GREEN, 128, 255, 128);
|
||||||
|
setColor(fColorMapBackground, BLUE, 128, 128, 255);
|
||||||
|
setColor(fColorMapBackground, YELLOW, 255, 255, 0);
|
||||||
|
setColor(fColorMapBackground, CYAN, 0, 255, 255);
|
||||||
|
setColor(fColorMapBackground, MAGENTA, 255, 255, 0);
|
||||||
|
setColor(fColorMapBackground, GRAY, 128, 128, 128);
|
||||||
|
}
|
||||||
|
private void setColor(Map colorMap, String name, int r, int g, int b) {
|
||||||
|
String colorName=PREFIX+r+"-"+g+"-"+b; //$NON-NLS-1$//$NON-NLS-2$
|
||||||
Color color=JFaceResources.getColorRegistry().get(colorName);
|
Color color=JFaceResources.getColorRegistry().get(colorName);
|
||||||
if(color==null) {
|
if(color==null) {
|
||||||
JFaceResources.getColorRegistry().put(colorName, new RGB(r,g,b));
|
JFaceResources.getColorRegistry().put(colorName, new RGB(r,g,b));
|
||||||
color=JFaceResources.getColorRegistry().get(colorName);
|
color=JFaceResources.getColorRegistry().get(colorName);
|
||||||
}
|
}
|
||||||
fColorMap.put(StyleColor.getStyleColor(name), color);
|
colorMap.put(StyleColor.getStyleColor(name), color);
|
||||||
fColorMap.put(StyleColor.getStyleColor(name.toUpperCase()), color);
|
colorMap.put(StyleColor.getStyleColor(name.toUpperCase()), color);
|
||||||
}
|
|
||||||
public Color getColor(StyleColor colorName) {
|
|
||||||
return (Color) fColorMap.get(colorName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color getForegrondColor(Style style) {
|
public Color getForegrondColor(Style style) {
|
||||||
style = defaultIfNull(style);
|
style = defaultIfNull(style);
|
||||||
if(style.isReverse())
|
if(style.isReverse())
|
||||||
return getColor(style.getBackground());
|
return getColor(fColorMapForeground,style.getBackground());
|
||||||
else
|
else
|
||||||
return getColor(style.getForground());
|
return getColor(fColorMapForeground,style.getForground());
|
||||||
|
}
|
||||||
|
public Color getBackgroundColor(Style style) {
|
||||||
|
style = defaultIfNull(style);
|
||||||
|
if(style.isReverse())
|
||||||
|
return getColor(fColorMapBackground,style.getForground());
|
||||||
|
else
|
||||||
|
return getColor(fColorMapBackground,style.getBackground());
|
||||||
|
}
|
||||||
|
Color getColor(Map map,StyleColor color) {
|
||||||
|
Color c=(Color) map.get(color);
|
||||||
|
if(c==null) {
|
||||||
|
c=Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
|
||||||
|
}
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
private Style defaultIfNull(Style style) {
|
private Style defaultIfNull(Style style) {
|
||||||
if(style==null)
|
if(style==null)
|
||||||
style=fDefaultStyle;
|
style=fDefaultStyle;
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
public Color getBackgroundColor(Style style) {
|
|
||||||
style = defaultIfNull(style);
|
|
||||||
if(style.isReverse())
|
|
||||||
return getColor(style.getForground());
|
|
||||||
else
|
|
||||||
return getColor(style.getBackground());
|
|
||||||
}
|
|
||||||
public void setInvertedColors(boolean invert) {
|
public void setInvertedColors(boolean invert) {
|
||||||
if(invert==fInvertColors)
|
if(invert==fInvertColors)
|
||||||
return;
|
return;
|
||||||
fInvertColors=invert;
|
fInvertColors=invert;
|
||||||
swapColors(WHITE,BLACK);
|
initColors();
|
||||||
fDefaultStyle=Style.getStyle(StyleColor.getStyleColor(BLACK),StyleColor.getStyleColor(WHITE));
|
|
||||||
}
|
|
||||||
void swapColors(String n1, String n2) {
|
|
||||||
swapColors2(n1, n2);
|
|
||||||
swapColors2(n1.toUpperCase(), n2.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
void swapColors2(String n1, String n2) {
|
|
||||||
Color c1=getColor(StyleColor.getStyleColor(n1));
|
|
||||||
Color c2=getColor(StyleColor.getStyleColor(n2));
|
|
||||||
fColorMap.put(StyleColor.getStyleColor(n1), c2);
|
|
||||||
fColorMap.put(StyleColor.getStyleColor(n2), c1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// static Font getBoldFont(Font font) {
|
// static Font getBoldFont(Font font) {
|
||||||
// FontData fontDatas[] = font.getFontData();
|
// FontData fontDatas[] = font.getFontData();
|
||||||
|
|
Loading…
Add table
Reference in a new issue