Kotlin Compose Multiplatform components for syntax highlighting based on Highlights library.
![iShot_2023-09-14_08 19 21](https://private-user-images.githubusercontent.com/8405055/268093552-adb205e4-ea16-41f7-aacb-de1085d6d5f5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5OTkyODQsIm5iZiI6MTcyNTk5ODk4NCwicGF0aCI6Ii84NDA1MDU1LzI2ODA5MzU1Mi1hZGIyMDVlNC1lYTE2LTQxZjctYWFjYi1kZTEwODVkNmQ1ZjUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDkxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA5MTBUMjAwOTQ0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTFjNDM1Y2Y4YjY3MjhiN2U5Njk2MzYzYzg0YTEyOGI4YzMzY2VmYThmOGVjMzg1ZTcxZmIzNWVmMTA3MDM1MyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.YOhtz65-aI9AsXP7CaiglSIZz1al5hSS3rrSNmAwv04)
repositories {
mavenCentral()
}
implementation("dev.snipme:kodeview:0.8.0")
- CodeTextView
- CodeEditText
- Code component analysis (Keyword, comment, etc.)
- Multiple syntax languages (Java, Swift, Kotlin, C, ...)
- Themes
- Text bolding (emphasis)
- Written in pure Kotlin, so available for many platforms 📱 💻 🖥️
Kotlin Multiplatform is a fresh environment and developing for it is neither fast nor easy 🥲
If you feel that any of our project has saved you a time or effort, then consider supporting us via:
🧋 Buy Me A Coffee
Basic component that takes instance of Highlights and applies coloring on a text.
@Composable
fun MyApp() {
val highlights = remember {
mutableStateOf(
Highlights
.Builder(code = "public static void main(String[] args) {}")
.build()
)
}
MaterialTheme {
Column {
CodeTextView(highlights = highlights.value)
}
}
}
With this component, you can update your code via onValueChange
callback.
The Highlights library is ready for incremental updates, so change values anytime.
The view bases on TextField()
, and all it's fields are available for customization.
@Composable
fun MyApp() {
val highlights = remember {
mutableStateOf(
Highlights
.Builder(code = "public static void main(String[] args) {}")
.build()
)
}
MaterialTheme {
Column {
CodeEditText(
highlights = highlights.value,
onValueChange = { textValue ->
highlights.value = highlights.value.getBuilder()
.code(textValue)
.build()
},
// Customize view's style
colors = TextFieldDefaults.textFieldColors(),
)
}
}
}
Not all examples can be executed from command line, so recommended way is to use pre-created configurations:
![iShot_2023-09-18_08 19 44](https://private-user-images.githubusercontent.com/8405055/268567596-be660f49-5a77-445e-a717-6aaec9b5c28a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5OTkyODQsIm5iZiI6MTcyNTk5ODk4NCwicGF0aCI6Ii84NDA1MDU1LzI2ODU2NzU5Ni1iZTY2MGY0OS01YTc3LTQ0NWUtYTcxNy02YWFlYzliNWMyOGEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDkxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA5MTBUMjAwOTQ0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODlhMjQ1MzU1MWVmNTY5MGY2NWY1ZTY1ZDUxZGFlZDY1MmQwOWUyMTI3MWY0Zjk1YTQ1NTBlODQ5MjczNDdlYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.zWLENaWLrkIDZxk5Lc-proY4qPnTguBhp301jryH5go)
- CodeEditText
Any form of support is very welcomed.
Bugs, problems and new feature requests should be placed in the Issues
tab with proper labeling.
New feature can be also submitted via Pull Requests
.
Then make sure:
- CHANGELOG and README have been updated
- New code matches library's vision and code style
Copyright 2023 Tomasz Kądziołka.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.