From 0469c6dbdf38fbd4a52284fa3f3db8beb5350933 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Sun, 17 Apr 2022 16:42:10 +0200 Subject: [PATCH] Add highlighting to current nesting level in Carp highlighter --- src/Carp/CarpApplication.class.st | 27 ++++++++ src/Carp/CarpStylerUtilities.class.st | 88 +++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 src/Carp/CarpApplication.class.st create mode 100644 src/Carp/CarpStylerUtilities.class.st diff --git a/src/Carp/CarpApplication.class.st b/src/Carp/CarpApplication.class.st new file mode 100644 index 0000000..e9dcf95 --- /dev/null +++ b/src/Carp/CarpApplication.class.st @@ -0,0 +1,27 @@ +Class { + #name : #CarpApplication, + #superclass : #LanguageLinkApplication, + #instVars : [ + 'uniqueInstance' + ], + #category : #'Carp-LanguageLink' +} + +{ #category : #'start-stop' } +CarpApplication class >> start [ + + ^ self startWith: LanguageLinkSettings jsDefaultSettings. +] + +{ #category : #accessing } +CarpApplication >> baseApplication [ + ^ CarpApplication +] + +{ #category : #accessing } +CarpApplication >> initializeHandlers [ + loggingHandler := LanguageLinkLoggingHandler application: self. + communicationHandler := LanguageLinkCommunicationHandler application: self. + processHandler := LanguageLinkServerHandler application: self. + "executionHandler := CarpExecutionHandler application: self" +] diff --git a/src/Carp/CarpStylerUtilities.class.st b/src/Carp/CarpStylerUtilities.class.st new file mode 100644 index 0000000..23033b7 --- /dev/null +++ b/src/Carp/CarpStylerUtilities.class.st @@ -0,0 +1,88 @@ +Class { + #name : #CarpStylerUtilities, + #superclass : #Object, + #category : #'Carp-Styler' +} + +{ #category : #accessing } +CarpStylerUtilities class >> colorAndHighlightParenthesesLeft: aLeftIndex right: aRightIndex atNestingLevel: aNestingLevel inText: aText [ + self + highlightParenthesesLeft: aLeftIndex + right: aRightIndex + inText: aText. + self + colorParenthesesLeft: aLeftIndex + right: aRightIndex + atNestingLevel: aNestingLevel + inText: aText +] + +{ #category : #accessing } +CarpStylerUtilities class >> colorParenthesesLeft: aLeftIndex right: aRightIndex atNestingLevel: aNestingLevel inText: aText [ + | color | + color := self parenthesesColorAt: aNestingLevel. + (aText + from: aLeftIndex + to: aLeftIndex) + foreground: color. + (aText + from: aRightIndex + to: aRightIndex) + foreground: color +] + +{ #category : #accessing } +CarpStylerUtilities class >> highlightParenthesesLeft: aLeftIndex right: aRightIndex inText: aText [ + | theParanthesesMarker cursorEnterAction cursorLeaveAction | + + theParanthesesMarker := BrTextInvisibleMarkerAttribute new. + aText + attribute: theParanthesesMarker + from: aLeftIndex + to: aRightIndex. + + cursorEnterAction := [ :aTextEditor | + aTextEditor text + findAttribute: theParanthesesMarker + indicesDo: [ :aParanthesesStart :aParanthesesEnd | + aTextEditor text + attribute: (GtPharoParenthesesHighlightAttribute paint: BrGlamorousColors neutralBackgroundColor) + from: aParanthesesStart + to: aParanthesesEnd ] ]. + + cursorLeaveAction := [ :aTextEditor | + aTextEditor text + findAttribute: theParanthesesMarker + indicesDo: [ :aParanthesesStart :aParanthesesEnd | + (aTextEditor text + from: aParanthesesStart + to: aParanthesesEnd) + clearAttributesOfClass: GtPharoParenthesesHighlightAttribute ] ]. + + (aText + from: aLeftIndex + to: aLeftIndex) + onCursorEnter: cursorEnterAction + leave: cursorLeaveAction. + + (aText + from: aRightIndex + to: aRightIndex) + onCursorEnter: cursorEnterAction + leave: cursorLeaveAction +] + +{ #category : #accessing } +CarpStylerUtilities class >> parenthesesColorAt: anIndex [ + | colors | + colors := self parenthesesColors. + ^ colors at: (anIndex - 1) \\ colors size + 1 +] + +{ #category : #accessing } +CarpStylerUtilities class >> parenthesesColors [ + | colors | + colors := BrGlamorousColors distinctTenStrongColors allButFirst allButLast + collect: [ :each | each twiceDarker ]. + ^ colors +]