mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
terminal: respect font typography settings (IDEA-266310)
GitOrigin-RevId: afd26ec9f67feddb32c8c6a4b4b9c36135c8d23a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f8f62678fa
commit
c1b84b3b35
@@ -274,10 +274,10 @@ public class JBTerminalPanel extends TerminalPanel implements FocusListener, Dis
|
||||
fontStyle |= Font.ITALIC;
|
||||
}
|
||||
FontInfo fontInfo = fontForChar(c, fontStyle);
|
||||
return fontInfo.getFont();
|
||||
return fontInfo.getFont().deriveFont((float)mySettingsProvider.getUiSettingsManager().getFontSize());
|
||||
}
|
||||
|
||||
public FontInfo fontForChar(final char c, @JdkConstants.FontStyle int style) {
|
||||
private @NotNull FontInfo fontForChar(final char c, @JdkConstants.FontStyle int style) {
|
||||
return ComplementaryFontsRegistry.getFontAbleToDisplay(c, style, mySettingsProvider.getColorsScheme().getConsoleFontPreferences(), null);
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ public class JBTerminalPanel extends TerminalPanel implements FocusListener, Dis
|
||||
if (EditorSettingsExternalizable.getInstance().isWheelFontChangeEnabled() && EditorUtil.isChangeFontSize(e)) {
|
||||
int newFontSize = (int)mySettingsProvider.getTerminalFontSize() - e.getWheelRotation();
|
||||
if (newFontSize >= MIN_FONT_SIZE) {
|
||||
mySettingsProvider.getUiSettingsManager().setConsoleFontSize(newFontSize);
|
||||
mySettingsProvider.getUiSettingsManager().setFontSize(newFontSize);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ import com.intellij.idea.ActionsBundle;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.actionSystem.KeyboardShortcut;
|
||||
import com.intellij.openapi.actionSystem.Shortcut;
|
||||
import com.intellij.openapi.editor.colors.EditorColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.colors.*;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
@@ -37,11 +35,9 @@ public class JBTerminalSystemSettingsProviderBase extends DefaultTabbedSettingsP
|
||||
TextAttributesKey.createTextAttributesKey("TERMINAL_COMMAND_TO_RUN_USING_IDE");
|
||||
|
||||
private final TerminalUiSettingsManager myUiSettingsManager;
|
||||
private final EditorColorsScheme myColorsScheme;
|
||||
|
||||
public JBTerminalSystemSettingsProviderBase() {
|
||||
myUiSettingsManager = TerminalUiSettingsManager.getInstance();
|
||||
myColorsScheme = myUiSettingsManager.getEditorColorsScheme();
|
||||
}
|
||||
|
||||
@NotNull TerminalUiSettingsManager getUiSettingsManager() {
|
||||
@@ -49,7 +45,7 @@ public class JBTerminalSystemSettingsProviderBase extends DefaultTabbedSettingsP
|
||||
}
|
||||
|
||||
@NotNull EditorColorsScheme getColorsScheme() {
|
||||
return myColorsScheme;
|
||||
return myUiSettingsManager.getEditorColorsScheme();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,51 +197,42 @@ public class JBTerminalSystemSettingsProviderBase extends DefaultTabbedSettingsP
|
||||
|
||||
@Override
|
||||
public float getLineSpacing() {
|
||||
return myColorsScheme.getConsoleLineSpacing();
|
||||
return getColorsScheme().getConsoleLineSpacing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextStyle getSelectionColor() {
|
||||
return new TextStyle(TerminalColor.awt(myColorsScheme.getColor(EditorColors.SELECTION_FOREGROUND_COLOR)),
|
||||
TerminalColor.awt(myColorsScheme.getColor(EditorColors.SELECTION_BACKGROUND_COLOR)));
|
||||
return new TextStyle(TerminalColor.awt(getColorsScheme().getColor(EditorColors.SELECTION_FOREGROUND_COLOR)),
|
||||
TerminalColor.awt(getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextStyle getFoundPatternColor() {
|
||||
return new TextStyle(TerminalColor.awt(myColorsScheme.getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES).getForegroundColor()),
|
||||
TerminalColor.awt(myColorsScheme.getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES).getBackgroundColor()));
|
||||
return new TextStyle(TerminalColor.awt(getColorsScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES).getForegroundColor()),
|
||||
TerminalColor.awt(getColorsScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES).getBackgroundColor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextStyle getHyperlinkColor() {
|
||||
return new TextStyle(TerminalColor.awt(myColorsScheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR).getForegroundColor()),
|
||||
TerminalColor.awt(myColorsScheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR).getBackgroundColor()));
|
||||
return new TextStyle(TerminalColor.awt(getColorsScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR).getForegroundColor()),
|
||||
TerminalColor.awt(getColorsScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR).getBackgroundColor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextStyle getDefaultStyle() {
|
||||
return new TextStyle(new TerminalColor(() -> myColorsScheme.getDefaultForeground()),
|
||||
new TerminalColor(() -> myColorsScheme.getDefaultBackground()));
|
||||
return new TextStyle(new TerminalColor(() -> myUiSettingsManager.getDefaultForeground()),
|
||||
new TerminalColor(() -> myUiSettingsManager.getDefaultBackground()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Font getTerminalFont() {
|
||||
return new Font(getFontName(), Font.PLAIN, (int)getTerminalFontSize());
|
||||
}
|
||||
|
||||
public String getFontName() {
|
||||
List<String> fonts = myColorsScheme.getConsoleFontPreferences().getEffectiveFontFamilies();
|
||||
|
||||
if (fonts.size() > 0) {
|
||||
return fonts.get(0);
|
||||
}
|
||||
|
||||
return "Monospaced-14";
|
||||
Font font = getColorsScheme().getFont(EditorFontType.CONSOLE_PLAIN);
|
||||
return font.deriveFont(getTerminalFontSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTerminalFontSize() {
|
||||
return (float)myColorsScheme.getConsoleFontSize();
|
||||
return (float)myUiSettingsManager.getFontSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,51 +6,51 @@ import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.ide.ui.UISettingsListener;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.colors.*;
|
||||
import com.intellij.openapi.editor.colors.impl.FontPreferencesImpl;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsListener;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.jediterm.terminal.emulator.ColorPalette;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
final class TerminalUiSettingsManager implements Disposable {
|
||||
|
||||
private final MyColorsSchemeDelegate myColorsScheme;
|
||||
private @NotNull EditorColorsScheme myColorsScheme;
|
||||
private int myFontSize;
|
||||
private JBTerminalSchemeColorPalette myColorPalette;
|
||||
private final List<JBTerminalPanel> myTerminalPanels = new CopyOnWriteArrayList<>();
|
||||
|
||||
TerminalUiSettingsManager() {
|
||||
myColorsScheme = new MyColorsSchemeDelegate();
|
||||
myColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
|
||||
|
||||
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(this);
|
||||
connection.subscribe(UISettingsListener.TOPIC, uiSettings -> {
|
||||
int oldSize = myColorsScheme.getConsoleFontSize();
|
||||
int newSize = myColorsScheme.detectConsoleFontSize();
|
||||
if (oldSize != newSize) {
|
||||
setConsoleFontSize(newSize);
|
||||
}
|
||||
setFontSize(detectFontSize());
|
||||
});
|
||||
connection.subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
|
||||
@Override
|
||||
public void globalSchemeChange(@Nullable EditorColorsScheme scheme) {
|
||||
myColorsScheme.updateGlobalScheme(scheme);
|
||||
myColorsScheme = scheme != null ? scheme : EditorColorsManager.getInstance().getGlobalScheme();
|
||||
myColorPalette = null;
|
||||
setConsoleFontSize(myColorsScheme.detectConsoleFontSize());
|
||||
fireFontChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setConsoleFontSize(int fontSize) {
|
||||
myColorsScheme.setConsoleFontSize(fontSize);
|
||||
fireFontChanged();
|
||||
@NotNull Color getDefaultForeground() {
|
||||
Color foregroundColor = myColorsScheme.getAttributes(ConsoleViewContentType.NORMAL_OUTPUT_KEY).getForegroundColor();
|
||||
return foregroundColor != null ? foregroundColor : myColorsScheme.getDefaultForeground();
|
||||
}
|
||||
|
||||
@NotNull Color getDefaultBackground() {
|
||||
Color color = myColorsScheme.getColor(ConsoleViewContentType.CONSOLE_BACKGROUND_KEY);
|
||||
return color != null ? color : myColorsScheme.getDefaultBackground();
|
||||
}
|
||||
|
||||
static @NotNull TerminalUiSettingsManager getInstance() {
|
||||
@@ -81,236 +81,28 @@ final class TerminalUiSettingsManager implements Disposable {
|
||||
return colorPalette;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {}
|
||||
|
||||
private static final class MyColorsSchemeDelegate implements EditorColorsScheme {
|
||||
|
||||
private final FontPreferencesImpl myFontPreferences = new FontPreferencesImpl();
|
||||
private final HashMap<TextAttributesKey, TextAttributes> myOwnAttributes = new HashMap<>();
|
||||
private final HashMap<ColorKey, Color> myOwnColors = new HashMap<>();
|
||||
private Map<EditorFontType, Font> myFontsMap = null;
|
||||
private String myFaceName = null;
|
||||
private EditorColorsScheme myGlobalScheme;
|
||||
|
||||
private int myConsoleFontSize;
|
||||
|
||||
private MyColorsSchemeDelegate() {
|
||||
updateGlobalScheme(null);
|
||||
myConsoleFontSize = detectConsoleFontSize();
|
||||
initFonts();
|
||||
int getFontSize() {
|
||||
if (myFontSize <= 0) {
|
||||
myFontSize = detectFontSize();
|
||||
}
|
||||
return myFontSize;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private EditorColorsScheme getGlobal() {
|
||||
return myGlobalScheme;
|
||||
private int detectFontSize() {
|
||||
if (UISettings.getInstance().getPresentationMode()) {
|
||||
return UISettings.getInstance().getPresentationModeFontSize();
|
||||
}
|
||||
return myColorsScheme.getConsoleFontSize();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return getGlobal().getName();
|
||||
}
|
||||
|
||||
private void initFonts() {
|
||||
String consoleFontName = getConsoleFontName();
|
||||
int consoleFontSize = getConsoleFontSize();
|
||||
myFontPreferences.clear();
|
||||
myFontPreferences.register(consoleFontName, consoleFontSize);
|
||||
|
||||
myFontsMap = new EnumMap<>(EditorFontType.class);
|
||||
|
||||
Font plainFont = new Font(consoleFontName, Font.PLAIN, consoleFontSize);
|
||||
Font boldFont = new Font(consoleFontName, Font.BOLD, consoleFontSize);
|
||||
Font italicFont = new Font(consoleFontName, Font.ITALIC, consoleFontSize);
|
||||
Font boldItalicFont = new Font(consoleFontName, Font.BOLD | Font.ITALIC, consoleFontSize);
|
||||
|
||||
myFontsMap.put(EditorFontType.PLAIN, plainFont);
|
||||
myFontsMap.put(EditorFontType.BOLD, boldFont);
|
||||
myFontsMap.put(EditorFontType.ITALIC, italicFont);
|
||||
myFontsMap.put(EditorFontType.BOLD_ITALIC, boldItalicFont);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
getGlobal().setName(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return getGlobal().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextAttributes getAttributes(TextAttributesKey key) {
|
||||
if (myOwnAttributes.containsKey(key)) return myOwnAttributes.get(key);
|
||||
return getGlobal().getAttributes(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttributes(@NotNull TextAttributesKey key, TextAttributes attributes) {
|
||||
myOwnAttributes.put(key, attributes);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Color getDefaultBackground() {
|
||||
Color color = getGlobal().getColor(ConsoleViewContentType.CONSOLE_BACKGROUND_KEY);
|
||||
return color != null ? color : getGlobal().getDefaultBackground();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Color getDefaultForeground() {
|
||||
Color foregroundColor = getGlobal().getAttributes(ConsoleViewContentType.NORMAL_OUTPUT_KEY).getForegroundColor();
|
||||
return foregroundColor != null ? foregroundColor : getGlobal().getDefaultForeground();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor(ColorKey key) {
|
||||
if (myOwnColors.containsKey(key)) return myOwnColors.get(key);
|
||||
return getGlobal().getColor(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(ColorKey key, Color color) {
|
||||
myOwnColors.put(key, color);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FontPreferences getFontPreferences() {
|
||||
return myGlobalScheme.getFontPreferences();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFontPreferences(@NotNull FontPreferences preferences) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEditorFontSize() {
|
||||
return getGlobal().getEditorFontSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEditorFontSize(int fontSize) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEditorFontName() {
|
||||
return getGlobal().getEditorFontName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEditorFontName(String fontName) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Font getFont(EditorFontType key) {
|
||||
if (myFontsMap != null) {
|
||||
Font font = myFontsMap.get(key);
|
||||
if (font != null) return font;
|
||||
}
|
||||
return getGlobal().getFont(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFont(EditorFontType key, Font font) {
|
||||
if (myFontsMap == null) {
|
||||
initFonts();
|
||||
}
|
||||
myFontsMap.put(key, font);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLineSpacing() {
|
||||
return getGlobal().getLineSpacing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLineSpacing(float lineSpacing) {
|
||||
getGlobal().setLineSpacing(lineSpacing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
}
|
||||
|
||||
private void updateGlobalScheme(@Nullable EditorColorsScheme scheme) {
|
||||
myFontsMap = null;
|
||||
myGlobalScheme = scheme != null ? scheme : EditorColorsManager.getInstance().getGlobalScheme();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FontPreferences getConsoleFontPreferences() {
|
||||
return myFontPreferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConsoleFontPreferences(@NotNull FontPreferences preferences) {
|
||||
preferences.copyTo(myFontPreferences);
|
||||
initFonts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConsoleFontName() {
|
||||
if (myFaceName == null) {
|
||||
return getGlobal().getConsoleFontName();
|
||||
}
|
||||
else {
|
||||
return myFaceName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConsoleFontName(String fontName) {
|
||||
myFaceName = fontName;
|
||||
initFonts();
|
||||
}
|
||||
|
||||
private int detectConsoleFontSize() {
|
||||
if (UISettings.getInstance().getPresentationMode()) {
|
||||
return UISettings.getInstance().getPresentationModeFontSize();
|
||||
}
|
||||
return getGlobal().getConsoleFontSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConsoleFontSize() {
|
||||
return myConsoleFontSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConsoleFontSize(int fontSize) {
|
||||
myConsoleFontSize = fontSize;
|
||||
initFonts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getConsoleLineSpacing() {
|
||||
return getGlobal().getConsoleLineSpacing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConsoleLineSpacing(float lineSpacing) {
|
||||
getGlobal().setConsoleLineSpacing(lineSpacing);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Properties getMetaProperties() {
|
||||
return myGlobalScheme.getMetaProperties();
|
||||
void setFontSize(int fontSize) {
|
||||
int prevFontSize = myFontSize;
|
||||
myFontSize = fontSize;
|
||||
if (prevFontSize != fontSize) {
|
||||
fireFontChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user