Skip to content

Commit 8640056

Browse files
committed
Add the xoria theme
1 parent e1e2c6d commit 8640056

File tree

5 files changed

+330
-7
lines changed

5 files changed

+330
-7
lines changed

v2/cmenu.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ func (e *Editor) CommandMenu(c *vt.Canvas, tty *vt.TTY, status *StatusBar, undo
375375
"Gray Mono (O_THEME=graymono)",
376376
"Amber Mono (O_THEME=ambermono)",
377377
"Green Mono (O_THEME=greenmono)",
378-
"Blue Mono (O_THEME=bluemono)"}
378+
"Blue Mono (O_THEME=bluemono)",
379+
"Xoria (O_THEME=xoria)"}
379380
menuChoices = append(menuChoices, "No colors (NO_COLOR=1)")
380381
useMenuIndex := 0
381382
for i, menuChoiceText := range menuChoices {
@@ -462,6 +463,20 @@ func (e *Editor) CommandMenu(c *vt.Canvas, tty *vt.TTY, status *StatusBar, undo
462463
envNoColor = false
463464
e.setBlueTheme()
464465
e.syntaxHighlight = false
466+
case "xoria":
467+
if termHas256Colors() {
468+
envNoColor = false
469+
registerXoria256Colors()
470+
e.SetTheme(NewXoria256Theme())
471+
e.syntaxHighlight = true
472+
} else if envNoColor {
473+
e.setNoColorTheme()
474+
e.syntaxHighlight = false
475+
} else {
476+
envNoColor = false
477+
e.SetTheme(NewXoria16Theme())
478+
e.syntaxHighlight = true
479+
}
465480
case "nocolor":
466481
envNoColor = true
467482
e.setNoColorTheme()

v2/highlight.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ const (
7070
TextAttrValue
7171
TextTag
7272
Type
73+
CurlyBracket
74+
IncludeSystem
7375
)
7476

7577
// TextConfig holds the Text class configuration to be used by annotators when highlighting code.
@@ -79,8 +81,10 @@ type TextConfig struct {
7981
AssemblyEnd string
8082
Class string
8183
Comment string
84+
CurlyBracket string
8285
Decimal string
8386
Dollar string
87+
IncludeSystem string
8488
Keyword string
8589
Literal string
8690
Mut string
@@ -118,8 +122,10 @@ var DefaultTextConfig = TextConfig{
118122
AssemblyEnd: "lightyellow",
119123
Class: "white",
120124
Comment: "darkgray",
125+
CurlyBracket: "red",
121126
Decimal: "red",
122127
Dollar: "white",
128+
IncludeSystem: "red",
123129
Keyword: "red",
124130
Literal: "white",
125131
Mut: "magenta",
@@ -191,6 +197,10 @@ func (c TextConfig) GetClass(kind Kind) string {
191197
return c.AssemblyEnd
192198
case Mut:
193199
return c.Mut
200+
case CurlyBracket:
201+
return c.CurlyBracket
202+
case IncludeSystem:
203+
return c.IncludeSystem
194204
}
195205
return ""
196206
}
@@ -259,9 +269,10 @@ func Print(s *scanner.Scanner, w io.Writer, p Printer, m mode.Mode) error {
259269
}
260270
}
261271
inComment := false
272+
inInclude := false
262273
for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() {
263274
tokText := s.TokenText()
264-
if err := p.Print(w, tokenKind(tok, tokText, &inComment, m), tokText); err != nil {
275+
if err := p.Print(w, tokenKind(tok, tokText, &inComment, &inInclude, m), tokText); err != nil {
265276
return err
266277
}
267278
}
@@ -901,15 +912,15 @@ func (e *Editor) WriteLines(c *vt.Canvas, fromline, toline LineIndex, cx, cy uin
901912
if inSelection {
902913
c.WriteWideRuneBNoLock(tx, ty, e.NanoHelpForeground, e.NanoHelpBackground, letter)
903914
} else if highlightCurrentLine && (e.highlightCurrentText || e.highlightCurrentLine) {
904-
c.WriteWideRuneBNoLock(tx, ty, e.HighlightForeground, e.HighlightBackground, letter)
915+
c.WriteWideRuneBNoLock(tx, ty, e.HighlightForeground, e.Background, letter)
905916
} else {
906917
c.WriteWideRuneBNoLock(tx, ty, fg, bg, letter)
907918
}
908919
} else if rw <= 1 {
909920
if inSelection {
910921
c.WriteRuneBNoLock(tx, ty, e.NanoHelpForeground, e.NanoHelpBackground, letter)
911922
} else if highlightCurrentLine && (e.highlightCurrentText || e.highlightCurrentLine) {
912-
c.WriteRuneBNoLock(tx, ty, e.HighlightForeground, e.HighlightBackground, letter)
923+
c.WriteRuneBNoLock(tx, ty, e.HighlightForeground, e.Background, letter)
913924
} else {
914925
c.WriteRuneBNoLock(tx, ty, fg, bg, letter)
915926
}
@@ -945,7 +956,7 @@ func (e *Editor) WriteLines(c *vt.Canvas, fromline, toline LineIndex, cx, cy uin
945956
xp = cx + lineRuneCount
946957
if int(cw-lineRuneCount) > 0 {
947958
if highlightCurrentLine && e.highlightCurrentLine {
948-
c.WriteRunesB(xp, yp, e.HighlightForeground, e.HighlightBackground, ' ', cw-lineRuneCount)
959+
c.WriteRunesB(xp, yp, e.HighlightForeground, e.Background, ' ', cw-lineRuneCount)
949960
} else {
950961
c.WriteRunesB(xp, yp, e.Foreground, bg, ' ', cw-lineRuneCount)
951962
}

v2/neweditor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,14 @@ func NewEditor(tty *vt.TTY, c *vt.Canvas, fnord FilenameOrData, lineNumber LineN
457457
e.setBlueTheme()
458458
e.syntaxHighlight = false
459459
themeWasSet = true
460+
case "xoria":
461+
if termHas256Colors() {
462+
registerXoria256Colors()
463+
e.SetTheme(NewXoria256Theme(), assumeLightBackground)
464+
} else if !envNoColor {
465+
e.SetTheme(NewXoria16Theme(), assumeLightBackground)
466+
}
467+
themeWasSet = true
460468
case "default":
461469
themeWasSet = true
462470
}

v2/syntax.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,42 @@ import (
1010
)
1111

1212
// tokenKind determines the Kind of a token for syntax highlighting.
13-
func tokenKind(tok rune, tokText string, inComment *bool, m mode.Mode) Kind {
13+
func tokenKind(tok rune, tokText string, inComment *bool, inInclude *bool, m mode.Mode) Kind {
1414
// Detect single-line comment start/end.
1515
if (m == mode.Assembly && tok == ';') ||
1616
(m != mode.Assembly && m != mode.GoAssembly && m != mode.Clojure && m != mode.Lisp && m != mode.C && m != mode.Cpp && m != mode.Lua && tok == '#') ||
1717
((m == mode.ABC || m == mode.Lilypond || m == mode.Perl || m == mode.Prolog) && tok == '%') {
1818
*inComment = true
1919
} else if tok == '\n' {
2020
*inComment = false
21+
*inInclude = false
2122
}
2223

2324
// C-style preprocessor directives.
2425
if (m == mode.C || m == mode.Cpp) && (tokText == "include" || tokText == "define" || tokText == "ifdef" || tokText == "ifndef" || tokText == "endif" || tokText == "else" || tokText == "elif") {
2526
*inComment = false
27+
if tokText == "include" {
28+
*inInclude = true
29+
}
2630
return Keyword
2731
}
2832

33+
// If we are inside a #include <...> directive, color tokens as IncludeSystem
34+
if *inInclude && (m == mode.C || m == mode.Cpp) {
35+
if tok == scanner.Char || tok == scanner.String || tok == scanner.RawString {
36+
// #include "..." gets String color (local include)
37+
*inInclude = false
38+
return String
39+
}
40+
if unicode.IsSpace(tok) {
41+
return Whitespace
42+
}
43+
if tok == '>' {
44+
*inInclude = false
45+
}
46+
return IncludeSystem
47+
}
48+
2949
if *inComment {
3050
return Comment
3151
}
@@ -91,6 +111,8 @@ func tokenKind(tok rune, tokText string, inComment *bool, m mode.Mode) Kind {
91111
return Dollar
92112
} else if tok == '<' || tok == '>' {
93113
return AngleBracket
114+
} else if tok == '{' || tok == '}' {
115+
return CurlyBracket
94116
}
95117

96118
if unicode.IsSpace(tok) {

0 commit comments

Comments
 (0)