├── .gitignore ├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── css-attr.gif ├── css-text.gif ├── ansi4j-css-demo └── src │ └── main │ ├── resources │ ├── com │ │ └── techsenger │ │ │ └── ansi4j │ │ │ └── css │ │ │ └── demo │ │ │ ├── fonts │ │ │ ├── JetBrainsMonoNL-Bold.ttf │ │ │ ├── JetBrainsMonoNL-Light.ttf │ │ │ ├── JetBrainsMonoNL-Thin.ttf │ │ │ ├── JetBrainsMonoNL-Italic.ttf │ │ │ ├── JetBrainsMonoNL-Medium.ttf │ │ │ ├── JetBrainsMonoNL-Regular.ttf │ │ │ ├── JetBrainsMonoNL-SemiBold.ttf │ │ │ ├── JetBrainsMonoNL-BoldItalic.ttf │ │ │ ├── JetBrainsMonoNL-ExtraBold.ttf │ │ │ ├── JetBrainsMonoNL-ExtraLight.ttf │ │ │ ├── JetBrainsMonoNL-ThinItalic.ttf │ │ │ ├── JetBrainsMonoNL-LightItalic.ttf │ │ │ ├── JetBrainsMonoNL-MediumItalic.ttf │ │ │ ├── JetBrainsMonoNL-ExtraBoldItalic.ttf │ │ │ ├── JetBrainsMonoNL-SemiBoldItalic.ttf │ │ │ ├── JetBrainsMonoNL-ExtraLightItalic.ttf │ │ │ └── JetBrainsMonoNL-AUTHORS.txt │ │ │ └── demo.css │ └── log4j2.xml │ └── java │ ├── com │ └── techsenger │ │ └── ansi4j │ │ └── css │ │ └── demo │ │ ├── mvvm │ │ ├── ComponentService.java │ │ ├── ViewModel.java │ │ └── View.java │ │ ├── text │ │ ├── TargetControlBuilder.java │ │ ├── SgrParameter.java │ │ ├── TextComponentService.java │ │ ├── CommandViewModel.java │ │ └── CommandView.java │ │ ├── AbstractTabViewModel.java │ │ ├── TargetControl.java │ │ ├── content │ │ ├── ContentBuilder.java │ │ ├── TextFlowContentBuilder.java │ │ └── RtfxTextAreaContentBuilder.java │ │ ├── AbstractTabView.java │ │ ├── Constants.java │ │ ├── attribute │ │ ├── SampleContent.java │ │ ├── ItalicSample.java │ │ ├── VisibilitySample.java │ │ ├── StrikethroughSample.java │ │ ├── ReverseVideoSample.java │ │ ├── BlinkingSample.java │ │ ├── IntensitySample.java │ │ ├── UnderlineSample.java │ │ ├── FontSample.java │ │ ├── BgColorSample.java │ │ ├── FgColorSample.java │ │ ├── SampleContents.java │ │ └── AttributeTabViewModel.java │ │ ├── utils │ │ └── TextUtils.java │ │ ├── material │ │ ├── StatusBar.java │ │ └── Dialog.java │ │ ├── DemoComponentService.java │ │ └── DemoViewModel.java │ └── module-info.java ├── ansi4j-core-it ├── src │ ├── test │ │ ├── resources │ │ │ └── log4j2.xml │ │ └── java │ │ │ ├── com │ │ │ └── techsenger │ │ │ │ └── ansi4j │ │ │ │ └── core │ │ │ │ └── it │ │ │ │ └── package-info.java │ │ │ └── module-info.java │ └── main │ │ └── java │ │ └── module-info.java └── pom.xml ├── ansi4j-css-it ├── src │ ├── test │ │ ├── resources │ │ │ └── log4j2.xml │ │ └── java │ │ │ ├── com │ │ │ └── techsenger │ │ │ │ └── ansi4j │ │ │ │ └── css │ │ │ │ └── it │ │ │ │ └── package-info.java │ │ │ └── module-info.java │ └── main │ │ └── java │ │ └── module-info.java └── pom.xml ├── ansi4j-core-impl ├── src │ ├── test │ │ ├── resources │ │ │ └── log4j2.xml │ │ └── java │ │ │ ├── com │ │ │ └── techsenger │ │ │ │ └── ansi4j │ │ │ │ └── core │ │ │ │ └── impl │ │ │ │ ├── package-info.java │ │ │ │ └── iso6429 │ │ │ │ ├── ControlSequenceMatcherTest.java │ │ │ │ └── ControlSequenceUtilsTest.java │ │ │ └── module-info.java │ └── main │ │ └── java │ │ ├── com │ │ └── techsenger │ │ │ └── ansi4j │ │ │ └── core │ │ │ └── impl │ │ │ ├── package-info.java │ │ │ ├── FunctionMatcher.java │ │ │ ├── ParserFactoryProvider.java │ │ │ ├── TextFragmentImpl.java │ │ │ ├── AbstractFragmentHandlerResult.java │ │ │ ├── TextHandlerResultImpl.java │ │ │ ├── FunctionHandlerResultImpl.java │ │ │ ├── TextHandlerImpl.java │ │ │ ├── function │ │ │ └── FunctionArgumentImpl.java │ │ │ ├── iso6429 │ │ │ ├── AbstractFunctionHandler.java │ │ │ ├── C0ControlFunctionHandler.java │ │ │ ├── IndependentControlFunctionHandler.java │ │ │ └── C1ControlFunctionHandler.java │ │ │ ├── StringParserImpl.java │ │ │ ├── FunctionDescriptor.java │ │ │ ├── FunctionFinderResultImpl.java │ │ │ ├── AbstractFragment.java │ │ │ └── FunctionFragmentImpl.java │ │ └── module-info.java └── pom.xml ├── ansi4j-css-impl ├── src │ └── main │ │ └── java │ │ ├── com │ │ └── techsenger │ │ │ └── ansi4j │ │ │ └── css │ │ │ ├── package-info.java │ │ │ └── impl │ │ │ ├── attribute │ │ │ ├── AbstractAttributeGroup.java │ │ │ ├── AttributeImpl.java │ │ │ └── AttributeRegistryImpl.java │ │ │ ├── StyleProcessorProvider.java │ │ │ ├── FunctionEvaluator.java │ │ │ └── ProcessorResultImpl.java │ │ └── module-info.java └── pom.xml ├── ansi4j-css-api ├── src │ └── main │ │ └── java │ │ ├── com │ │ └── techsenger │ │ │ └── ansi4j │ │ │ └── css │ │ │ └── api │ │ │ ├── package-info.java │ │ │ ├── color │ │ │ ├── PaletteType.java │ │ │ ├── Palette.java │ │ │ ├── Palette8.java │ │ │ ├── Palette16.java │ │ │ ├── Palette256.java │ │ │ ├── VsCodePalette16.java │ │ │ ├── VgaPalette16.java │ │ │ ├── XtermPalette16.java │ │ │ ├── Color8.java │ │ │ ├── Color16.java │ │ │ ├── ColorUtils.java │ │ │ ├── Color.java │ │ │ └── SgrExtraColorValue.java │ │ │ ├── spi │ │ │ ├── StyleProcessorService.java │ │ │ └── StyleProcessorConfig.java │ │ │ ├── attribute │ │ │ ├── Attribute.java │ │ │ ├── AttributeGroupConfig.java │ │ │ ├── AttributeGroup.java │ │ │ ├── AttributeRegistry.java │ │ │ └── AttributeChange.java │ │ │ ├── ProcessorResult.java │ │ │ ├── text │ │ │ ├── FontIndex.java │ │ │ └── TextAttributeGroup.java │ │ │ └── GroupStyleGenerator.java │ │ └── module-info.java └── pom.xml └── ansi4j-core-api ├── src └── main │ └── java │ ├── com │ └── techsenger │ │ └── ansi4j │ │ └── core │ │ └── api │ │ ├── package-info.java │ │ ├── Environment.java │ │ ├── FragmentType.java │ │ ├── function │ │ ├── FunctionType.java │ │ ├── FunctionArgument.java │ │ └── Function.java │ │ ├── FailureReason.java │ │ ├── TextFragment.java │ │ ├── FragmentHandler.java │ │ ├── spi │ │ └── ParserFactoryService.java │ │ ├── Initializable.java │ │ ├── StringParser.java │ │ ├── iso6429 │ │ ├── ControlFunction.java │ │ ├── AllControlFunctionAlias.java │ │ ├── ControlFunctionType.java │ │ └── IndependentControlFunctionAlias.java │ │ ├── FragmentHandlerResult.java │ │ ├── TextHandlerResult.java │ │ ├── FunctionHandlerResult.java │ │ ├── FunctionFinder.java │ │ ├── FunctionFailureReason.java │ │ ├── Parser.java │ │ ├── FunctionFragment.java │ │ ├── TextHandler.java │ │ ├── StreamParser.java │ │ ├── Fragment.java │ │ ├── FunctionFinderResult.java │ │ ├── utils │ │ └── Characters.java │ │ └── FunctionHandler.java │ └── module-info.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: techsenger -------------------------------------------------------------------------------- /css-attr.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/css-attr.gif -------------------------------------------------------------------------------- /css-text.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/css-text.gif -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve the project 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Bold.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Light.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Thin.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Italic.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Medium.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-Regular.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-SemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-SemiBold.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-BoldItalic.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ExtraBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ExtraBold.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ExtraLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ExtraLight.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ThinItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ThinItalic.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-LightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-LightItalic.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-MediumItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-MediumItalic.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ExtraBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ExtraBoldItalic.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-SemiBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-SemiBoldItalic.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ExtraLightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/ansi4j/HEAD/ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-ExtraLightItalic.ttf -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/fonts/JetBrainsMonoNL-AUTHORS.txt: -------------------------------------------------------------------------------- 1 | # This is the official list of project authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS.txt file. 3 | # See the latter for an explanation. 4 | # 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | 8 | JetBrains <> 9 | Philipp Nurullin 10 | Konstantin Bulenkov 11 | -------------------------------------------------------------------------------- /ansi4j-core-it/src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ansi4j-css-it/src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ansi4j-css-it/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.css.it { 18 | 19 | } -------------------------------------------------------------------------------- /ansi4j-core-it/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.core.it { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /ansi4j-css-impl/src/main/java/com/techsenger/ansi4j/css/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css; 18 | -------------------------------------------------------------------------------- /ansi4j-core-it/src/test/java/com/techsenger/ansi4j/core/it/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.it; 18 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api; 18 | -------------------------------------------------------------------------------- /ansi4j-css-it/src/test/java/com/techsenger/ansi4j/css/it/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.it; 18 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/test/java/com/techsenger/ansi4j/core/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/Environment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public enum Environment { 24 | 25 | _7_BIT, _8_BIT 26 | } 27 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FragmentType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public enum FragmentType { 24 | 25 | TEXT, FUNCTION 26 | } 27 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/function/FunctionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.function; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface FunctionType { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/mvvm/ComponentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.mvvm; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface ComponentService { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FailureReason.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | /** 20 | * Marker interface. 21 | * 22 | * @author Pavel Castornii 23 | */ 24 | public interface FailureReason { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/test/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | open module com.techsenger.ansi4j.core.impl { 18 | requires com.techsenger.ansi4j.core.api; 19 | requires org.slf4j; 20 | 21 | requires org.junit.jupiter.api; 22 | requires org.assertj.core; 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/PaletteType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public enum PaletteType { 24 | 25 | PALETTE_8, PALETTE_16, PALETTE_256, 26 | } 27 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/text/TargetControlBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.text; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | interface TargetControlBuilder { 24 | 25 | T build(C content); 26 | } 27 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/mvvm/ViewModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.mvvm; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface ViewModel { 24 | 25 | void setComponentService(ComponentService s); 26 | } 27 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/Palette.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface Palette { 24 | 25 | PaletteType getType(); 26 | 27 | int[] getColors(); 28 | } 29 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/mvvm/View.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.mvvm; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface View { 24 | 25 | T getViewModel(); 26 | 27 | Object getNode(); 28 | } 29 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/TextFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.Immutable; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | @Immutable 26 | public interface TextFragment extends Fragment { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.core.impl { 18 | requires com.techsenger.ansi4j.core.api; 19 | requires org.slf4j; 20 | 21 | provides com.techsenger.ansi4j.core.api.spi.ParserFactoryService 22 | with com.techsenger.ansi4j.core.impl.ParserFactoryProvider; 23 | } 24 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FragmentHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.ThreadSafe; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | @ThreadSafe 26 | public interface FragmentHandler extends Initializable { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/Palette8.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface Palette8 extends Palette { 24 | 25 | @Override 26 | default PaletteType getType() { 27 | return PaletteType.PALETTE_8; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/Palette16.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface Palette16 extends Palette8 { 24 | 25 | @Override 26 | default PaletteType getType() { 27 | return PaletteType.PALETTE_16; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/Palette256.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface Palette256 extends Palette16 { 24 | 25 | @Override 26 | default PaletteType getType() { 27 | return PaletteType.PALETTE_256; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/spi/ParserFactoryService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.spi; 18 | 19 | import com.techsenger.ansi4j.core.api.ParserFactory; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | public interface ParserFactoryService { 26 | 27 | ParserFactory createFactory(ParserFactoryConfig config); 28 | } 29 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/Initializable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface Initializable { 24 | 25 | /** 26 | * Initializes object with environment. 27 | * @param environment 28 | */ 29 | void initialize(Environment environment); 30 | } 31 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/spi/StyleProcessorService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.spi; 18 | 19 | import com.techsenger.ansi4j.css.api.StyleProcessor; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | public interface StyleProcessorService { 26 | 27 | StyleProcessor createProcessor(StyleProcessorConfig config); 28 | } 29 | -------------------------------------------------------------------------------- /ansi4j-core-it/src/test/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.core.it { 18 | requires com.techsenger.ansi4j.core.api; 19 | requires com.techsenger.ansi4j.core.impl; 20 | 21 | requires org.slf4j; 22 | requires org.junit.jupiter.api; 23 | requires org.junit.jupiter.params; 24 | requires org.assertj.core; 25 | 26 | opens com.techsenger.ansi4j.core.it; 27 | } 28 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/AbstractTabViewModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo; 18 | 19 | import com.techsenger.ansi4j.css.demo.mvvm.ViewModel; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | public abstract class AbstractTabViewModel implements ViewModel { 26 | 27 | public AbstractTabViewModel() { 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/StringParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.NotThreadSafe; 20 | 21 | /** 22 | * String parser is very light and can be created for every text line if necessary. 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @NotThreadSafe 27 | public interface StringParser extends Parser { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/attribute/Attribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.attribute; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface Attribute { 24 | 25 | String getName(); 26 | 27 | AttributeGroup getGroup(); 28 | 29 | T getDefaultValue(); 30 | 31 | T getValue(); 32 | 33 | boolean isValueDefault(); 34 | } 35 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/attribute/AttributeGroupConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.attribute; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface AttributeGroupConfig> { 24 | 25 | /** 26 | * Returns the key of the group. 27 | * @return 28 | */ 29 | AttributeGroup.Key getGroupKey(); 30 | } 31 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/iso6429/ControlFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.iso6429; 18 | 19 | import javax.annotation.concurrent.Immutable; 20 | import com.techsenger.ansi4j.core.api.function.Function; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @Immutable 27 | public interface ControlFunction extends Function { 28 | 29 | ControlFunctionType getType(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/iso6429/AllControlFunctionAlias.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.iso6429; 18 | 19 | /** 20 | * This interface contains the aliases of all control functions. 21 | * 22 | * @author Pavel Castornii 23 | */ 24 | public interface AllControlFunctionAlias extends C0ControlFunctionAlias, C1ControlFunctionAlias, 25 | ControlSequenceFunctionAlias, IndependentControlFunctionAlias { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ansi4j-css-impl/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.css.impl { 18 | requires com.techsenger.ansi4j.core.api; 19 | requires com.techsenger.ansi4j.css.api; 20 | requires org.slf4j; 21 | 22 | exports com.techsenger.ansi4j.css.impl.attribute to com.techsenger.ansi4j.css.demo; 23 | 24 | provides com.techsenger.ansi4j.css.api.spi.StyleProcessorService 25 | with com.techsenger.ansi4j.css.impl.StyleProcessorProvider; 26 | } -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FragmentHandlerResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.Immutable; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | @Immutable 26 | public interface FragmentHandlerResult { 27 | 28 | /** 29 | * The reason why fragment wasn't parsed. 30 | * 31 | * @return 32 | */ 33 | FailureReason getFailureReason(); 34 | } 35 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/iso6429/ControlFunctionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.iso6429; 18 | 19 | import com.techsenger.ansi4j.core.api.function.FunctionType; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | public enum ControlFunctionType implements FunctionType { 26 | 27 | C0_SET, 28 | 29 | C1_SET, 30 | 31 | CONTROL_SEQUENCE, 32 | 33 | INDEPENDENT_FUNCTION, 34 | 35 | CONTROL_STRING 36 | } 37 | -------------------------------------------------------------------------------- /ansi4j-css-it/src/test/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.css.it { 18 | requires com.techsenger.ansi4j.core.api; 19 | requires com.techsenger.ansi4j.core.impl; 20 | requires com.techsenger.ansi4j.css.api; 21 | requires com.techsenger.ansi4j.css.impl; 22 | requires org.slf4j; 23 | 24 | requires org.junit.jupiter.api; 25 | requires org.junit.jupiter.params; 26 | requires org.assertj.core; 27 | 28 | opens com.techsenger.ansi4j.css.it; 29 | } 30 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/TargetControl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public enum TargetControl { 24 | 25 | /** 26 | * For this control standard web CSS styles will be generated. 27 | */ 28 | WEB_VIEW, 29 | 30 | /** 31 | * JavaFX TextFlow. 32 | */ 33 | TEXT_FLOW, 34 | 35 | /** 36 | * RichTextFX text areas. 37 | */ 38 | RTFX_TEXT_AREA 39 | } 40 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/TextHandlerResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import java.util.Optional; 20 | import javax.annotation.concurrent.Immutable; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @Immutable 27 | public interface TextHandlerResult extends FragmentHandlerResult { 28 | 29 | /** 30 | * Parsed fragment or empty optional. 31 | * 32 | * @return 33 | */ 34 | Optional getFragment(); 35 | } 36 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.core.api { 18 | requires org.slf4j; 19 | requires jsr305; 20 | 21 | exports com.techsenger.ansi4j.core.api; 22 | exports com.techsenger.ansi4j.core.api.function; 23 | exports com.techsenger.ansi4j.core.api.iso6429; 24 | exports com.techsenger.ansi4j.core.api.spi to com.techsenger.ansi4j.core.impl; 25 | exports com.techsenger.ansi4j.core.api.utils; 26 | 27 | uses com.techsenger.ansi4j.core.api.spi.ParserFactoryService; 28 | } -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FunctionHandlerResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import java.util.Optional; 20 | import javax.annotation.concurrent.Immutable; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @Immutable 27 | public interface FunctionHandlerResult extends FragmentHandlerResult { 28 | 29 | /** 30 | * Parsed fragment or empty optional. 31 | * 32 | * @return 33 | */ 34 | Optional getFragment(); 35 | } 36 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/FunctionMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface FunctionMatcher { 24 | 25 | /** 26 | * Matches function in text to one of the supported functions of certain type. 27 | * @param startIndex 28 | * @param text 29 | * @return descriptor if function was matched, otherwise null. 30 | */ 31 | FunctionDescriptor match(int startIndex, String text); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/content/ContentBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.content; 18 | 19 | import com.techsenger.ansi4j.css.demo.TargetControl; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | public interface ContentBuilder { 26 | 27 | TargetControl getTargetControl(); 28 | 29 | void startStyle(String style); 30 | 31 | void endStyle(); 32 | 33 | void appendText(String text); 34 | 35 | void terminateLine(); 36 | 37 | T build(); 38 | } 39 | -------------------------------------------------------------------------------- /ansi4j-css-impl/src/main/java/com/techsenger/ansi4j/css/impl/attribute/AbstractAttributeGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.impl.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.attribute.AttributeGroup; 21 | import java.util.List; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | public abstract class AbstractAttributeGroup> implements AttributeGroup { 28 | 29 | public abstract List> getAttributes(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.css.api { 18 | requires com.techsenger.ansi4j.core.api; 19 | requires org.slf4j; 20 | requires jsr305; 21 | 22 | exports com.techsenger.ansi4j.css.api; 23 | exports com.techsenger.ansi4j.css.api.attribute; 24 | exports com.techsenger.ansi4j.css.api.color; 25 | exports com.techsenger.ansi4j.css.api.spi to com.techsenger.ansi4j.css.impl; 26 | exports com.techsenger.ansi4j.css.api.text; 27 | 28 | uses com.techsenger.ansi4j.css.api.spi.StyleProcessorService; 29 | } -------------------------------------------------------------------------------- /ansi4j-core-api/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techsenger.ansi4j 6 | ansi4j 7 | 2.1.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.ansi4j 11 | ansi4j-core-api 12 | jar 13 | ANSI4J - Core API 14 | API for text parsing 15 | 16 | 17 | 18 | com.google.code.findbugs 19 | jsr305 20 | 21 | 22 | org.slf4j 23 | slf4j-api 24 | 25 | 26 | org.junit.jupiter 27 | junit-jupiter-api 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FunctionFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import java.util.Optional; 20 | import javax.annotation.concurrent.ThreadSafe; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @ThreadSafe 27 | public interface FunctionFinder extends Initializable { 28 | 29 | /** 30 | * Finds function in text. 31 | * 32 | * @param startIndex 33 | * @param text 34 | * @return finder result or null if function isn't found. 35 | */ 36 | Optional find(int startIndex, String text); 37 | } 38 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/ParserFactoryProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import com.techsenger.ansi4j.core.api.ParserFactory; 20 | import com.techsenger.ansi4j.core.api.spi.ParserFactoryConfig; 21 | import com.techsenger.ansi4j.core.api.spi.ParserFactoryService; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | public class ParserFactoryProvider implements ParserFactoryService { 28 | 29 | @Override 30 | public ParserFactory createFactory(ParserFactoryConfig config) { 31 | return new ParserFactoryImpl(config); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ansi4j-css-impl/src/main/java/com/techsenger/ansi4j/css/impl/StyleProcessorProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.impl; 18 | 19 | import com.techsenger.ansi4j.css.api.spi.StyleProcessorConfig; 20 | import com.techsenger.ansi4j.css.api.StyleProcessor; 21 | import com.techsenger.ansi4j.css.api.spi.StyleProcessorService; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | public class StyleProcessorProvider implements StyleProcessorService { 28 | 29 | @Override 30 | public StyleProcessor createProcessor(StyleProcessorConfig config) { 31 | return new StyleProcessorImpl(config); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FunctionFailureReason.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public enum FunctionFailureReason implements FailureReason { 24 | 25 | /** 26 | * Parser can't parse function as it doesn't know how to parse it. 27 | */ 28 | UNKNOWN_FUNCTION, 29 | 30 | /** 31 | * This reason happens when text for parsing is read from stream. Using this reason parser understands 32 | * if it can parse function or parsing must be repeated when whole function is read from the stream. 33 | */ 34 | NO_END_OF_FUNCTION 35 | } 36 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/TextFragmentImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import com.techsenger.ansi4j.core.api.FragmentType; 20 | import com.techsenger.ansi4j.core.api.TextFragment; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | public class TextFragmentImpl extends AbstractFragment implements TextFragment { 27 | 28 | public TextFragmentImpl(String text, int currentIndex) { 29 | super(FragmentType.TEXT, text, currentIndex); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "TextFragmentImpl{" + '}' + "->" + super.toString(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/VsCodePalette16.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 16 colors for VS. See https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit 21 | * 22 | * @author Pavel Castornii 23 | */ 24 | public class VsCodePalette16 implements Palette16 { 25 | 26 | private final int[] colors = new int[] { 27 | 0x000000, 0xcd3131, 0x0dbc79, 0xe5e510, 0x2472c8, 0xbc3fbc, 0x11a8cd, 0xe5e5e5, 28 | 0x666666, 0xf14c4c, 0x23d18b, 0xf5f543, 0x3b8eea, 0xd670d6, 0x29b8db, 0xe5e5e5 29 | }; 30 | 31 | @Override 32 | public int[] getColors() { 33 | return colors; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/function/FunctionArgument.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.function; 18 | 19 | import javax.annotation.concurrent.Immutable; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | @Immutable 26 | public interface FunctionArgument { 27 | 28 | /** 29 | * Returns the value of the parameter. It can be either an explicit value or a default value. 30 | * 31 | */ 32 | Object getValue(); 33 | 34 | /** 35 | * This flag allows to check if parameter value is default (escape code didn't contain explicit value). 36 | * 37 | * @return 38 | */ 39 | boolean isDefault(); 40 | } 41 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/VgaPalette16.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 16 colors for VGA. See https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit 21 | * 22 | * @author Pavel Castornii 23 | */ 24 | public class VgaPalette16 implements Palette16 { 25 | 26 | private final int[] colors = new int[] { 27 | 0x000000, 0xaa0000, 0x00aa00, 0xaa5500, 0x0000aa, 0xaa00aa, 0x00aaaa, 0xaaaaaa, 28 | 0x555555, 0xff5555, 0x55ff55, 0xffff55, 0x5555ff, 0xff55ff, 0x55ffff, 0xffffff 29 | }; 30 | 31 | @Override 32 | public int[] getColors() { 33 | return colors; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/XtermPalette16.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 16 colors for Xterm. See https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit 21 | * 22 | * @author Pavel Castornii 23 | */ 24 | public class XtermPalette16 implements Palette16 { 25 | 26 | private final int[] colors = new int[] { 27 | 0x000000, 0xcd0000, 0x00cd00, 0xcdcd00, 0x0000ee, 0xcd00cd, 0x00cdcd, 0xe5e5e5, 28 | 0x7f7f7f, 0xff0000, 0x00ff00, 0xffff00, 0x5c5cff, 0xff00ff, 0x00ffff, 0xffffff 29 | }; 30 | 31 | @Override 32 | public int[] getColors() { 33 | return colors; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/attribute/AttributeGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.attribute; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface AttributeGroup> { 24 | 25 | class Key> { } 26 | 27 | /** 28 | * Returns group key. 29 | * 30 | * @return 31 | */ 32 | Key getKey(); 33 | 34 | /** 35 | * Returns the config of the group. 36 | * 37 | * @return 38 | */ 39 | AttributeGroupConfig getConfig(); 40 | 41 | /** 42 | * Resets all the attributes of the group to their default values. 43 | */ 44 | void reset(); 45 | } 46 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/attribute/AttributeRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.attribute; 18 | 19 | import java.util.Set; 20 | import javax.annotation.concurrent.NotThreadSafe; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @NotThreadSafe 27 | public interface AttributeRegistry { 28 | 29 | /** 30 | * Returns an attribute group by group key. 31 | * 32 | * @param key 33 | * @return 34 | */ 35 | > T getGroup(AttributeGroup.Key key); 36 | 37 | /** 38 | * Returns the keys of all groups. 39 | * 40 | * @return 41 | */ 42 | Set> getGroupKeys(); 43 | } 44 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/Color8.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * All these colors are indexes in palette. 21 | * 22 | * @author Pavel Castornii 23 | */ 24 | public final class Color8 { 25 | 26 | public static final int BLACK = 0; 27 | 28 | public static final int RED = 1; 29 | 30 | public static final int GREEN = 2; 31 | 32 | public static final int YELLOW = 3; 33 | 34 | public static final int BLUE = 4; 35 | 36 | public static final int MAGENTA = 5; 37 | 38 | public static final int CYAN = 6; 39 | 40 | public static final int WHITE = 7; 41 | 42 | private Color8() { 43 | //empty 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/AbstractFragmentHandlerResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import com.techsenger.ansi4j.core.api.FailureReason; 20 | import com.techsenger.ansi4j.core.api.FragmentHandlerResult; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | abstract class AbstractFragmentHandlerResult implements FragmentHandlerResult { 27 | 28 | private final FailureReason failureReason; 29 | 30 | AbstractFragmentHandlerResult(FailureReason failureReason) { 31 | this.failureReason = failureReason; 32 | } 33 | 34 | @Override 35 | public FailureReason getFailureReason() { 36 | return this.failureReason; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/Parser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.NotThreadSafe; 20 | 21 | /** 22 | * Parses text with control functions. 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @NotThreadSafe 27 | public interface Parser { 28 | 29 | /** 30 | * Parses next fragment and returns it. 31 | * 32 | * @return fragment or null if there is no fragments to parse. 33 | */ 34 | Fragment parse(); 35 | 36 | /** 37 | * Returns current index in text. Everything before index has been parsed, everything after index hasn't been 38 | * parsed. 39 | * 40 | * @return 41 | */ 42 | int getCurrentIndex(); 43 | } 44 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/AbstractTabView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo; 18 | 19 | import com.techsenger.ansi4j.css.demo.mvvm.View; 20 | import javafx.scene.control.Tab; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | public abstract class AbstractTabView implements View { 27 | 28 | private final T viewModel; 29 | 30 | private final Tab tab = new Tab(); 31 | 32 | public AbstractTabView(T viewModel) { 33 | this.viewModel = viewModel; 34 | } 35 | 36 | @Override 37 | public T getViewModel() { 38 | return this.viewModel; 39 | } 40 | 41 | public Tab getNode() { 42 | return this.tab; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FunctionFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import com.techsenger.ansi4j.core.api.function.FunctionArgument; 20 | import java.util.List; 21 | import javax.annotation.concurrent.Immutable; 22 | import com.techsenger.ansi4j.core.api.function.Function; 23 | 24 | /** 25 | * 26 | * @author Pavel Castornii 27 | */ 28 | @Immutable 29 | public interface FunctionFragment extends Fragment { 30 | 31 | /** 32 | * Returns function. 33 | * 34 | * @return 35 | */ 36 | Function getFunction(); 37 | 38 | /** 39 | * Returns functions arguments or empty list. 40 | * 41 | * @return 42 | */ 43 | List getArguments(); 44 | } 45 | -------------------------------------------------------------------------------- /ansi4j-css-api/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techsenger.ansi4j 6 | ansi4j 7 | 2.1.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.ansi4j 11 | ansi4j-css-api 12 | jar 13 | ANSI4J - CSS API 14 | API for text styling with CSS 15 | 16 | 17 | 18 | com.techsenger.ansi4j 19 | ansi4j-core-api 20 | 21 | 22 | com.google.code.findbugs 23 | jsr305 24 | 25 | 26 | org.slf4j 27 | slf4j-api 28 | 29 | 30 | org.junit.jupiter 31 | junit-jupiter-api 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/ProcessorResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.AttributeChange; 20 | import java.util.List; 21 | import javax.annotation.concurrent.Immutable; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | @Immutable 28 | public interface ProcessorResult { 29 | 30 | /** 31 | * Returns the attribute changes that occurred during the function processing. 32 | * 33 | * @return 34 | */ 35 | List> getAttributeChanges(); 36 | 37 | /** 38 | * Returns a list of CSS declarations without a semicolon at the end. 39 | * 40 | * @return 41 | */ 42 | List getStyleDeclarations(); 43 | } 44 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/Color16.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * All these colors are indexes in a palette. 21 | * 22 | * @author Pavel Castornii 23 | */ 24 | public final class Color16 { 25 | 26 | public static final int BRIGHT_BLACK = 8; 27 | 28 | public static final int BRIGHT_RED = 9; 29 | 30 | public static final int BRIGHT_GREEN = 10; 31 | 32 | public static final int BRIGHT_YELLOW = 11; 33 | 34 | public static final int BRIGHT_BLUE = 12; 35 | 36 | public static final int BRIGHT_MAGENTA = 13; 37 | 38 | public static final int BRIGHT_CYAN = 14; 39 | 40 | public static final int BRIGHT_WHITE = 15; 41 | 42 | private Color16() { 43 | //empty 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/text/SgrParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.text; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | class SgrParameter { 24 | 25 | private final int code; 26 | 27 | private final String description; 28 | 29 | private final boolean supported; 30 | 31 | SgrParameter(int code, String description, boolean supported) { 32 | this.code = code; 33 | this.description = description; 34 | this.supported = supported; 35 | } 36 | 37 | public int getCode() { 38 | return code; 39 | } 40 | 41 | public String getDescription() { 42 | return description; 43 | } 44 | 45 | public boolean isSupported() { 46 | return supported; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/text/TextComponentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.text; 18 | 19 | import com.techsenger.ansi4j.css.demo.mvvm.ComponentService; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | class TextComponentService implements ComponentService { 26 | 27 | private final TextTabView view; 28 | 29 | TextComponentService(TextTabView view) { 30 | this.view = view; 31 | } 32 | 33 | public void openCommandDialog(CommandViewModel viewModel) { 34 | var v = new CommandView(viewModel); 35 | this.view.openDialog(v.getNode()); 36 | } 37 | 38 | public void openSgrDialog(SgrHelpViewModel viewModel) { 39 | var v = new SgrHelpView(viewModel); 40 | this.view.openDialog(v.getNode()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public final class Constants { 24 | 25 | public static final String MODAL_PANE_ID = "dialog-modal-pane"; 26 | 27 | public static final double INSET = 10; 28 | 29 | public static final double INSET_HALF = 5; 30 | 31 | public static final String FONT_FAMILY = "'JetBrains Mono NL'"; 32 | 33 | public static final String ALTERNATIVE_FONT_FAMILY = "Arial"; 34 | 35 | public static final int FG_COLOR = 0xf8f8f2FF; // -color-fg-default 36 | 37 | public static final int BG_COLOR = 0x181920FF; // -color-bg-inset 38 | 39 | public static final int FONT_SIZE = 13; 40 | 41 | private Constants() { 42 | //empty 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/SampleContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | class SampleContent { 24 | 25 | private final T value; 26 | 27 | private final String defaultStyle; 28 | 29 | private final String currentStyle; 30 | 31 | SampleContent(T value, String defaultStyle, String currentStyle) { 32 | this.value = value; 33 | this.defaultStyle = defaultStyle; 34 | this.currentStyle = currentStyle; 35 | } 36 | 37 | public T getValue() { 38 | return value; 39 | } 40 | 41 | public String getDefaultStyle() { 42 | return defaultStyle; 43 | } 44 | 45 | public String getCurrentStyle() { 46 | return currentStyle; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/TextHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.ThreadSafe; 20 | 21 | /** 22 | * This parser can do any modification with text. 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @ThreadSafe 27 | public interface TextHandler extends FragmentHandler { 28 | 29 | /** 30 | * Parses text (string that doesn't contain functions). 31 | * 32 | * @param text is a piece of the whole text and doesn't have any functions. 33 | * @param currentIndex index in the whole text (is equal to parsed text length). This parameter is required for 34 | * calculating start and end index as they are relative to the whole text. 35 | * 36 | * @return 37 | */ 38 | TextHandlerResult handle(String text, int currentIndex); 39 | } 40 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/text/FontIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.text; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public final class FontIndex { 24 | 25 | public static final int DEFAULT = 0; 26 | 27 | public static final int ALTERNATIVE_1 = 1; 28 | 29 | public static final int ALTERNATIVE_2 = 2; 30 | 31 | public static final int ALTERNATIVE_3 = 3; 32 | 33 | public static final int ALTERNATIVE_4 = 4; 34 | 35 | public static final int ALTERNATIVE_5 = 5; 36 | 37 | public static final int ALTERNATIVE_6 = 6; 38 | 39 | public static final int ALTERNATIVE_7 = 7; 40 | 41 | public static final int ALTERNATIVE_8 = 8; 42 | 43 | public static final int ALTERNATIVE_9 = 9; 44 | 45 | private FontIndex() { 46 | //empty 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/ItalicSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | class ItalicSample extends AbstractAttributeSample { 27 | 28 | ItalicSample(Boolean defaultValue, Boolean currentValue, boolean supportedInWebView, 29 | boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 30 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 31 | } 32 | 33 | @Override 34 | public Attribute resolveAttribute(TextAttributeGroup group) { 35 | return group.getItalicAttribute(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/utils/TextUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.utils; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public final class TextUtils { 24 | 25 | public static String hideEsc(String text) { 26 | return text.replace("ESC[", "\u001b["); 27 | } 28 | 29 | public static String showEsc(String text) { 30 | return text.replace("\u001b[", "ESC["); 31 | } 32 | 33 | public static boolean isEscHidden(String text) { 34 | return text.contains("\u001b["); 35 | } 36 | 37 | public static String suppotedIcon(boolean supported) { 38 | if (supported) { 39 | return "\u2713"; 40 | } else { 41 | return "\u2717"; 42 | } 43 | } 44 | 45 | private TextUtils() { 46 | //empty 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ansi4j-css-impl/src/main/java/com/techsenger/ansi4j/css/impl/FunctionEvaluator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.impl; 18 | 19 | import com.techsenger.ansi4j.core.api.FunctionFragment; 20 | import com.techsenger.ansi4j.core.api.function.Function; 21 | import com.techsenger.ansi4j.css.api.ProcessorResult; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | public interface FunctionEvaluator { 28 | 29 | /** 30 | * Resolves attributes on the base of function and modifies context. 31 | * 32 | * @param functionFragment 33 | * @return changes or empty list. 34 | */ 35 | void evaluate(FunctionFragment functionFragment, ProcessorResult processorResult); 36 | 37 | /** 38 | * Returns function that this attribute resolver supports. 39 | * 40 | * @return 41 | */ 42 | Function getFunction(); 43 | } 44 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/VisibilitySample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | class VisibilitySample extends AbstractAttributeSample { 27 | 28 | VisibilitySample(Boolean defaultValue, Boolean currentValue, boolean supportedInWebView, 29 | boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 30 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 31 | } 32 | 33 | @Override 34 | public Attribute resolveAttribute(TextAttributeGroup group) { 35 | return group.getVisibilityAttribute(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/StreamParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import java.io.Closeable; 20 | import javax.annotation.concurrent.NotThreadSafe; 21 | 22 | /** 23 | * Stream parser is created for one input stream. After using parser must be closed. 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | @NotThreadSafe 28 | public interface StreamParser extends Parser, Closeable { 29 | 30 | /** 31 | * {@inheritDoc} 32 | * 33 | * This method will return null when input stream returns -1 and there is no more buffered data. However, 34 | * if input stream will provide data again the same instance of StreamParser can be used. Also 35 | * see https://stackoverflow.com/questions/611760/java-inputstream-blocking-read 36 | * 37 | * @return 38 | */ 39 | @Override 40 | Fragment parse(); 41 | } 42 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/StrikethroughSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | class StrikethroughSample extends AbstractAttributeSample { 27 | 28 | StrikethroughSample(Boolean defaultValue, Boolean currentValue, boolean supportedInWebView, 29 | boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 30 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 31 | } 32 | 33 | @Override 34 | public Attribute resolveAttribute(TextAttributeGroup group) { 35 | return group.getStrikethroughAttribute(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/ReverseVideoSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | class ReverseVideoSample extends AbstractAttributeSample { 27 | 28 | ReverseVideoSample(Boolean defaultValue, Boolean currentValue, boolean supportedInWebView, 29 | boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 30 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 31 | } 32 | 33 | @Override 34 | public Attribute resolveAttribute(TextAttributeGroup group) { 35 | return group.getReverseVideoAttribute(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/TextHandlerResultImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import java.util.Optional; 20 | import com.techsenger.ansi4j.core.api.FunctionFailureReason; 21 | import com.techsenger.ansi4j.core.api.TextFragment; 22 | import com.techsenger.ansi4j.core.api.TextHandlerResult; 23 | 24 | /** 25 | * 26 | * @author Pavel Castornii 27 | */ 28 | public class TextHandlerResultImpl extends AbstractFragmentHandlerResult implements TextHandlerResult { 29 | 30 | private final Optional fragment; 31 | 32 | public TextHandlerResultImpl(Optional fragment, FunctionFailureReason failureReason) { 33 | super(failureReason); 34 | this.fragment = fragment; 35 | } 36 | 37 | @Override 38 | public Optional getFragment() { 39 | return this.fragment; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/Fragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.Immutable; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | @Immutable 26 | public interface Fragment { 27 | 28 | /** 29 | * Returns type of this fragment. 30 | * 31 | * @return 32 | */ 33 | FragmentType getType(); 34 | 35 | /** 36 | * Text on which base this fragment was created (this is a piece of the whole text). 37 | * 38 | * @return 39 | */ 40 | String getText(); 41 | 42 | /** 43 | * Start index of the fragment text in the whole text, inclusive. 44 | * 45 | * @return 46 | */ 47 | int getStartIndex(); 48 | 49 | /** 50 | * End index of the fragment text in the whole text, exclusive. 51 | * 52 | * @return 53 | */ 54 | int getEndIndex(); 55 | } 56 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/material/StatusBar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.material; 18 | 19 | import com.techsenger.ansi4j.css.demo.Constants; 20 | import javafx.geometry.Insets; 21 | import javafx.geometry.Pos; 22 | import javafx.scene.control.ProgressBar; 23 | import javafx.scene.layout.HBox; 24 | 25 | /** 26 | * 27 | * @author Pavel Castornii 28 | */ 29 | public class StatusBar extends HBox { 30 | 31 | private final ProgressBar progressBar = new ProgressBar(); 32 | 33 | public StatusBar() { 34 | getStyleClass().add("status-bar"); 35 | getChildren().add(progressBar); 36 | progressBar.setPadding(new Insets(0, Constants.INSET, 0, Constants.INSET)); 37 | progressBar.setVisible(false); 38 | setAlignment(Pos.CENTER_RIGHT); 39 | } 40 | 41 | public ProgressBar getProgressBar() { 42 | return progressBar; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/FunctionHandlerResultImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import java.util.Optional; 20 | import com.techsenger.ansi4j.core.api.FunctionFailureReason; 21 | import com.techsenger.ansi4j.core.api.FunctionFragment; 22 | import com.techsenger.ansi4j.core.api.FunctionHandlerResult; 23 | 24 | /** 25 | * 26 | * @author Pavel Castornii 27 | */ 28 | public class FunctionHandlerResultImpl extends AbstractFragmentHandlerResult implements FunctionHandlerResult { 29 | 30 | private final Optional fragment; 31 | 32 | public FunctionHandlerResultImpl(Optional fragment, FunctionFailureReason failureReason) { 33 | super(failureReason); 34 | this.fragment = fragment; 35 | } 36 | 37 | @Override 38 | public Optional getFragment() { 39 | return this.fragment; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/BlinkingSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | class BlinkingSample extends AbstractAttributeSample { 27 | 28 | BlinkingSample(TextAttributeGroup.Blinking defaultValue, TextAttributeGroup.Blinking currentValue, 29 | boolean supportedInWebView, boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 30 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 31 | } 32 | 33 | @Override 34 | public Attribute resolveAttribute(TextAttributeGroup group) { 35 | return group.getBlinkingAttribute(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/IntensitySample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | class IntensitySample extends AbstractAttributeSample { 27 | 28 | IntensitySample(TextAttributeGroup.Intensity defaultValue, TextAttributeGroup.Intensity currentValue, 29 | boolean supportedInWebView, boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 30 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 31 | } 32 | 33 | @Override 34 | public Attribute resolveAttribute(TextAttributeGroup group) { 35 | return group.getIntensityAttribute(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/UnderlineSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | class UnderlineSample extends AbstractAttributeSample { 27 | 28 | UnderlineSample(TextAttributeGroup.Underline defaultValue, TextAttributeGroup.Underline currentValue, 29 | boolean supportedInWebView, boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 30 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 31 | } 32 | 33 | @Override 34 | public Attribute resolveAttribute(TextAttributeGroup group) { 35 | return group.getUnderlineAttribute(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/TextHandlerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import java.util.Optional; 20 | import com.techsenger.ansi4j.core.api.Environment; 21 | import com.techsenger.ansi4j.core.api.TextHandler; 22 | import com.techsenger.ansi4j.core.api.TextHandlerResult; 23 | 24 | /** 25 | * Default implementation doesn't do any modifications with text and simply returns fragment with input text. 26 | * 27 | * @author Pavel Castornii 28 | */ 29 | public class TextHandlerImpl implements TextHandler { 30 | 31 | private Environment environment; 32 | 33 | @Override 34 | public TextHandlerResult handle(String text, int currentIndex) { 35 | return new TextHandlerResultImpl(Optional.of(new TextFragmentImpl(text, currentIndex)), null); 36 | } 37 | 38 | @Override 39 | public void initialize(Environment environment) { 40 | this.environment = environment; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/FontSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | class FontSample extends AbstractAttributeSample { 27 | 28 | FontSample(String defaultValue, String currentValue, boolean supportedInWebView, 29 | boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 30 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 31 | } 32 | 33 | @Override 34 | public Attribute resolveAttribute(TextAttributeGroup group) { 35 | return group.getFontAttribute(); 36 | } 37 | 38 | @Override 39 | public String toString(String value) { 40 | return value.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/function/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.function; 18 | 19 | import java.util.List; 20 | import javax.annotation.concurrent.Immutable; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @Immutable 27 | public interface Function { 28 | 29 | /** 30 | * Returns pattern. Definitions: 31 | * 32 | *

    33 | *
  • {s} - single numeric parameter, 34 | *
  • {m} - any number of numeric parameters. 35 | *
  • {c} - a single character, 36 | *
  • {t} - text. 37 | *

38 | * 39 | * @return 40 | */ 41 | String getPattern(); 42 | 43 | /** 44 | * Returns function type. 45 | * 46 | * @return 47 | */ 48 | FunctionType getType(); 49 | 50 | /** 51 | * Returns default values of the function. 52 | * 53 | * @return values or null. 54 | */ 55 | List getDefaultValues(); 56 | } 57 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/function/FunctionArgumentImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl.function; 18 | 19 | import com.techsenger.ansi4j.core.api.function.FunctionArgument; 20 | 21 | /** 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | public class FunctionArgumentImpl implements FunctionArgument { 26 | 27 | private final Object value; 28 | 29 | private final boolean isDefault; 30 | 31 | public FunctionArgumentImpl(Object value, boolean isDefault) { 32 | this.value = value; 33 | this.isDefault = isDefault; 34 | } 35 | 36 | @Override 37 | public Object getValue() { 38 | return this.value; 39 | } 40 | 41 | @Override 42 | public boolean isDefault() { 43 | return this.isDefault; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return "FunctionArgumentImpl{" + "value=" + value + ", isDefault=" + isDefault + '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.ansi4j.css.demo { 18 | requires com.techsenger.ansi4j.core.api; 19 | requires com.techsenger.ansi4j.core.impl; 20 | requires com.techsenger.ansi4j.css.api; 21 | requires com.techsenger.ansi4j.css.impl; 22 | requires org.slf4j; 23 | requires org.apache.logging.log4j; 24 | requires org.apache.logging.log4j.core; 25 | requires org.apache.logging.log4j.slf4j2.impl; 26 | requires javafx.base; 27 | requires javafx.controls; 28 | requires javafx.graphics; 29 | requires javafx.web; 30 | requires org.fxmisc.richtext; 31 | requires org.fxmisc.flowless; 32 | requires jdk.jsobject; 33 | requires atlantafx.base; 34 | requires org.kordamp.ikonli.javafx; 35 | requires org.kordamp.ikonli.materialdesign2; 36 | requires com.google.common; 37 | 38 | exports com.techsenger.ansi4j.css.demo; 39 | opens com.techsenger.ansi4j.css.demo.text to javafx.web; 40 | } 41 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/iso6429/AbstractFunctionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl.iso6429; 18 | 19 | import com.techsenger.ansi4j.core.api.Environment; 20 | import com.techsenger.ansi4j.core.api.FunctionHandler; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | public abstract class AbstractFunctionHandler implements FunctionHandler { 27 | 28 | private Environment environment; 29 | 30 | /** 31 | * Functions checks if whole function is present in text. 32 | * @param text 33 | * @param endIndex 34 | * @return 35 | */ 36 | protected boolean isEndOfFunctionPresent(String text, int endIndex) { 37 | return !(endIndex > text.length()); 38 | } 39 | 40 | @Override 41 | public void initialize(Environment environment) { 42 | this.environment = environment; 43 | } 44 | 45 | protected Environment getEnvironment() { 46 | return environment; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/BgColorSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.color.ColorUtils; 21 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | class BgColorSample extends AbstractAttributeSample { 28 | 29 | BgColorSample(Integer defaultValue, Integer currentValue, boolean supportedInWebView, 30 | boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 31 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 32 | } 33 | 34 | @Override 35 | public Attribute resolveAttribute(TextAttributeGroup group) { 36 | return group.getBgColorAttribute(); 37 | } 38 | 39 | @Override 40 | public String toString(Integer value) { 41 | return ColorUtils.toHex(value); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/FgColorSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.color.ColorUtils; 21 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | class FgColorSample extends AbstractAttributeSample { 28 | 29 | FgColorSample(Integer defaultValue, Integer currentValue, 30 | boolean supportedInWebView, boolean supportedInTextFlow, boolean supportedInRtfxTextArea) { 31 | super(defaultValue, currentValue, supportedInWebView, supportedInTextFlow, supportedInRtfxTextArea); 32 | } 33 | 34 | @Override 35 | public Attribute resolveAttribute(TextAttributeGroup group) { 36 | return group.getFgColorAttribute(); 37 | } 38 | 39 | @Override 40 | public String toString(Integer value) { 41 | return ColorUtils.toHex(value); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/GroupStyleGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.AttributeGroup; 20 | import java.util.List; 21 | import javax.annotation.concurrent.NotThreadSafe; 22 | 23 | /** 24 | * CSS generator generates CSS declarations on the base of attribute values. 25 | * 26 | * @author Pavel Castornii 27 | */ 28 | @NotThreadSafe 29 | public interface GroupStyleGenerator> { 30 | 31 | /** 32 | * Returns the key of the attribute group this generator creates declarations for. 33 | * 34 | * @return 35 | */ 36 | AttributeGroup.Key getGroupKey(); 37 | 38 | /** 39 | * Initializes the generator. This method is called only once after registry is created. 40 | * @param group 41 | */ 42 | void initialize(T group); 43 | 44 | /** 45 | * Generates collections of CSS declarations. 46 | * 47 | * @return declarations or empty list. 48 | */ 49 | List generate(); 50 | } 51 | -------------------------------------------------------------------------------- /ansi4j-css-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techsenger.ansi4j 6 | ansi4j 7 | 2.1.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.ansi4j 11 | ansi4j-css-impl 12 | jar 13 | ANSI4J - CSS IMPL 14 | Implementation of text styling with CSS 15 | 16 | 17 | 18 | com.techsenger.ansi4j 19 | ansi4j-core-api 20 | 21 | 22 | com.techsenger.ansi4j 23 | ansi4j-css-api 24 | 25 | 26 | org.slf4j 27 | slf4j-api 28 | 29 | 30 | org.junit.jupiter 31 | junit-jupiter-api 32 | 33 | 34 | org.junit.jupiter 35 | junit-jupiter-params 36 | 37 | 38 | org.assertj 39 | assertj-core 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/ColorUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public final class ColorUtils { 24 | 25 | /** 26 | * Returns #RRGGBBAA string. 27 | * 28 | * @param rgba 29 | * @return 30 | */ 31 | public static String toHex(int rgba) { 32 | String hex = Integer.toUnsignedString(rgba, 16); 33 | hex = "#" + "0".repeat(8 - hex.length()) + hex; 34 | return hex; 35 | } 36 | 37 | public static int getRgba(int rgb, int alpha) { 38 | alpha = Math.max(0, Math.min(255, alpha)); 39 | return (rgb << 8) | (alpha & 0xFF); 40 | } 41 | 42 | public static int getRgb(int rgba) { 43 | var rgb = (rgba >>> 8); 44 | return rgb; 45 | } 46 | 47 | public static int setAlpha(int rgba, int alpha) { 48 | alpha = Math.max(0, Math.min(255, alpha)); 49 | rgba = (rgba & 0xFFFFFF00) | (alpha & 0xFF); 50 | return rgba; 51 | } 52 | 53 | private ColorUtils() { 54 | //empty 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ansi4j-css-impl/src/main/java/com/techsenger/ansi4j/css/impl/ProcessorResultImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.impl; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.AttributeChange; 20 | import com.techsenger.ansi4j.css.api.ProcessorResult; 21 | import java.util.ArrayList; 22 | import java.util.Collections; 23 | import java.util.List; 24 | 25 | /** 26 | * 27 | * @author Pavel Castornii 28 | */ 29 | public class ProcessorResultImpl implements ProcessorResult { 30 | 31 | private List> attributeChanges = new ArrayList<>(); 32 | 33 | private List styleDeclarations = new ArrayList<>(); 34 | 35 | @Override 36 | public List> getAttributeChanges() { 37 | return attributeChanges; 38 | } 39 | 40 | @Override 41 | public List getStyleDeclarations() { 42 | return this.styleDeclarations; 43 | } 44 | 45 | void makeListsUnmodifiable() { 46 | this.attributeChanges = Collections.unmodifiableList(attributeChanges); 47 | this.styleDeclarations = Collections.unmodifiableList(styleDeclarations); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FunctionFinderResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.Immutable; 20 | import com.techsenger.ansi4j.core.api.function.FunctionType; 21 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunction; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | @Immutable 28 | public interface FunctionFinderResult { 29 | 30 | /** 31 | * Returns position of function in text. 32 | * 33 | * @return 34 | */ 35 | int getFunctionIndex(); 36 | 37 | /** 38 | * Returns found function type. We don't take type from firstFunction because first function can hold C1 function 39 | * but type can be ControlString. 40 | * 41 | * @return 42 | */ 43 | FunctionType getFunctionType(); 44 | 45 | /** 46 | * For C0 returns C0 function, for C1 return C1 function, for sequence returns CSI, for independent returns 47 | * independent function, for control strings returns opening delimiter. 48 | * 49 | * @return 50 | */ 51 | ControlFunction getFunction(); 52 | } 53 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/DemoComponentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo; 18 | 19 | import com.techsenger.ansi4j.css.demo.attribute.AttributeTabView; 20 | import com.techsenger.ansi4j.css.demo.attribute.AttributeTabViewModel; 21 | import com.techsenger.ansi4j.css.demo.mvvm.ComponentService; 22 | import com.techsenger.ansi4j.css.demo.text.TextTabView; 23 | import com.techsenger.ansi4j.css.demo.text.TextTabViewModel; 24 | 25 | /** 26 | * 27 | * @author Pavel Castornii 28 | */ 29 | public class DemoComponentService implements ComponentService { 30 | 31 | private final DemoView view; 32 | 33 | public DemoComponentService(DemoView view) { 34 | this.view = view; 35 | } 36 | 37 | public void openTextTab(TextTabViewModel textViewModel) { 38 | var textView = new TextTabView(textViewModel); 39 | this.view.addTab(textView.getNode()); 40 | } 41 | 42 | public void openAttributeTab(AttributeTabViewModel attributeViewModel) { 43 | var attributeView = new AttributeTabView(attributeViewModel); 44 | this.view.addTab(attributeView.getNode()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/utils/Characters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.utils; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public final class Characters { 24 | 25 | /** 26 | * Escape. 27 | */ 28 | public static final char ESC = '\u001b'; 29 | 30 | /** 31 | * Left square bracket. 32 | */ 33 | public static final char LEFT_SB = '['; 34 | 35 | /** 36 | * Replaces invisible characters with unicodes in a string. 37 | * 38 | * @param input 39 | * @return 40 | */ 41 | public static String invisibleToUnicode(String input) { 42 | StringBuilder result = new StringBuilder(); 43 | for (char ch : input.toCharArray()) { 44 | if (Character.isISOControl(ch) || (ch >= 0x200B && ch <= 0x200D) || (ch >= 0x202A && ch <= 0x202E)) { 45 | result.append(String.format("\\u%04x", (int) ch)); 46 | } else { 47 | result.append(ch); 48 | } 49 | } 50 | return result.toString(); 51 | } 52 | 53 | private Characters() { 54 | //empty 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/StringParserImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import com.techsenger.ansi4j.core.api.FailureReason; 22 | import com.techsenger.ansi4j.core.api.Fragment; 23 | import com.techsenger.ansi4j.core.api.ParserFactory; 24 | import com.techsenger.ansi4j.core.api.StringParser; 25 | 26 | /** 27 | * 28 | * @author Pavel Castornii 29 | */ 30 | public class StringParserImpl extends AbstractParser implements StringParser { 31 | 32 | private static final Logger logger = LoggerFactory.getLogger(StringParserImpl.class); 33 | 34 | public StringParserImpl(String text, ParserFactory factory) { 35 | super(text, factory); 36 | } 37 | 38 | @Override 39 | public Fragment parse() { 40 | try { 41 | return this.doParse(); 42 | } catch (Exception ex) { 43 | logger.error("Error parsing text", ex); 44 | return null; 45 | } 46 | } 47 | 48 | @Override 49 | protected boolean delayFunctionParsing(FailureReason reason) { 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/resources/com/techsenger/ansi4j/css/demo/demo.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | .root { 18 | -fx-font-size: 13px; 19 | } 20 | 21 | .table-view { 22 | -fx-fixed-cell-size:27px; 23 | } 24 | 25 | .modal-pane { 26 | -color-modal-pane-overlay: rgba(255, 255, 255, 0); 27 | -fx-padding: 0 0 100 0; 28 | } 29 | 30 | .ikonli-font-icon { 31 | -fx-icon-size: 18px; 32 | } 33 | 34 | .menu-item { 35 | -fx-padding: 7 8 7 8; 36 | } 37 | 38 | .tool-bar .button { 39 | -fx-padding: 5 10 5 10; 40 | } 41 | 42 | .tool-bar .button .ikonli-font-icon { 43 | -fx-icon-size: 22px; 44 | } 45 | 46 | .status-bar { 47 | -fx-border-color: -color-border-default; 48 | -fx-border-width: 1 0 0 0; 49 | -fx-min-height: 2em; 50 | -fx-background-color: -color-bg-overlay; 51 | } 52 | 53 | .modal-dialog { 54 | -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 1), 25, 0, 0, 0); 55 | } 56 | 57 | .modal-dialog .main { 58 | -fx-border-color: -color-border-default; 59 | -fx-border-width: 1; 60 | } 61 | 62 | .modal-dialog .title { 63 | -fx-padding: 12 10 12 10; 64 | -fx-background-color: -color-bg-subtle; 65 | -fx-font-weight: bold; 66 | } 67 | 68 | .modal-dialog .content { 69 | -fx-padding: 10; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/FunctionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api; 18 | 19 | import javax.annotation.concurrent.ThreadSafe; 20 | import com.techsenger.ansi4j.core.api.function.FunctionType; 21 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunction; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | @ThreadSafe 28 | public interface FunctionHandler extends FragmentHandler { 29 | 30 | /** 31 | * The type of the function this parser works with. 32 | * 33 | * @return 34 | */ 35 | FunctionType getFunctionType(); 36 | 37 | /** 38 | * Parses function text. 39 | * 40 | * @param text is a piece of the whole text and starts with the function (first character is the beginning of the 41 | * function) 42 | * @param function function that must be parsed 43 | * @param currentIndex index in the whole text (is equal to parsed text length). This parameter is required for 44 | * calculating start and end index as they are relative to the whole text. 45 | * 46 | * @return fragment parser result 47 | */ 48 | FunctionHandlerResult handle(String text, ControlFunction function, int currentIndex); 49 | } 50 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/attribute/AttributeChange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.attribute; 18 | 19 | import javax.annotation.concurrent.Immutable; 20 | 21 | /** 22 | * Change in value of some attribute. 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | @Immutable 27 | public final class AttributeChange { 28 | 29 | private final Attribute key; 30 | 31 | private final T oldValue; 32 | 33 | private final T newValue; 34 | 35 | public AttributeChange(Attribute attribute, T oldValue, T newValue) { 36 | this.key = attribute; 37 | this.oldValue = oldValue; 38 | this.newValue = newValue; 39 | } 40 | 41 | /** 42 | * Returns attribute. 43 | * 44 | * @return 45 | */ 46 | public Attribute getAttribute() { 47 | return key; 48 | } 49 | 50 | /** 51 | * Returns the old value of the attribute. It can be either default and non default. 52 | * 53 | * @return 54 | */ 55 | public T getOldValue() { 56 | return this.oldValue; 57 | } 58 | 59 | /** 60 | * Returns the new value of the attribute. It can be either default and non default. 61 | * @return 62 | */ 63 | public T getNewValue() { 64 | return this.newValue; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/SampleContents.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import java.util.List; 20 | import javafx.scene.text.Text; 21 | import javafx.util.Pair; 22 | import org.fxmisc.richtext.model.StyleSpans; 23 | 24 | /** 25 | * 26 | * @author Pavel Castornii 27 | */ 28 | class SampleContents { 29 | 30 | private final SampleContent webViewContent; 31 | 32 | private final SampleContent> textFlowContent; 33 | 34 | private final SampleContent>> rtfxTextAreaContent; 35 | 36 | SampleContents(SampleContent webViewContent, SampleContent> textFlowContent, 37 | SampleContent>> rtfxTextAreaContent) { 38 | this.webViewContent = webViewContent; 39 | this.textFlowContent = textFlowContent; 40 | this.rtfxTextAreaContent = rtfxTextAreaContent; 41 | } 42 | 43 | public SampleContent getWebViewContent() { 44 | return webViewContent; 45 | } 46 | 47 | public SampleContent> getTextFlowContent() { 48 | return textFlowContent; 49 | } 50 | 51 | public SampleContent>> getRtfxTextAreaContent() { 52 | return rtfxTextAreaContent; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ansi4j-core-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techsenger.ansi4j 6 | ansi4j 7 | 2.1.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.ansi4j 11 | ansi4j-core-impl 12 | jar 13 | ANSI4J - Core IMPL 14 | Implementation of text parsing 15 | 16 | 17 | 18 | com.techsenger.ansi4j 19 | ansi4j-core-api 20 | 21 | 22 | org.slf4j 23 | slf4j-api 24 | 25 | 26 | org.junit.jupiter 27 | junit-jupiter-api 28 | 29 | 30 | org.assertj 31 | assertj-core 32 | 33 | 34 | org.apache.logging.log4j 35 | log4j-slf4j2-impl 36 | test 37 | 38 | 39 | org.apache.logging.log4j 40 | log4j-core 41 | test 42 | 43 | 44 | org.apache.logging.log4j 45 | log4j-api 46 | test 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/FunctionDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | import com.techsenger.ansi4j.core.api.function.Function; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | public class FunctionDescriptor { 28 | 29 | private final Function function; 30 | 31 | private final List parameters; 32 | 33 | private final List codes; 34 | 35 | /** 36 | * 37 | * @param function 38 | * @param parameters modifiable collection of parameters. 39 | * @param codes modifiable collection codes. 40 | */ 41 | public FunctionDescriptor(Function function, List parameters, List codes) { 42 | this.function = function; 43 | if (parameters != null) { 44 | this.parameters = Collections.unmodifiableList(parameters); 45 | } else { 46 | this.parameters = null; 47 | } 48 | this.codes = Collections.unmodifiableList(codes); 49 | } 50 | 51 | public Function getFunction() { 52 | return this.function; 53 | } 54 | 55 | public List getParameters() { 56 | return this.parameters; 57 | } 58 | 59 | public List getCodes() { 60 | return this.codes; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/spi/StyleProcessorConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.spi; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.AttributeGroupConfig; 20 | import java.util.List; 21 | import com.techsenger.ansi4j.css.api.GroupStyleGenerator; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | public class StyleProcessorConfig { 28 | 29 | private List> configs; 30 | 31 | private List> generators; 32 | 33 | public List> getConfigs() { 34 | return configs; 35 | } 36 | 37 | public void setConfigs(List> groupConfigs) { 38 | this.configs = groupConfigs; 39 | } 40 | 41 | public List> getGenerators() { 42 | return generators; 43 | } 44 | 45 | public void setGenerators(List> generators) { 46 | this.generators = generators; 47 | } 48 | 49 | public void validate() { 50 | if (this.configs == null || this.configs.isEmpty()) { 51 | throw new IllegalStateException("No attribute group configs provided"); 52 | } 53 | if (this.generators == null || this.generators.isEmpty()) { 54 | throw new IllegalStateException("No style generators provided"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/FunctionFinderResultImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import com.techsenger.ansi4j.core.api.function.FunctionType; 20 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunction; 21 | import com.techsenger.ansi4j.core.api.FunctionFinderResult; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | public class FunctionFinderResultImpl implements FunctionFinderResult { 28 | 29 | private final int functionIndex; 30 | 31 | private final FunctionType functionType; 32 | 33 | private final ControlFunction function; 34 | 35 | public FunctionFinderResultImpl(int functionIndex, FunctionType functionType, ControlFunction function) { 36 | this.functionIndex = functionIndex; 37 | this.functionType = functionType; 38 | this.function = function; 39 | } 40 | 41 | @Override 42 | public int getFunctionIndex() { 43 | return this.functionIndex; 44 | } 45 | 46 | @Override 47 | public FunctionType getFunctionType() { 48 | return this.functionType; 49 | } 50 | 51 | @Override 52 | public ControlFunction getFunction() { 53 | return function; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "FunctionFinderResultImpl{" + "functionIndex=" + functionIndex + ", functionType=" + functionType 59 | + ", function=" + function + '}'; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/text/TextAttributeGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.text; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.attribute.AttributeGroup; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | public interface TextAttributeGroup extends AttributeGroup { 27 | 28 | enum Intensity { 29 | NORMAL, INCREASED, DECREASED 30 | } 31 | 32 | enum Underline { 33 | OFF, SINGLE, DOUBLE 34 | } 35 | 36 | enum Blinking { 37 | OFF, SLOW, RAPID 38 | } 39 | 40 | AttributeGroup.Key KEY = new Key<>(); 41 | 42 | TextAttributeGroupConfig getConfig(); 43 | 44 | Attribute getFontAttribute(); 45 | 46 | /** 47 | * Color as RRGGBBAA. 48 | * @return 49 | */ 50 | Attribute getFgColorAttribute(); 51 | 52 | /** 53 | * Color as RRGGBBAA. 54 | * @return 55 | */ 56 | Attribute getBgColorAttribute(); 57 | 58 | Attribute getItalicAttribute(); 59 | 60 | Attribute getStrikethroughAttribute(); 61 | 62 | Attribute getUnderlineAttribute(); 63 | 64 | Attribute getIntensityAttribute(); 65 | 66 | Attribute getVisibilityAttribute(); 67 | 68 | Attribute getReverseVideoAttribute(); 69 | 70 | Attribute getBlinkingAttribute(); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/DemoViewModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo; 18 | 19 | import com.techsenger.ansi4j.css.demo.attribute.AttributeTabViewModel; 20 | import com.techsenger.ansi4j.css.demo.mvvm.ComponentService; 21 | import com.techsenger.ansi4j.css.demo.mvvm.ViewModel; 22 | import com.techsenger.ansi4j.css.demo.text.TextTabViewModel; 23 | import javafx.application.Platform; 24 | import javafx.beans.property.SimpleStringProperty; 25 | import javafx.beans.property.StringProperty; 26 | 27 | /** 28 | * 29 | * @author Pavel Castornii 30 | */ 31 | public class DemoViewModel implements ViewModel { 32 | 33 | private final StringProperty stageTitle = new SimpleStringProperty("Techsenger ANSI4J CSS Demo"); 34 | 35 | private DemoComponentService componentService; 36 | 37 | public DemoViewModel() { 38 | 39 | } 40 | 41 | @Override 42 | public void setComponentService(ComponentService s) { 43 | this.componentService = (DemoComponentService) s; 44 | } 45 | 46 | public StringProperty stageTitleProperty() { 47 | return stageTitle; 48 | } 49 | 50 | public void openTextTab() { 51 | this.componentService.openTextTab(new TextTabViewModel()); 52 | } 53 | 54 | public void openAttributeTab() { 55 | this.componentService.openAttributeTab(new AttributeTabViewModel()); 56 | } 57 | 58 | public void exit() { 59 | Platform.exit(); 60 | } 61 | 62 | public void doOnShow() { 63 | this.openTextTab(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/Color.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public class Color { 24 | 25 | private final PaletteType paletteType; 26 | 27 | private final int index; 28 | 29 | private int rgb; 30 | 31 | public Color(PaletteType paletteType, int index) { 32 | this.paletteType = paletteType; 33 | this.index = index; 34 | this.rgb = -1; 35 | } 36 | 37 | /** 38 | * Color as RRGGBB. This is the only place where RGB is used. Everywhere RGBA is used. 39 | * 40 | * @param rgb 41 | */ 42 | public Color(int rgb) { 43 | this.rgb = rgb; 44 | this.paletteType = null; 45 | this.index = -1; 46 | } 47 | 48 | /** 49 | * Returns a palette type or null if palette is not used. 50 | * 51 | * @return 52 | */ 53 | public PaletteType getPaletteType() { 54 | return paletteType; 55 | } 56 | 57 | /** 58 | * Returns a color index in the palette or -1 if palette is not used. 59 | * 60 | * @return 61 | */ 62 | public int getIndex() { 63 | return index; 64 | } 65 | 66 | /** 67 | * Returns color as RRGGBBAA. 68 | * 69 | * @return 70 | */ 71 | public int getRgb() { 72 | return rgb; 73 | } 74 | 75 | /** 76 | * Sets rgba. 77 | * @param rgb 78 | */ 79 | public void setRgb(int rgb) { 80 | this.rgb = rgb; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/iso6429/C0ControlFunctionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl.iso6429; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Optional; 21 | import com.techsenger.ansi4j.core.api.function.FunctionType; 22 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunctionType; 23 | import com.techsenger.ansi4j.core.impl.FunctionFragmentImpl; 24 | import com.techsenger.ansi4j.core.api.FunctionFailureReason; 25 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunction; 26 | import com.techsenger.ansi4j.core.impl.FunctionHandlerResultImpl; 27 | import com.techsenger.ansi4j.core.api.FunctionHandlerResult; 28 | 29 | /** 30 | * 31 | * @author Pavel Castornii 32 | */ 33 | public class C0ControlFunctionHandler extends AbstractFunctionHandler { 34 | 35 | @Override 36 | public FunctionType getFunctionType() { 37 | return ControlFunctionType.C0_SET; 38 | } 39 | 40 | @Override 41 | public FunctionHandlerResult handle(String text, ControlFunction function, int currentIndex) { 42 | var startIndex = 0; 43 | int endIndex = startIndex + 1; 44 | if (!isEndOfFunctionPresent(text, endIndex)) { 45 | return new FunctionHandlerResultImpl(Optional.empty(), FunctionFailureReason.NO_END_OF_FUNCTION); 46 | } 47 | var functionText = text.substring(startIndex, endIndex); 48 | return new FunctionHandlerResultImpl(Optional.of( 49 | new FunctionFragmentImpl(functionText, currentIndex, function, new ArrayList<>())), null); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/content/TextFlowContentBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.content; 18 | 19 | import com.techsenger.ansi4j.css.demo.TargetControl; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import javafx.scene.text.Text; 23 | 24 | /** 25 | * 26 | * @author Pavel Castornii 27 | */ 28 | public class TextFlowContentBuilder implements ContentBuilder> { 29 | 30 | private final List texts = new ArrayList<>(); 31 | 32 | private String style; 33 | 34 | private String styleClass; 35 | 36 | @Override 37 | public TargetControl getTargetControl() { 38 | return TargetControl.TEXT_FLOW; 39 | } 40 | 41 | @Override 42 | public void startStyle(String style) { 43 | this.style = style; 44 | } 45 | 46 | @Override 47 | public void endStyle() { 48 | this.style = null; 49 | } 50 | 51 | @Override 52 | public void appendText(String text) { 53 | var t = new Text(text); 54 | if (this.style != null) { 55 | t.setStyle(this.style); 56 | } 57 | if (styleClass != null) { 58 | t.getStyleClass().add(styleClass); 59 | } 60 | texts.add(t); 61 | } 62 | 63 | @Override 64 | public void terminateLine() { 65 | texts.add(new Text("\n")); 66 | } 67 | 68 | @Override 69 | public List build() { 70 | return texts; 71 | } 72 | 73 | public void setStyleClass(String styleClass) { 74 | this.styleClass = styleClass; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/AbstractFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import com.techsenger.ansi4j.core.api.Fragment; 20 | import com.techsenger.ansi4j.core.api.FragmentType; 21 | import com.techsenger.ansi4j.core.api.utils.Characters; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | abstract class AbstractFragment implements Fragment { 28 | 29 | private final FragmentType type; 30 | 31 | private final String text; 32 | 33 | private final int startIndex; 34 | 35 | private final int endIndex; 36 | 37 | AbstractFragment(FragmentType type, String text, int currentIndex) { 38 | this.type = type; 39 | this.text = text; 40 | this.startIndex = currentIndex; 41 | this.endIndex = currentIndex + text.length(); 42 | } 43 | 44 | @Override 45 | public FragmentType getType() { 46 | return type; 47 | } 48 | 49 | @Override 50 | public int getStartIndex() { 51 | return startIndex; 52 | } 53 | 54 | @Override 55 | public int getEndIndex() { 56 | return endIndex; 57 | } 58 | 59 | @Override 60 | public String getText() { 61 | return text; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | var t = this.text; 67 | if (t != null) { 68 | t = Characters.invisibleToUnicode(t); 69 | } 70 | return "AbstractFragmentImpl{" + "type=" + type + ", text=" + t + ", startIndex=" + startIndex 71 | + ", endIndex=" + endIndex + '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ansi4j-css-impl/src/main/java/com/techsenger/ansi4j/css/impl/attribute/AttributeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.impl.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.Attribute; 20 | import com.techsenger.ansi4j.css.api.attribute.AttributeGroup; 21 | import java.util.Objects; 22 | 23 | /** 24 | * 25 | * @author Pavel Castornii 26 | */ 27 | public class AttributeImpl implements Attribute { 28 | 29 | private final String name; 30 | 31 | private final AttributeGroup group; 32 | 33 | private T value; 34 | 35 | private T defaultValue; 36 | 37 | public AttributeImpl(AttributeGroup group, String name) { 38 | this.name = name; 39 | this.group = group; 40 | } 41 | 42 | @Override 43 | public String getName() { 44 | return this.name; 45 | } 46 | 47 | @Override 48 | public T getValue() { 49 | return value; 50 | } 51 | 52 | @Override 53 | public T getDefaultValue() { 54 | return defaultValue; 55 | } 56 | 57 | @Override 58 | public boolean isValueDefault() { 59 | return Objects.equals(this.value, this.defaultValue); 60 | } 61 | 62 | @Override 63 | public AttributeGroup getGroup() { 64 | return group; 65 | } 66 | 67 | public void setValue(T value) { 68 | this.value = value; 69 | } 70 | 71 | public void setDefaultValue(T defaultValue) { 72 | this.defaultValue = defaultValue; 73 | } 74 | 75 | public void setBothValues(T value) { 76 | this.value = value; 77 | this.defaultValue = value; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/iso6429/IndependentControlFunctionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl.iso6429; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Optional; 21 | import com.techsenger.ansi4j.core.api.function.FunctionType; 22 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunctionType; 23 | import com.techsenger.ansi4j.core.impl.FunctionFragmentImpl; 24 | import com.techsenger.ansi4j.core.api.FunctionFailureReason; 25 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunction; 26 | import com.techsenger.ansi4j.core.impl.FunctionHandlerResultImpl; 27 | import com.techsenger.ansi4j.core.api.FunctionHandlerResult; 28 | 29 | /** 30 | * 31 | * @author Pavel Castornii 32 | */ 33 | public class IndependentControlFunctionHandler extends AbstractFunctionHandler { 34 | 35 | @Override 36 | public FunctionType getFunctionType() { 37 | return ControlFunctionType.INDEPENDENT_FUNCTION; 38 | } 39 | 40 | @Override 41 | public FunctionHandlerResult handle(String text, ControlFunction function, int currentIndex) { 42 | var startIndex = 0; 43 | int endIndex = startIndex + 2; 44 | if (!isEndOfFunctionPresent(text, endIndex)) { 45 | return new FunctionHandlerResultImpl(Optional.empty(), FunctionFailureReason.NO_END_OF_FUNCTION); 46 | } 47 | var functionText = text.substring(startIndex, endIndex); 48 | return new FunctionHandlerResultImpl(Optional.of( 49 | new FunctionFragmentImpl(functionText, currentIndex, function, new ArrayList<>())), null); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/content/RtfxTextAreaContentBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.content; 18 | 19 | import com.techsenger.ansi4j.css.demo.TargetControl; 20 | import javafx.util.Pair; 21 | import org.fxmisc.richtext.model.StyleSpans; 22 | import org.fxmisc.richtext.model.StyleSpansBuilder; 23 | 24 | /** 25 | * 26 | * @author Pavel Castornii 27 | */ 28 | public class RtfxTextAreaContentBuilder implements ContentBuilder>> { 29 | 30 | private final StringBuilder sb = new StringBuilder(); 31 | 32 | private final StyleSpansBuilder ssb = new StyleSpansBuilder<>(); 33 | 34 | private String style; 35 | 36 | @Override 37 | public TargetControl getTargetControl() { 38 | return TargetControl.RTFX_TEXT_AREA; 39 | } 40 | 41 | @Override 42 | public void startStyle(String style) { 43 | this.style = style; 44 | } 45 | 46 | @Override 47 | public void endStyle() { 48 | this.style = null; 49 | } 50 | 51 | @Override 52 | public void appendText(String text) { 53 | sb.append(text); 54 | if (style != null) { 55 | ssb.add(style, text.length()); 56 | } else { 57 | ssb.add("", text.length()); 58 | } 59 | } 60 | 61 | @Override 62 | public void terminateLine() { 63 | var text = "\n"; 64 | sb.append(text); 65 | ssb.add("", text.length()); 66 | } 67 | 68 | @Override 69 | public Pair> build() { 70 | return new Pair<>(sb.toString(), ssb.create()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/FunctionFragmentImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | import com.techsenger.ansi4j.core.api.FragmentType; 22 | import com.techsenger.ansi4j.core.api.FunctionFragment; 23 | import com.techsenger.ansi4j.core.api.function.Function; 24 | import com.techsenger.ansi4j.core.api.function.FunctionArgument; 25 | 26 | /** 27 | * 28 | * @author Pavel Castornii 29 | */ 30 | public class FunctionFragmentImpl extends AbstractFragment implements FunctionFragment { 31 | 32 | private final Function function; 33 | 34 | private final List arguments; 35 | 36 | /** 37 | * 38 | * @param text 39 | * @param function 40 | * @param arguments modifiable collection. 41 | */ 42 | public FunctionFragmentImpl(String text, int currentIndex, Function function, List arguments) { 43 | super(FragmentType.FUNCTION, text, currentIndex); 44 | this.function = function; 45 | if (arguments != null) { 46 | this.arguments = Collections.unmodifiableList(arguments); 47 | } else { 48 | this.arguments = null; 49 | } 50 | } 51 | 52 | @Override 53 | public Function getFunction() { 54 | return this.function; 55 | } 56 | 57 | @Override 58 | public List getArguments() { 59 | return this.arguments; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return "FunctionFragment{" + "function=" + function + ", arguments=" + arguments + '}' 65 | + "->" + super.toString(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/attribute/AttributeTabViewModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.attribute; 18 | 19 | import com.techsenger.ansi4j.css.demo.AbstractTabViewModel; 20 | import com.techsenger.ansi4j.css.demo.mvvm.ComponentService; 21 | import javafx.beans.property.ObjectProperty; 22 | import javafx.beans.property.SimpleObjectProperty; 23 | import javafx.collections.FXCollections; 24 | import javafx.collections.ObservableList; 25 | 26 | /** 27 | * 28 | * @author Pavel Castornii 29 | */ 30 | public class AttributeTabViewModel extends AbstractTabViewModel { 31 | 32 | private final AttributeSampleService sampleService = new AttributeSampleService(); 33 | 34 | private final ObservableList> samples = 35 | FXCollections.observableArrayList(sampleService.createSamples()); 36 | 37 | private final ObjectProperty> selectedSample = new SimpleObjectProperty<>(); 38 | 39 | private final ObjectProperty content = new SimpleObjectProperty<>(); 40 | 41 | public AttributeTabViewModel() { 42 | this.selectedSample.addListener((ov, oldV, newV) -> { 43 | content.set(sampleService.createContent(newV)); 44 | }); 45 | } 46 | 47 | @Override 48 | public void setComponentService(ComponentService s) { 49 | 50 | } 51 | 52 | public ObservableList> getSamples() { 53 | return samples; 54 | } 55 | 56 | public ObjectProperty> selectedSampleProperty() { 57 | return selectedSample; 58 | } 59 | 60 | public ObjectProperty contentProperty() { 61 | return content; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/main/java/com/techsenger/ansi4j/core/impl/iso6429/C1ControlFunctionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl.iso6429; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Optional; 21 | import com.techsenger.ansi4j.core.api.Environment; 22 | import com.techsenger.ansi4j.core.api.FunctionFailureReason; 23 | import com.techsenger.ansi4j.core.api.function.FunctionType; 24 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunctionType; 25 | import com.techsenger.ansi4j.core.impl.FunctionFragmentImpl; 26 | import com.techsenger.ansi4j.core.api.iso6429.ControlFunction; 27 | import com.techsenger.ansi4j.core.impl.FunctionHandlerResultImpl; 28 | import com.techsenger.ansi4j.core.api.FunctionHandlerResult; 29 | 30 | /** 31 | * 32 | * @author Pavel Castornii 33 | */ 34 | public class C1ControlFunctionHandler extends AbstractFunctionHandler { 35 | 36 | @Override 37 | public FunctionType getFunctionType() { 38 | return ControlFunctionType.C1_SET; 39 | } 40 | 41 | @Override 42 | public FunctionHandlerResult handle(String text, ControlFunction function, int currentIndex) { 43 | var startIndex = 0; 44 | int endIndex; 45 | if (this.getEnvironment() == Environment._7_BIT) { 46 | endIndex = startIndex + 2; 47 | } else { 48 | endIndex = startIndex + 1; 49 | } 50 | if (!isEndOfFunctionPresent(text, endIndex)) { 51 | return new FunctionHandlerResultImpl(Optional.empty(), FunctionFailureReason.NO_END_OF_FUNCTION); 52 | } 53 | var functionText = text.substring(startIndex, endIndex); 54 | return new FunctionHandlerResultImpl(Optional.of( 55 | new FunctionFragmentImpl(functionText, currentIndex, function, new ArrayList<>())), null); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ansi4j-core-it/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techsenger.ansi4j 6 | ansi4j 7 | 2.1.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.ansi4j 11 | ansi4j-core-it 12 | jar 13 | ANSI4J - Core IT 14 | Integration tests for text parsing 15 | 16 | 17 | true 18 | 19 | 20 | 21 | 22 | com.techsenger.ansi4j 23 | ansi4j-core-api 24 | 25 | 26 | com.techsenger.ansi4j 27 | ansi4j-core-impl 28 | 29 | 30 | org.slf4j 31 | slf4j-api 32 | 33 | 34 | org.apache.logging.log4j 35 | log4j-slf4j2-impl 36 | test 37 | 38 | 39 | org.apache.logging.log4j 40 | log4j-core 41 | test 42 | 43 | 44 | org.apache.logging.log4j 45 | log4j-api 46 | test 47 | 48 | 49 | org.junit.jupiter 50 | junit-jupiter-api 51 | 52 | 53 | org.junit.jupiter 54 | junit-jupiter-params 55 | 56 | 57 | org.assertj 58 | assertj-core 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/text/CommandViewModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.text; 18 | 19 | import com.techsenger.ansi4j.css.demo.mvvm.ComponentService; 20 | import com.techsenger.ansi4j.css.demo.mvvm.ViewModel; 21 | import java.util.List; 22 | import javafx.beans.property.ObjectProperty; 23 | import javafx.beans.property.SimpleObjectProperty; 24 | import javafx.beans.property.SimpleStringProperty; 25 | import javafx.beans.property.StringProperty; 26 | import javafx.collections.FXCollections; 27 | import javafx.collections.ObservableList; 28 | 29 | /** 30 | * 31 | * @author Pavel Castornii 32 | */ 33 | public class CommandViewModel implements ViewModel { 34 | 35 | public enum ButtonType { 36 | CLOSE, OK 37 | } 38 | 39 | private final ObservableList commands = FXCollections.observableArrayList(List.of( 40 | "git log --color", 41 | "source-highlight -f esc256 -i pom.xml", 42 | "mvn help:help -Dstyle.color=always", 43 | "ls -la / --color")); 44 | 45 | private final StringProperty command = new SimpleStringProperty(); 46 | 47 | private final ObjectProperty onClose = new SimpleObjectProperty<>(); 48 | 49 | private ButtonType result = ButtonType.CLOSE; 50 | 51 | @Override 52 | public void setComponentService(ComponentService s) { 53 | 54 | } 55 | 56 | public ObservableList getCommands() { 57 | return commands; 58 | } 59 | 60 | public StringProperty commandProperty() { 61 | return command; 62 | } 63 | 64 | public ObjectProperty onCloseProperty() { 65 | return onClose; 66 | } 67 | 68 | public ButtonType getResult() { 69 | return result; 70 | } 71 | 72 | public void setResult(ButtonType result) { 73 | this.result = result; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/text/CommandView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.text; 18 | 19 | import com.techsenger.ansi4j.css.demo.material.Dialog; 20 | import com.techsenger.ansi4j.css.demo.mvvm.View; 21 | import com.techsenger.ansi4j.css.demo.utils.FxUtils; 22 | import javafx.scene.control.Button; 23 | import javafx.scene.control.ComboBox; 24 | import javafx.scene.layout.VBox; 25 | 26 | /** 27 | * 28 | * @author Pavel Castornii 29 | */ 30 | public class CommandView implements View { 31 | 32 | private final CommandViewModel viewModel; 33 | 34 | private final Dialog dialog = new Dialog("Command Input", 400, 10); 35 | 36 | private final ComboBox comboBox = new ComboBox<>(); 37 | 38 | private final Button okButton = new Button("OK"); 39 | 40 | public CommandView(CommandViewModel viewModel) { 41 | this.viewModel = viewModel; 42 | this.viewModel.commandProperty().bind(this.comboBox.getEditor().textProperty()); 43 | this.comboBox.setItems(viewModel.getCommands()); 44 | this.comboBox.setEditable(true); 45 | this.comboBox.setMaxWidth(Double.MAX_VALUE); 46 | var content = new VBox(this.comboBox); 47 | this.dialog.addContent(content); 48 | this.dialog.addButton(okButton); 49 | this.dialog.setOnClose(e -> this.viewModel.onCloseProperty().get().run()); 50 | this.okButton.setDefaultButton(true); 51 | this.okButton.setOnAction(e -> { 52 | this.viewModel.setResult(CommandViewModel.ButtonType.OK); 53 | this.dialog.close(); 54 | }); 55 | FxUtils.requestFocus(comboBox.getEditor()); 56 | } 57 | 58 | @Override 59 | public CommandViewModel getViewModel() { 60 | return this.viewModel; 61 | } 62 | 63 | @Override 64 | public Dialog getNode() { 65 | return this.dialog; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /ansi4j-css-demo/src/main/java/com/techsenger/ansi4j/css/demo/material/Dialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.demo.material; 18 | 19 | import atlantafx.base.layout.ModalBox; 20 | import com.techsenger.ansi4j.css.demo.Constants; 21 | import javafx.geometry.Insets; 22 | import javafx.geometry.Pos; 23 | import javafx.scene.Node; 24 | import javafx.scene.control.Button; 25 | import javafx.scene.control.Label; 26 | import javafx.scene.layout.HBox; 27 | import javafx.scene.layout.VBox; 28 | 29 | /** 30 | * 31 | * @author Pavel Castornii 32 | */ 33 | public class Dialog extends ModalBox { 34 | 35 | private final double width; 36 | 37 | private final double height; 38 | 39 | private final VBox mainBox; 40 | 41 | private final HBox titleBox; 42 | 43 | private VBox contentBox = new VBox(); 44 | 45 | private final HBox buttonBox = new HBox(); 46 | 47 | public Dialog(String title, double width, double height) { 48 | super("#" + Constants.MODAL_PANE_ID); 49 | this.getStyleClass().add("modal-dialog"); 50 | this.width = width; 51 | this.height = height; 52 | this.setMaxWidth(width); 53 | this.setMaxHeight(height); 54 | this.titleBox = new HBox(new Label(title)); 55 | this.titleBox.getStyleClass().add("title"); 56 | this.contentBox.getStyleClass().add("content"); 57 | mainBox = new VBox(titleBox, contentBox, buttonBox); 58 | mainBox.getStyleClass().add("main"); 59 | mainBox.setPrefSize(width, height); 60 | buttonBox.setAlignment(Pos.CENTER_RIGHT); 61 | buttonBox.setPadding(new Insets(Constants.INSET)); 62 | super.addContent(mainBox); 63 | } 64 | 65 | @Override 66 | public void addContent(Node node) { 67 | this.contentBox.getChildren().add(node); 68 | } 69 | 70 | public void addButton(Button button) { 71 | buttonBox.getChildren().add(button); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /ansi4j-core-api/src/main/java/com/techsenger/ansi4j/core/api/iso6429/IndependentControlFunctionAlias.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.api.iso6429; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public interface IndependentControlFunctionAlias { 24 | 25 | /** 26 | * See {@link IndependentControlFunction#CMD}. 27 | */ 28 | IndependentControlFunction CODING_METHOD_DELIMITER = IndependentControlFunction.CMD; 29 | 30 | /** 31 | * See {@link IndependentControlFunction#DMI}. 32 | */ 33 | IndependentControlFunction DISABLE_MANUAL_INPUT = IndependentControlFunction.DMI; 34 | 35 | /** 36 | * See {@link IndependentControlFunction#EMI}. 37 | */ 38 | IndependentControlFunction ENABLE_MANUAL_INPUT = IndependentControlFunction.EMI; 39 | 40 | /** 41 | * See {@link IndependentControlFunction#INT}. 42 | */ 43 | IndependentControlFunction INTERRUPT = IndependentControlFunction.INT; 44 | 45 | /** 46 | * See {@link IndependentControlFunction#LS1R}. 47 | */ 48 | IndependentControlFunction LOCKING_SHIFT_ONE_RIGHT = IndependentControlFunction.LS1R; 49 | 50 | /** 51 | * See {@link IndependentControlFunction#LS2}. 52 | */ 53 | IndependentControlFunction LOCKING_SHIFT_TWO = IndependentControlFunction.LS2; 54 | 55 | /** 56 | * See {@link IndependentControlFunction#LS2R}. 57 | */ 58 | IndependentControlFunction LOCKING_SHIFT_TWO_RIGHT = IndependentControlFunction.LS2R; 59 | 60 | /** 61 | * See {@link IndependentControlFunction#LS3}. 62 | */ 63 | IndependentControlFunction LOCKING_SHIFT_THREE = IndependentControlFunction.LS3; 64 | 65 | /** 66 | * See {@link IndependentControlFunction#LS3R}. 67 | */ 68 | IndependentControlFunction LOCKING_SHIFT_THREE_RIGHT = IndependentControlFunction.LS3R; 69 | 70 | /** 71 | * See {@link IndependentControlFunction#RIS}. 72 | */ 73 | IndependentControlFunction RESET_TO_INITIAL_STATE = IndependentControlFunction.RIS; 74 | } 75 | -------------------------------------------------------------------------------- /ansi4j-css-api/src/main/java/com/techsenger/ansi4j/css/api/color/SgrExtraColorValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.api.color; 18 | 19 | /** 20 | * ISO 6429 DOES NOT include these parameters values. However, they are widely used in many types of terminal. 21 | * See details here https://unix.stackexchange.com/a/696593/139986 22 | * 23 | * @author Pavel Castornii 24 | */ 25 | public final class SgrExtraColorValue { 26 | 27 | public static final int BRIGHT_BLACK_DISPLAY = 90; 28 | 29 | public static final int BRIGHT_RED_DISPLAY = 91; 30 | 31 | public static final int BRIGHT_GREEN_DISPLAY = 92; 32 | 33 | public static final int BRIGHT_YELLOW_DISPLAY = 93; 34 | 35 | public static final int BRIGHT_BLUE_DISPLAY = 94; 36 | 37 | public static final int BRIGHT_MAGENTA_DISPLAY = 95; 38 | 39 | public static final int BRIGHT_CYAN_DISPLAY = 96; 40 | 41 | public static final int BRIGHT_WHITE_DISPLAY = 97; 42 | 43 | 44 | public static final int BRIGHT_BLACK_BACKGROUND = 100; 45 | 46 | public static final int BRIGHT_RED_BACKGROUND = 101; 47 | 48 | public static final int BRIGHT_GREEN_BACKGROUND = 102; 49 | 50 | public static final int BRIGHT_YELLOW_BACKGROUND = 103; 51 | 52 | public static final int BRIGHT_BLUE_BACKGROUND = 104; 53 | 54 | public static final int BRIGHT_MAGENTA_BACKGROUND = 105; 55 | 56 | public static final int BRIGHT_CYAN_BACKGROUND = 106; 57 | 58 | public static final int BRIGHT_WHITE_BACKGROUND = 107; 59 | 60 | /** 61 | * 38;x. 62 | */ 63 | public static final int DISPLAY_8_OR_24_BIT_PALETTE = 38; 64 | 65 | /** 66 | * 48;x. 67 | */ 68 | public static final int BACKGROUND_8_OR_24_BIT_PALETTE = 48; 69 | 70 | /** 71 | * 38;5;⟨n⟩m OR 48;5;⟨n⟩m. 72 | */ 73 | public static final int PALETTE_8_BIT = 5; 74 | 75 | /** 76 | * 38;2;⟨r⟩;⟨g⟩;⟨b⟩ OR 48;2;⟨r⟩;⟨g⟩;⟨b⟩. 77 | */ 78 | public static final int PALETTE_24_BIT = 2; 79 | 80 | private SgrExtraColorValue() { 81 | //empty 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /ansi4j-css-it/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techsenger.ansi4j 6 | ansi4j 7 | 2.1.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.ansi4j 11 | ansi4j-css-it 12 | jar 13 | ANSI4J - CSS IT 14 | Integration tests for text styling with CSS 15 | 16 | 17 | true 18 | 19 | 20 | 21 | 22 | com.techsenger.ansi4j 23 | ansi4j-core-api 24 | 25 | 26 | com.techsenger.ansi4j 27 | ansi4j-core-impl 28 | 29 | 30 | com.techsenger.ansi4j 31 | ansi4j-css-api 32 | 33 | 34 | com.techsenger.ansi4j 35 | ansi4j-css-impl 36 | 37 | 38 | org.slf4j 39 | slf4j-api 40 | 41 | 42 | org.junit.jupiter 43 | junit-jupiter-api 44 | 45 | 46 | org.junit.jupiter 47 | junit-jupiter-params 48 | 49 | 50 | org.apache.logging.log4j 51 | log4j-slf4j2-impl 52 | test 53 | 54 | 55 | org.apache.logging.log4j 56 | log4j-core 57 | test 58 | 59 | 60 | org.apache.logging.log4j 61 | log4j-api 62 | test 63 | 64 | 65 | org.assertj 66 | assertj-core 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/test/java/com/techsenger/ansi4j/core/impl/iso6429/ControlSequenceMatcherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl.iso6429; 18 | 19 | import java.util.Arrays; 20 | import org.junit.jupiter.api.Test; 21 | import static org.assertj.core.api.Assertions.assertThat; 22 | import org.junit.jupiter.api.BeforeAll; 23 | import com.techsenger.ansi4j.core.api.iso6429.ControlSequenceFunction; 24 | import com.techsenger.ansi4j.core.api.utils.Characters; 25 | 26 | /** 27 | * 28 | * @author Pavel Castornii 29 | */ 30 | public class ControlSequenceMatcherTest { 31 | 32 | private static ControlSequenceMatcher matcher; 33 | 34 | @BeforeAll 35 | public static void init() { 36 | matcher = new ControlSequenceMatcher(Arrays.asList(ControlSequenceFunction.values())); 37 | } 38 | 39 | @Test 40 | public void createDescriptor_oneParameter_success() { 41 | var descriptor = matcher.createDescriptor(ControlSequenceFunction.CBT); 42 | assertThat(descriptor.getFunction()).isSameAs(ControlSequenceFunction.CBT); 43 | assertThat(descriptor.getParameters()).containsExactly("{s}"); 44 | assertThat(descriptor.getCodes()).containsExactly("{s}", "Z"); 45 | } 46 | 47 | @Test 48 | public void createDescriptor_manyParameters_success() { 49 | var descriptor = matcher.createDescriptor(ControlSequenceFunction.DTA); 50 | assertThat(descriptor.getFunction()).isSameAs(ControlSequenceFunction.DTA); 51 | assertThat(descriptor.getParameters()).containsExactly("{s}", "{s}"); 52 | assertThat(descriptor.getCodes()).containsExactly("{s}", ";", "{s}", " ", "T"); 53 | } 54 | 55 | @Test 56 | public void match_oneParameter_success() { 57 | var descriptor = matcher.match(0, Characters.ESC + "[12Z"); 58 | assertThat(descriptor.getFunction()).isSameAs(ControlSequenceFunction.CBT); 59 | } 60 | 61 | @Test 62 | public void match_manyParameters_success() { 63 | var descriptor = matcher.match(3, "abc" + Characters.ESC + "[28;14 T"); 64 | assertThat(descriptor.getFunction()).isSameAs(ControlSequenceFunction.DTA); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ansi4j-core-impl/src/test/java/com/techsenger/ansi4j/core/impl/iso6429/ControlSequenceUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.core.impl.iso6429; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * 24 | * @author Pavel Castornii 25 | */ 26 | public class ControlSequenceUtilsTest { 27 | 28 | @Test 29 | public void parseArguments_string_noArg_success() { 30 | var arguments = ControlSequenceUtils.parseArguments(""); 31 | assertThat(arguments).isNull(); 32 | } 33 | 34 | @Test 35 | public void parseArguments_string_oneArgNoDefaultValues_success() { 36 | var arguments = ControlSequenceUtils.parseArguments("20"); 37 | assertThat(arguments).containsExactly("20"); 38 | } 39 | 40 | @Test 41 | public void parseArguments_string_manyArgsWithoutDefaultValues_success() { 42 | var arguments = ControlSequenceUtils.parseArguments("20;30"); 43 | assertThat(arguments).containsExactly("20", "30"); 44 | } 45 | 46 | @Test 47 | public void parseArguments_string_manyArgsWithOneDefaultValues_success() { 48 | var arguments = ControlSequenceUtils.parseArguments(";20;30"); 49 | assertThat(arguments).containsExactly(null, "20", "30"); 50 | } 51 | 52 | @Test 53 | public void parseArguments_string_manyArgsWithTwoDefaultValues_success() { 54 | var arguments = ControlSequenceUtils.parseArguments("20;;30;"); 55 | assertThat(arguments).containsExactly("20", null, "30", null); 56 | } 57 | 58 | @Test 59 | public void parseArguments_string_manyArgsWithThreeDefaultValues_success() { 60 | var arguments = ControlSequenceUtils.parseArguments(";20;foo;;30;"); 61 | assertThat(arguments).containsExactly(null, "20", "foo", null, "30", null); 62 | } 63 | 64 | @Test 65 | public void parseArguments_string_manyArgsWithFourDefaultValues_success() { 66 | var arguments = ControlSequenceUtils.parseArguments(";20;foo;;;30;"); 67 | assertThat(arguments).containsExactly(null, "20", "foo", null, null, "30", null); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /ansi4j-css-impl/src/main/java/com/techsenger/ansi4j/css/impl/attribute/AttributeRegistryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022-2024 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.ansi4j.css.impl.attribute; 18 | 19 | import com.techsenger.ansi4j.css.api.attribute.AttributeChange; 20 | import com.techsenger.ansi4j.css.api.attribute.AttributeGroup; 21 | import com.techsenger.ansi4j.css.api.attribute.AttributeGroupConfig; 22 | import com.techsenger.ansi4j.css.api.attribute.AttributeRegistry; 23 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroup; 24 | import com.techsenger.ansi4j.css.api.text.TextAttributeGroupConfig; 25 | import com.techsenger.ansi4j.css.impl.text.TextAttributeGroupImpl; 26 | import java.util.Collections; 27 | import java.util.HashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | import java.util.Set; 31 | import java.util.function.Function; 32 | import java.util.stream.Collectors; 33 | 34 | /** 35 | * 36 | * @author Pavel Castornii 37 | */ 38 | public class AttributeRegistryImpl implements AttributeRegistry { 39 | 40 | private final Map, AttributeGroup> groupsByKey = new HashMap<>(); 41 | 42 | public AttributeRegistryImpl(List> configs) { 43 | var configsByKey = configs.stream() 44 | .collect(Collectors.toMap(AttributeGroupConfig::getGroupKey, Function.identity())); 45 | 46 | var textGroup = new TextAttributeGroupImpl((TextAttributeGroupConfig) configsByKey.get(TextAttributeGroup.KEY)); 47 | groupsByKey.put(textGroup.getKey(), textGroup); 48 | } 49 | 50 | @Override 51 | public > T getGroup(AttributeGroup.Key key) { 52 | return (T) this.groupsByKey.get(key); 53 | } 54 | 55 | @Override 56 | public Set> getGroupKeys() { 57 | return Collections.unmodifiableSet(this.groupsByKey.keySet()); 58 | } 59 | 60 | /** 61 | * Updates attribute values. 62 | * 63 | * @param changes 64 | */ 65 | public void applyChanges(List> changes) { 66 | changes.forEach(c -> { 67 | var attribute = (AttributeImpl) c.getAttribute(); 68 | attribute.setValue(c.getNewValue()); 69 | }); 70 | } 71 | } 72 | --------------------------------------------------------------------------------