Skip to content

Commit

Permalink
Highl;ighting for digits in large numbers with CVM gold
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 7, 2024
1 parent 44b01e7 commit 100b3cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public BalanceMenu() {

public static final Color GOLD=new Color(255,255,0);
public static final Color SILVER=new Color(200,200,230);
public static final Color BRONZE=new Color(180,120,60);
public static final Color COPPER=new Color(150,80,30);
public static final Color BRONZE=new Color(200,120,60);
public static final Color COPPER=new Color(150,100,30);

protected int decimals=9;
private Color balanceColour=GOLD;
Expand Down
22 changes: 21 additions & 1 deletion convex-gui/src/main/java/convex/gui/utils/CVXHighlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.antlr.v4.runtime.Token;

import convex.core.lang.reader.AntlrReader;
import convex.gui.components.BalanceLabel;

/**
* Tools for highlighting Convex Lisp code in Swing
Expand All @@ -31,6 +32,12 @@ public class CVXHighlighter {
static AttributeSet SYMBOL = NORMAL;
static AttributeSet NUMBER = sc.addAttribute(BASE, StyleConstants.Foreground, Color.ORANGE);

static AttributeSet GOLD = sc.addAttribute(BASE, StyleConstants.Foreground, BalanceLabel.GOLD);
static AttributeSet SILVER = sc.addAttribute(BASE, StyleConstants.Foreground, BalanceLabel.SILVER);
static AttributeSet BRONZE = sc.addAttribute(BASE, StyleConstants.Foreground, BalanceLabel.BRONZE);
static AttributeSet COPPER = sc.addAttribute(BASE, StyleConstants.Foreground, BalanceLabel.COPPER);


private static final AttributeSet[] PARENS = new AttributeSet[10];

static {
Expand Down Expand Up @@ -110,8 +117,21 @@ public static void highlight(JTextPane inputArea, int start, int end) {

default: {
if (Character.isDigit(c)) {
aset=NUMBER; break;
aset=NUMBER;
}
if (tlen>3) try {
// Might be worth formatting as a quantity
String fullNum=d.getText(tstart,tlen);
Long.parseLong(fullNum);
if (tlen>9) d.setCharacterAttributes(tstart, tlen-9, GOLD, true);
if (tlen>6) d.setCharacterAttributes(tstart+Math.max(0, tlen-9), Math.min(3, tlen-6), SILVER, true);
if (tlen>3) d.setCharacterAttributes(tstart+Math.max(0, tlen-6), Math.min(3, tlen-3), BRONZE, false);
d.setCharacterAttributes(tstart+tlen-3, tlen, COPPER, false);
continue;
} catch (NumberFormatException e) {
// OK
}
break;
}
}

Expand Down

0 comments on commit 100b3cf

Please sign in to comment.