Skip to content

Commit

Permalink
Merge pull request #4350 from Textualize/text-area-new-languages
Browse files Browse the repository at this point in the history
TextArea new languages
  • Loading branch information
willmcgugan authored Mar 30, 2024
2 parents 179207a + a6cc76d commit ccc71b0
Show file tree
Hide file tree
Showing 16 changed files with 4,783 additions and 574 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Added `Document.start` and `end` location properties for convenience https://github.com/Textualize/textual/pull/4267
- Added support for JavaScript, Golang, Rust, Bash, Java and Kotlin to `TextArea` https://github.com/Textualize/textual/pull/4350
- Added `inline` parameter to `run` and `run_async` to run app inline (under the prompt). https://github.com/Textualize/textual/pull/4343
- Added `mouse` parameter to disable mouse support https://github.com/Textualize/textual/pull/4343

Expand Down
260 changes: 135 additions & 125 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rich = ">=13.3.3"
#rich = {path="../rich", develop=true}
typing-extensions = "^4.4.0"
tree-sitter = { version = "^0.20.1", optional = true }
tree_sitter_languages = { version = ">=1.7.0", optional = true }
tree-sitter-languages = { version = "1.10.2", optional = true }

[tool.poetry.extras]
syntax = ["tree-sitter", "tree_sitter_languages"]
Expand Down
4 changes: 4 additions & 0 deletions src/textual/_text_area_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def builtin_themes(cls) -> list[TextAreaTheme]:
"method": Style(color="#A6E22E"),
"method.call": Style(color="#A6E22E"),
"boolean": Style(color="#66D9EF", italic=True),
"constant.builtin": Style(color="#66D9EF", italic=True),
"json.null": Style(color="#66D9EF", italic=True),
"regex.punctuation.bracket": Style(color="#F92672"),
"regex.operator": Style(color="#F92672"),
Expand Down Expand Up @@ -271,6 +272,7 @@ def builtin_themes(cls) -> list[TextAreaTheme]:
"method": Style(color="#50fa7b"),
"method.call": Style(color="#50fa7b"),
"boolean": Style(color="#bd93f9"),
"constant.builtin": Style(color="#bd93f9"),
"json.null": Style(color="#bd93f9"),
"regex.punctuation.bracket": Style(color="#ff79c6"),
"regex.operator": Style(color="#ff79c6"),
Expand Down Expand Up @@ -320,6 +322,7 @@ def builtin_themes(cls) -> list[TextAreaTheme]:
"method": Style(color="#4EC9B0"),
"method.call": Style(color="#4EC9B0"),
"boolean": Style(color="#7DAF9C"),
"constant.builtin": Style(color="#7DAF9C"),
"json.null": Style(color="#7DAF9C"),
"tag": Style(color="#EFCB43"),
"yaml.field": Style(color="#569cd6", bold=True),
Expand Down Expand Up @@ -365,6 +368,7 @@ def builtin_themes(cls) -> list[TextAreaTheme]:
"function": Style(color="#6639BB"),
"method": Style(color="#6639BB"),
"boolean": Style(color="#7DAF9C"),
"constant.builtin": Style(color="#7DAF9C"),
"tag": Style(color="#6639BB"),
"yaml.field": Style(color="#6639BB"),
"json.label": Style(color="#6639BB"),
Expand Down
12 changes: 9 additions & 3 deletions src/textual/document/_languages.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
BUILTIN_LANGUAGES = sorted(
[
"markdown",
"yaml",
"sql",
"bash",
"css",
"go",
"html",
"java",
"javascript",
"json",
"kotlin",
"markdown",
"python",
"rust",
"regex",
"sql",
"toml",
"yaml",
]
)
199 changes: 55 additions & 144 deletions src/textual/tree-sitter/highlights/bash.scm
Original file line number Diff line number Diff line change
@@ -1,145 +1,56 @@
(simple_expansion) @none
(expansion
"${" @punctuation.special
"}" @punctuation.special) @none
[
"("
")"
"(("
"))"
"{"
"}"
"["
"]"
"[["
"]]"
] @punctuation.bracket

[
";"
";;"
(heredoc_start)
] @punctuation.delimiter

[
"$"
] @punctuation.special

[
">"
">>"
"<"
"<<"
"&"
"&&"
"|"
"||"
"="
"=~"
"=="
"!="
] @operator

[
(string)
(raw_string)
(ansi_c_string)
(heredoc_body)
] @string @spell

(variable_assignment (word) @string)

[
"if"
"then"
"else"
"elif"
"fi"
"case"
"in"
"esac"
] @conditional

[
"for"
"do"
"done"
"select"
"until"
"while"
] @repeat

[
"declare"
"export"
"local"
"readonly"
"unset"
] @keyword

"function" @keyword.function

(special_variable_name) @constant

; trap -l
((word) @constant.builtin
(#match? @constant.builtin "^SIG(HUP|INT|QUIT|ILL|TRAP|ABRT|BUS|FPE|KILL|USR[12]|SEGV|PIPE|ALRM|TERM|STKFLT|CHLD|CONT|STOP|TSTP|TT(IN|OU)|URG|XCPU|XFSZ|VTALRM|PROF|WINCH|IO|PWR|SYS|RTMIN([+]([1-9]|1[0-5]))?|RTMAX(-([1-9]|1[0-4]))?)$"))

((word) @boolean
(#any-of? @boolean "true" "false"))

(comment) @comment @spell
(test_operator) @string

(command_substitution
[ "$(" ")" ] @punctuation.bracket)

(process_substitution
[ "<(" ")" ] @punctuation.bracket)


(function_definition
name: (word) @function)

(command_name (word) @function.call)

((command_name (word) @function.builtin)
(#any-of? @function.builtin
"alias" "bg" "bind" "break" "builtin" "caller" "cd"
"command" "compgen" "complete" "compopt" "continue"
"coproc" "dirs" "disown" "echo" "enable" "eval"
"exec" "exit" "fc" "fg" "getopts" "hash" "help"
"history" "jobs" "kill" "let" "logout" "mapfile"
"popd" "printf" "pushd" "pwd" "read" "readarray"
"return" "set" "shift" "shopt" "source" "suspend"
"test" "time" "times" "trap" "type" "typeset"
"ulimit" "umask" "unalias" "wait"))

(command
argument: [
(word) @parameter
(concatenation (word) @parameter)
])

((word) @number
(#lua-match? @number "^[0-9]+$"))

(file_redirect
descriptor: (file_descriptor) @operator
destination: (word) @parameter)

(expansion
[ "${" "}" ] @punctuation.bracket)

(variable_name) @variable

((variable_name) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))

(case_item
value: (word) @parameter)

(regex) @string.regex

((program . (comment) @preproc)
(#lua-match? @preproc "^#!/"))
(string)
(raw_string)
(heredoc_body)
(heredoc_start)
] @string

(command_name) @function

(variable_name) @property

[
"case"
"do"
"done"
"elif"
"else"
"esac"
"export"
"fi"
"for"
"function"
"if"
"in"
"select"
"then"
"unset"
"until"
"while"
] @keyword

(comment) @comment

(function_definition name: (word) @function)

(file_descriptor) @number

[
(command_substitution)
(process_substitution)
(expansion)
]@embedded

[
"$"
"&&"
">"
">>"
"<"
"|"
] @operator

(
(command (_) @constant)
(#match? @constant "^-")
)
123 changes: 123 additions & 0 deletions src/textual/tree-sitter/highlights/go.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
; Function calls

(call_expression
function: (identifier) @function.builtin
(.match? @function.builtin "^(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)$"))

(call_expression
function: (identifier) @function)

(call_expression
function: (selector_expression
field: (field_identifier) @function.method))

; Function definitions

(function_declaration
name: (identifier) @function)

(method_declaration
name: (field_identifier) @function.method)

; Identifiers

(type_identifier) @type
(field_identifier) @property
(identifier) @variable

; Operators

[
"--"
"-"
"-="
":="
"!"
"!="
"..."
"*"
"*"
"*="
"/"
"/="
"&"
"&&"
"&="
"%"
"%="
"^"
"^="
"+"
"++"
"+="
"<-"
"<"
"<<"
"<<="
"<="
"="
"=="
">"
">="
">>"
">>="
"|"
"|="
"||"
"~"
] @operator

; Keywords

[
"break"
"case"
"chan"
"const"
"continue"
"default"
"defer"
"else"
"fallthrough"
"for"
"func"
"go"
"goto"
"if"
"import"
"interface"
"map"
"package"
"range"
"return"
"select"
"struct"
"switch"
"type"
"var"
] @keyword

; Literals

[
(interpreted_string_literal)
(raw_string_literal)
(rune_literal)
] @string

(escape_sequence) @escape

[
(int_literal)
(float_literal)
(imaginary_literal)
] @number

[
(true)
(false)
(nil)
(iota)
] @constant.builtin

(comment) @comment
Loading

0 comments on commit ccc71b0

Please sign in to comment.