Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terminal setup color guidance for good experience with kalk #9

Open
xoofx opened this issue Nov 29, 2020 · 0 comments
Open

Add terminal setup color guidance for good experience with kalk #9

xoofx opened this issue Nov 29, 2020 · 0 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@xoofx
Copy link
Owner

xoofx commented Nov 29, 2020

kalk is relying on standard ANSI escape code colors to select the colors for syntax highlighting.

We don't want necessarily to use other colors (e.g user defined with full RGB escape sequences) but would like to only rely on these standard escape code.

The supported colors are the following, and kalk is using only a subset of them:

  • Black
  • Red -> kalk errors
  • Green
  • Yellow -> kalk units
  • Blue
  • Magenta
  • Cyan -> kalk built-in functions/values
  • White -> kalk anything else
  • Bright Black (Gray)
  • Bright Red
  • Bright Green -> kalk comments
  • Bright Yellow -> kalk keywords
  • Bright Blue
  • Bright Magenta
  • Bright Cyan -> kalk VerbatimString
  • Bright White -> kalk name followed by a :

The code involved is here:

private ConsoleStyle? GetStyle(int index, Token token, string text, bool isPreviousNotDot, List<Token> tokens)
{
switch (token.Type)
{
case TokenType.Integer:
case TokenType.HexaInteger:
case TokenType.BinaryInteger:
case TokenType.Float:
return ConsoleStyle.Bold;
case TokenType.String:
case TokenType.VerbatimString:
return ConsoleStyle.BrightCyan;
case TokenType.Comment:
case TokenType.CommentMulti:
return ConsoleStyle.BrightGreen;
case TokenType.Identifier:
var key = token.GetText(text);
if (isPreviousNotDot)
{
if ((index + 1 < tokens.Count && tokens[index + 1].Type == TokenType.Colon))
{
return ConsoleStyle.BrightWhite;
}
if (ScriptKeywords.Contains(key))
{
// Handle the case where for ... in, the in should be marked as a keyword
if (key != "in" || !(index > 1 && tokens[index - 2].GetText(text) == "for"))
{
return ConsoleStyle.BrightYellow;
}
}
if (Builtins.ContainsKey(key) || ValueKeywords.Contains(key))
{
return ConsoleStyle.Cyan;
}
else if (Units.ContainsKey(key))
{
return ConsoleStyle.Yellow;
}
}
return ConsoleStyle.White;
default:
return null;
}
}

We should add some guidance to the documentation on how to configure these colors (e.g in new Windows terminal)

Accessorily, do we need to improve the syntax highlighting?

@xoofx xoofx added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant