├── .github ├── FUNDING.yml └── workflows │ └── dotnet-core.yml ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── LICENSE ├── Program.cs ├── README.md ├── Tui.cs ├── _config.yml ├── imgs ├── drawBook.png ├── drawlist.png ├── screen-tui-netcore-draw-input.gif ├── screen-tui-netcore-draw-ok-box.gif ├── screen-tui-netcore-hello-world.gif └── screen-tui-netcore-yes-no.gif ├── nuget └── fc.tui-core.0.0.2-alpha.nupkg └── tui-netcore.csproj /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | #patreon: # Replace with a single Patreon username 5 | #open_collective: # Replace with a single Open Collective username 6 | ko_fi: fcrozetta # Replace with a single Ko-fi username 7 | #tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | #community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | #liberapay: # Replace with a single Liberapay username 10 | #issuehunt: # Replace with a single IssueHunt username 11 | #otechie: # Replace with a single Otechie username 12 | #custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-core.yml: -------------------------------------------------------------------------------- 1 | name: Build and Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Setup .NET Core 14 | uses: actions/setup-dotnet@v1 15 | with: 16 | dotnet-version: "5.0.x" 17 | - name: Install dependencies 18 | run: dotnet restore 19 | - name: Build 20 | run: dotnet pack --configuration Release 21 | - name: Build project # This would actually build your project, using zip for an example artifact 22 | run: zip --junk-paths tui-netcore bin/Release/*pkg 23 | - name: Create a Release 24 | id: create_release 25 | uses: actions/create-release@v1 26 | env: 27 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 28 | with: 29 | tag_name: ${{ github.ref }} 30 | release_name: Release ${{ github.ref }} 31 | draft: false 32 | prerelease: false 33 | - name: Upload Release Asset 34 | id: upload-release-asset 35 | uses: actions/upload-release-asset@v1 36 | env: 37 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 38 | with: 39 | upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps 40 | asset_path: ./tui-netcore.zip 41 | asset_name: tui-netcore.zip 42 | asset_content_type: application/zip 43 | - name: nuget upload 44 | env: 45 | API_KEY: ${{secrets.NUGET_API_KEY}} 46 | run: dotnet nuget push bin/Release/*.nupkg -k $API_KEY -s "https://api.nuget.org/v3/index.json" 47 | - name: Symbol nuget upload 48 | env: 49 | API_KEY: ${{secrets.NUGET_API_KEY}} 50 | run: dotnet nuget push bin/Release/*.snupkg -k $API_KEY -s "https://api.nuget.org/v3/index.json" 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | obj/ 3 | 4 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | "program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/tui-netcore.dll", 13 | "args": [], 14 | "cwd": "${workspaceFolder}", 15 | "console": "externalTerminal", 16 | "stopAtEntry": false, 17 | "internalConsoleOptions": "openOnSessionStart" 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build", 8 | "command": "dotnet build", 9 | "type": "shell", 10 | "group": "build", 11 | "presentation": { 12 | "reveal": "silent" 13 | }, 14 | "problemMatcher": "$msCompile" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using tui_netcore; 3 | using System.Collections.Generic; 4 | namespace tui_netcore 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | Console.CursorVisible = false; 11 | 12 | // The empty Constructor build a fullscreen, based on Console size at instance time 13 | Tui fullscreen = new Tui(); 14 | fullscreen.DrawYesNo(); 15 | 16 | //The construction of a box. Set Size and position 17 | Tui t = new Tui(100, 25, 10, 15) 18 | { 19 | Title = "Tui Demo", 20 | Body = "This is a demo test for Tui netcore. This is the first version, and bugs may appear" + 21 | " \n Do not be afraid. \n This Contains a sequence of screens that will show you how to create and" + 22 | " manage screens. \n You can create your own screens to play with." 23 | }; 24 | 25 | // This sets a color schema for the windows 26 | Tui.ColorSchema schema = Tui.ColorSchema.Info; 27 | // Draw ok is a screen that will continue on any key pressed 28 | t.DrawOk(schema); 29 | 30 | // text with pages 31 | t.Title = "Long screen with paging"; 32 | t.Body = "Occaecat labore est Lorem pariatur deserunt. Esse sint aliquip sit culpa sit exercitation. Quis ad pariatur officia exercitation dolore dolor ad quis. Esse incididunt in nulla ullamco deserunt sunt tempor incididunt mollit est laborum. \n Esse pariatur nostrud dolor excepteur consectetur Lorem minim minim. Commodo do ex anim aliquip. Nostrud elit aliqua nostrud sunt nostrud ipsum est elit est. Ex magna magna occaecat occaecat quis eiusmod elit anim voluptate. Pariatur sint aute proident Lorem in quis fugiat. \n Magna adipisicing occaecat pariatur et ad. Enim pariatur esse sint deserunt irure dolor Lorem anim est laboris voluptate ut voluptate ut. Aliquip sunt id ad ea sunt culpa mollit ipsum et laboris eu exercitation proident. Enim duis quis et voluptate nulla quis quis Lorem dolor labore sit excepteur aliqua aute. Fugiat elit veniam esse sit laboris aliqua commodo ad consequat incididunt eiusmod minim esse aliqua. Deserunt laboris nostrud sunt sunt veniam officia culpa duis.Occaecat labore est Lorem pariatur deserunt. Esse sint aliquip sit culpa sit exercitation. Quis ad pariatur officia exercitation dolore dolor ad quis. Esse incididunt in nulla ullamco deserunt sunt tempor incididunt mollit est laborum. \n Esse pariatur nostrud dolor excepteur consectetur Lorem minim minim. Commodo do ex anim aliquip. Nostrud elit aliqua nostrud sunt nostrud ipsum est elit est. Ex magna magna occaecat occaecat quis eiusmod elit anim voluptate. Pariatur sint aute proident Lorem in quis fugiat. \n Magna adipisicing occaecat pariatur et ad. Enim pariatur esse sint deserunt irure dolor Lorem anim est laboris voluptate ut voluptate ut. Aliquip sunt id ad ea sunt culpa mollit ipsum et laboris eu exercitation proident. Enim duis quis et voluptate nulla quis quis Lorem dolor labore sit excepteur aliqua aute. Fugiat elit veniam esse sit laboris aliqua commodo ad consequat incididunt eiusmod minim esse aliqua. Deserunt laboris nostrud sunt sunt veniam officia culpa duis.Occaecat labore est Lorem pariatur deserunt. Esse sint aliquip sit culpa sit exercitation. Quis ad pariatur officia exercitation dolore dolor ad quis. Esse incididunt in nulla ullamco deserunt sunt tempor incididunt mollit est laborum. \n Esse pariatur nostrud dolor excepteur consectetur Lorem minim minim. Commodo do ex anim aliquip. Nostrud elit aliqua nostrud sunt nostrud ipsum est elit est. Ex magna magna occaecat occaecat quis eiusmod elit anim voluptate. Pariatur sint aute proident Lorem in quis fugiat. \n Magna adipisicing occaecat pariatur et ad. Enim pariatur esse sint deserunt irure dolor Lorem anim est laboris voluptate ut voluptate ut. Aliquip sunt id ad ea sunt culpa mollit ipsum et laboris eu exercitation proident. Enim duis quis et voluptate nulla quis quis Lorem dolor labore sit excepteur aliqua aute. Fugiat elit veniam esse sit laboris aliqua commodo ad consequat incididunt eiusmod minim esse aliqua. Deserunt laboris nostrud sunt sunt veniam officia culpa duis.Occaecat labore est Lorem pariatur deserunt. Esse sint aliquip sit culpa sit exercitation. Quis ad pariatur officia exercitation dolore dolor ad quis. Esse incididunt in nulla ullamco deserunt sunt tempor incididunt mollit est laborum. \n Esse pariatur nostrud dolor excepteur consectetur Lorem minim minim. Commodo do ex anim aliquip. Nostrud elit aliqua nostrud sunt nostrud ipsum est elit est. Ex magna magna occaecat occaecat quis eiusmod elit anim voluptate. Pariatur sint aute proident Lorem in quis fugiat. \n Magna adipisicing occaecat pariatur et ad. Enim pariatur esse sint deserunt irure dolor Lorem anim est laboris voluptate ut voluptate ut. Aliquip sunt id ad ea sunt culpa mollit ipsum et laboris eu exercitation proident. Enim duis quis et voluptate nulla quis quis Lorem dolor labore sit excepteur aliqua aute. Fugiat elit veniam esse sit laboris aliqua commodo ad consequat incididunt eiusmod minim esse aliqua. Deserunt laboris nostrud sunt sunt veniam officia culpa duis.FINISH"; 33 | t.BorderStyle = Tui.BorderStyles.SingleLine; 34 | t.DrawBook(); 35 | 36 | // text with pages fulllscreen 37 | Tui tfull = new Tui(); 38 | tfull.Title = "Long screen with paging (Fullscreen)"; 39 | tfull.Body = "Occaecat labore est Lorem pariatur deserunt. Esse sint aliquip sit culpa sit exercitation. Quis ad pariatur officia exercitation dolore dolor ad quis. Esse incididunt in nulla ullamco deserunt sunt tempor incididunt mollit est laborum. \n Esse pariatur nostrud dolor excepteur consectetur Lorem minim minim. Commodo do ex anim aliquip. Nostrud elit aliqua nostrud sunt nostrud ipsum est elit est. Ex magna magna occaecat occaecat quis eiusmod elit anim voluptate. Pariatur sint aute proident Lorem in quis fugiat. \n Magna adipisicing occaecat pariatur et ad. Enim pariatur esse sint deserunt irure dolor Lorem anim est laboris voluptate ut voluptate ut. Aliquip sunt id ad ea sunt culpa mollit ipsum et laboris eu exercitation proident. Enim duis quis et voluptate nulla quis quis Lorem dolor labore sit excepteur aliqua aute. Fugiat elit veniam esse sit laboris aliqua commodo ad consequat incididunt eiusmod minim esse aliqua. Deserunt laboris nostrud sunt sunt veniam officia culpa duis.Occaecat labore est Lorem pariatur deserunt. Esse sint aliquip sit culpa sit exercitation. Quis ad pariatur officia exercitation dolore dolor ad quis. Esse incididunt in nulla ullamco deserunt sunt tempor incididunt mollit est laborum. \n Esse pariatur nostrud dolor excepteur consectetur Lorem minim minim. Commodo do ex anim aliquip. Nostrud elit aliqua nostrud sunt nostrud ipsum est elit est. Ex magna magna occaecat occaecat quis eiusmod elit anim voluptate. Pariatur sint aute proident Lorem in quis fugiat. \n Magna adipisicing occaecat pariatur et ad. Enim pariatur esse sint deserunt irure dolor Lorem anim est laboris voluptate ut voluptate ut. Aliquip sunt id ad ea sunt culpa mollit ipsum et laboris eu exercitation proident. Enim duis quis et voluptate nulla quis quis Lorem dolor labore sit excepteur aliqua aute. Fugiat elit veniam esse sit laboris aliqua commodo ad consequat incididunt eiusmod minim esse aliqua. Deserunt laboris nostrud sunt sunt veniam officia culpa duis.Occaecat labore est Lorem pariatur deserunt. Esse sint aliquip sit culpa sit exercitation. Quis ad pariatur officia exercitation dolore dolor ad quis. Esse incididunt in nulla ullamco deserunt sunt tempor incididunt mollit est laborum. \n Esse pariatur nostrud dolor excepteur consectetur Lorem minim minim. Commodo do ex anim aliquip. Nostrud elit aliqua nostrud sunt nostrud ipsum est elit est. Ex magna magna occaecat occaecat quis eiusmod elit anim voluptate. Pariatur sint aute proident Lorem in quis fugiat. \n Magna adipisicing occaecat pariatur et ad. Enim pariatur esse sint deserunt irure dolor Lorem anim est laboris voluptate ut voluptate ut. Aliquip sunt id ad ea sunt culpa mollit ipsum et laboris eu exercitation proident. Enim duis quis et voluptate nulla quis quis Lorem dolor labore sit excepteur aliqua aute. Fugiat elit veniam esse sit laboris aliqua commodo ad consequat incididunt eiusmod minim esse aliqua. Deserunt laboris nostrud sunt sunt veniam officia culpa duis.Occaecat labore est Lorem pariatur deserunt. Esse sint aliquip sit culpa sit exercitation. Quis ad pariatur officia exercitation dolore dolor ad quis. Esse incididunt in nulla ullamco deserunt sunt tempor incididunt mollit est laborum. \n Esse pariatur nostrud dolor excepteur consectetur Lorem minim minim. Commodo do ex anim aliquip. Nostrud elit aliqua nostrud sunt nostrud ipsum est elit est. Ex magna magna occaecat occaecat quis eiusmod elit anim voluptate. Pariatur sint aute proident Lorem in quis fugiat. \n Magna adipisicing occaecat pariatur et ad. Enim pariatur esse sint deserunt irure dolor Lorem anim est laboris voluptate ut voluptate ut. Aliquip sunt id ad ea sunt culpa mollit ipsum et laboris eu exercitation proident. Enim duis quis et voluptate nulla quis quis Lorem dolor labore sit excepteur aliqua aute. Fugiat elit veniam esse sit laboris aliqua commodo ad consequat incididunt eiusmod minim esse aliqua. Deserunt laboris nostrud sunt sunt veniam officia culpa duis.FINISH"; 40 | tfull.BorderStyle = Tui.BorderStyles.DoubleLine; 41 | tfull.DrawBook(); 42 | 43 | // User answer 44 | t.Title = "Screen to get user answer"; 45 | t.Body = "This screen contains a text, which is a description of what the user whould do. \n Use this to let the user type the answer." + 46 | " \n For the sake of this tutorial, type your name, and press ."; 47 | string username = t.DrawInput(schema); 48 | 49 | t.Title = "CheckBox Screen"; 50 | t.Body = "Check Box Screens allows the user to choose multiple options. A list of the chosen options will be returned." + 51 | " \n The user can select using and continue to the next screen using "; 52 | 53 | List options = t.DrawCheckBox(new List(){ 54 | new Tui.CheckBoxOption(){ 55 | IsSelected = false, 56 | Name = "option 1", 57 | Description = "Description of option 1" 58 | }, 59 | new Tui.CheckBoxOption(){ 60 | IsSelected = true, 61 | Name = "option 2", 62 | Description = "Description of option 2" 63 | }, 64 | new Tui.CheckBoxOption(){ 65 | IsSelected = false, 66 | Name = "option 3", 67 | Description = "Description of option 3" 68 | } 69 | }, schema); 70 | 71 | 72 | t.Title = "Lists"; 73 | t.Body = "Lists were created to be used as 'radio buttons' and simple menus." + 74 | " \n Use the Lists as a single choice menu. \n Press to select."; 75 | string TestList = t.DrawList(new List() { 76 | "Banana", 77 | "Apple", 78 | "Orange" 79 | }, schema); 80 | 81 | t.Title = "Confirmation Screen"; 82 | t.Body = $"This Screens let the user choose between Yes and No options.You can set one options as default." + 83 | " \n selects an option"; 84 | t.DrawYesNo(Tui.ColorSchema.Danger); 85 | 86 | t.Title = "Finish"; 87 | t.Body = "You have Completed the example program"; 88 | t.DrawOk(); 89 | 90 | 91 | t.Title = "End Program"; 92 | t.Body = "This does not require user interaction"; 93 | t.Draw(); 94 | 95 | //! Going back to default terminal settings 96 | Console.ResetColor(); 97 | Console.CursorVisible = true; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![.NET Core](https://github.com/fcrozetta/tui-netcore/workflows/.NET%20Core/badge.svg) 3 | # tui-netcore 4 | Simple Text User Interface for .net Core. 5 | This Class was implemented to make easy to implement a simple interface for the user. 6 | It's is possible to use, but bugs are still happening. 7 | 8 | > Nuget Package was released Firstly as Stable package. That was not the intention. 9 | 10 | >0.0.1 and 0.0.1-alpha are the same. 11 | 12 | # Contents 13 | - [tui-netcore](#tui-netcore) 14 | - [Contents](#contents) 15 | - [But why?](#but-why) 16 | - [Instalation](#instalation) 17 | - [Usage](#usage) 18 | - [Creating a Hello World](#creating-a-hello-world) 19 | - [Instantiating the box object](#instantiating-the-box-object) 20 | - [OK Box](#ok-box) 21 | - [Drawing a box, without waiting response from user](#drawing-a-box-without-waiting-response-from-user) 22 | - [Drawing an Input Box](#drawing-an-input-box) 23 | - [Drawing a Yes/No Box](#drawing-a-yesno-box) 24 | - [Draw a check Box](#draw-a-check-box) 25 | - [Draw a list box](#draw-a-list-box) 26 | - [Draw a Book box](#draw-a-book-box) 27 | - [Bugs](#bugs) 28 | 29 | # But why? 30 | >tl,dr; Because why not? 31 | 32 | I've used other TUI programs in python, bash and node, but personally i didn't enjoy all the parameters i had to pass to render a simple message in the screen. So, i created one class, that draws a box, and the same box can be rendered as: 33 | - Simple message box (pressing any key will continue) 34 | - User Input box (User can type the answer and press enter to confirm) 35 | - Yes/No box (User can select with Arrow keys, and enter to confirm) 36 | - Check Box (User can select multiple elements with arrow keys and spacebar, and enter to confirm) 37 | - List Box (User can choose one option in the list, and press enter to select the option) 38 | 39 | 40 | 41 | # Instalation 42 | 43 | > If you don't have dotnet core installed, you can follow the instructions on this website : https://www.microsoft.com/net/download/windows 44 | 45 | If you have your own project and want to use this interface, you just have to install the package. The easiest way to do it is: 46 | 1. open a terminal and go to your project folder 47 | 2. Execute command: 48 | `dotnet add package fc.tui-core` 49 | 3. Execute the command: 50 | `dotnet restore` 51 | 52 | > If you need other ways to install the package, you can check https://www.nuget.org/packages/fc.tui-core/ 53 | 54 | # Usage 55 | To use the class, it's possible to initialize only one time use the same windows multiple times. In this section we will initialize once and use it for every example. 56 | 57 | ## Creating a Hello World 58 | 59 | ![asciicast](imgs/screen-tui-netcore-hello-world.gif) 60 | 61 | The easiest way to start is creating a window that uses all the available space in your terminal. 62 | 63 | In your project, add the import 64 | ```csharp 65 | using tui_netcore; 66 | ``` 67 | 68 | and inside your program, create a new window: 69 | 70 | ```csharp 71 | Tui window = new Tui() 72 | window.Title = " Hello World "; 73 | window.Body = "This is a dullscreen window"; 74 | window.DrawOk(); 75 | ``` 76 | 77 | and run it with ```dotnet run``` or the method you prefer. 78 | ## Instantiating the box object 79 | 80 | ```csharp 81 | using tui_netcore; 82 | 83 | /* Inside your main */ 84 | Tui t= new Tui(); 85 | ``` 86 | 87 | If you want to use directly, you can also use the following code: 88 | ```csharp 89 | using tui_netcore; 90 | 91 | /* Inside your main */ 92 | Tui.ColorSchema schema =Tui.ColorSchema.Info; // This is used to change the color of the box 93 | Tui t = new Tui(){ 94 | Title = "Title message", 95 | Body = "Body message" 96 | }; 97 | ``` 98 | 99 | ## OK Box 100 | ![drawOk](imgs/screen-tui-netcore-draw-ok-box.gif) 101 | 102 | ```csharp 103 | t.DrawOk(); 104 | ``` 105 | Yes. It's simple like that. 106 | 107 | DrawOk() Method will accept any key to continue. 108 | 109 | 110 | 111 | ## Drawing a box, without waiting response from user 112 | ```csharp 113 | t.Draw(); 114 | ``` 115 | This will create a box, and continue the program. Use this as a part of something more complex. 116 | 117 | ## Drawing an Input Box 118 | ![drawInput](imgs/screen-tui-netcore-draw-input.gif) 119 | 120 | ```csharp 121 | string answer = t.DrawInput(); 122 | ``` 123 | 124 | The return type of the DrawInput Method will always be a string. 125 | Note that the Property AnserChar will be printed where the User have to type 126 | 127 | ## Drawing a Yes/No Box 128 | ![drawYesNo](imgs/screen-tui-netcore-yes-no.gif) 129 | 130 | ```csharp 131 | bool answer = t.DrawYesNo(); 132 | ``` 133 | 134 | The Yes/no box returns a bool, where "yes" is true. 135 | 136 | 137 | You can customise the "yes" and "no" words, like this: 138 | ```csharp 139 | bool answer = t.DrawYesNo(schema,txtYes="YAH",txtNo="NAH"); 140 | ``` 141 | You can also set the default option, adding an argument at the end of the method: 142 | ```csharp 143 | // This set the default answer to YES (true) 144 | bool answer = t.DrawYesNo(schema,txtYes="YAH",txtNo="NAH",defaultAnswer=true); 145 | ``` 146 | ## Draw a check Box 147 | [![asciicast](https://asciinema.org/a/CXProc6Etf4UuPR6s7aQKnutp.svg)](https://asciinema.org/a/CXProc6Etf4UuPR6s7aQKnutp) 148 | This type of box will allow the user to select multiple options with spacebar, and continue with Enter 149 | The signature of the method is: 150 | ```csharp 151 | public List DrawCheckBox(List options, ColorSchema schema = ColorSchema.Regular, bool onlyChecked = true) 152 | ``` 153 | The first parameter is a list of checkboxOption objects, followed by a ColoSchema, and a boolean as last parameter. 154 | You can check the CheckBox class on TUI.cs file. 155 | The schema is also set on TUI.cs file, and is used to change the colors of the boxes. 156 | The last parameter is used to return only the options selected by the user(true), or the entire list, with checked and unchecked values. 157 | 158 | >Note that the return type is a list of CheckBoxOption 159 | 160 | ## Draw a list box 161 | [![asciicast](https://asciinema.org/a/z3qETOmPLjxLabSp1hALvREbo.svg)](https://asciinema.org/a/z3qETOmPLjxLabSp1hALvREbo) 162 | ![drawList](imgs/drawlist.png) 163 | 164 | This type of box will render a List of otions where the user can select only one option. This box can be used as simple selction and menu. 165 | 166 | >For now there is no description. If you want to show the description, you have to format manually the strings. 167 | ```csharp 168 | string ListBox = t.DrawList(new List() { 169 | "Banana", 170 | "Apple", 171 | "Orange" 172 | }); 173 | ``` 174 | ## Draw a Book box 175 | [![asciicast](https://asciinema.org/a/uaBmZK6X3nS8tovaTUbDCrHi3.svg)](https://asciinema.org/a/uaBmZK6X3nS8tovaTUbDCrHi3) 176 | ![drawBook](imgs/drawBook.png) 177 | 178 | This type of box will render a "book" splitting the text into pages. 179 | 180 | The page number will be at the title bar, after the title 181 | 182 | ```csharp 183 | string ListBox = t.DrawBook(); 184 | ``` 185 | 186 | # Bugs 187 | Yes. 188 | -------------------------------------------------------------------------------- /Tui.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Linq; 5 | 6 | #nullable enable 7 | 8 | namespace tui_netcore 9 | { 10 | public class Tui 11 | { 12 | // Box Width 13 | public int Width { get; set; } 14 | // Box Height 15 | public int Height { get; set; } 16 | 17 | // Position (left) of the first character of the box inside the terminal 18 | public int PosLeft { get; set; } 19 | // Position (top) of the first character of the box inside the terminal 20 | public int PosTop { get; set; } 21 | public string Title { get; set; } 22 | public string Body { get; set; } 23 | 24 | //Character Used to navigate, answer strings and select an option 25 | public char AnswerChar { get; set; } 26 | public char SelectedChar { get; set; } 27 | 28 | public char HorizontalChar { get; set; } 29 | public char VerticalChar { get; set; } 30 | public char TopLeftChar { get; set; } 31 | public char TopRightChar { get; set; } 32 | public char BottomLeftChar { get; set; } 33 | public char BottomRightChar { get; set; } 34 | public char IntersectionChar { get; set; } 35 | public char EmptyChar { get; set; } 36 | public int MarginLeft { get; set; } 37 | public int MarginTop { get; set; } 38 | 39 | public BorderStyleBrush BorderStyle { get; set; } = BorderStyles.Text; 40 | 41 | // * This is used to draw multiple lines below the body (checkbox/radio) 42 | public int LastBodyHeight { get; set; } 43 | 44 | public enum ColorSchema 45 | { 46 | Regular, 47 | Info, 48 | Warning, 49 | Danger, 50 | System 51 | 52 | } 53 | 54 | /// 55 | /// This is the object used for each option in the checkbox and/or radio options 56 | /// 57 | public struct CheckBoxOption 58 | { 59 | public bool IsSelected { get; set; } 60 | public string Name { get; set; } 61 | public string Description { get; set; } 62 | } 63 | 64 | public sealed class BorderStyleBrush 65 | { 66 | public char TopLeftChar { get; } 67 | public char HorizontalChar { get; } 68 | public char TopRightChar { get; } 69 | public char VerticalChar { get; } 70 | public char BottomLeftChar { get; } 71 | public char BottomRightChar { get; } 72 | 73 | public BorderStyleBrush(char topLeft, char horizontal, char topRight, char vertical, char bottomLeft, char bottomRight) 74 | { 75 | TopLeftChar = topLeft; 76 | HorizontalChar = horizontal; 77 | TopRightChar = topRight; 78 | VerticalChar = vertical; 79 | BottomLeftChar = bottomLeft; 80 | BottomRightChar = bottomRight; 81 | } 82 | 83 | public void Deconstruct(out char topLeft, out char horizontal, out char topRight, out char vertical, out char bottomLeft, out char bottomRight) 84 | { 85 | topLeft = TopLeftChar; 86 | horizontal = HorizontalChar; 87 | topRight = TopRightChar; 88 | vertical = VerticalChar; 89 | bottomLeft = BottomLeftChar; 90 | bottomRight = BottomRightChar; 91 | } 92 | } 93 | 94 | public static class BorderStyles 95 | { 96 | public static readonly BorderStyleBrush Text = new BorderStyleBrush('+', '-', '+', '|', '+', '+'); 97 | public static readonly BorderStyleBrush SingleLine = new BorderStyleBrush('┌', '─', '┐', '│', '└', '┘'); 98 | public static readonly BorderStyleBrush DoubleLine = new BorderStyleBrush('╔', '═', '╗', '║', '╚', '╝'); 99 | } 100 | 101 | public Tui(int width = 100, int height = 80, int posLeft = 0, int posTop = 0) 102 | { 103 | Width = width; 104 | Height = height; 105 | PosTop = posTop; 106 | PosLeft = posLeft; 107 | AnswerChar = '>'; 108 | SelectedChar = '*'; 109 | IntersectionChar = '+'; 110 | 111 | EmptyChar = ' '; 112 | Title = String.Empty; 113 | Body = String.Empty; 114 | MarginLeft = 4; 115 | MarginTop = 2; 116 | LastBodyHeight = 0; 117 | } 118 | 119 | public Tui() : this(Console.WindowWidth, Console.WindowHeight, 0, 0) 120 | { 121 | } 122 | 123 | /// 124 | /// Defines a Color schema to the box 125 | /// 126 | /// 127 | private void setColorSchema(ColorSchema color) 128 | { 129 | switch (color) 130 | { 131 | case ColorSchema.Regular: 132 | Console.BackgroundColor = ConsoleColor.Black; 133 | Console.ForegroundColor = ConsoleColor.White; 134 | break; 135 | case ColorSchema.Info: 136 | Console.BackgroundColor = ConsoleColor.DarkBlue; 137 | Console.ForegroundColor = ConsoleColor.White; 138 | break; 139 | case ColorSchema.Warning: 140 | Console.BackgroundColor = ConsoleColor.DarkYellow; 141 | Console.ForegroundColor = ConsoleColor.White; 142 | break; 143 | case ColorSchema.Danger: 144 | Console.BackgroundColor = ConsoleColor.DarkRed; 145 | Console.ForegroundColor = ConsoleColor.White; 146 | break; 147 | case ColorSchema.System: 148 | Console.BackgroundColor = ConsoleColor.White; 149 | Console.ForegroundColor = ConsoleColor.Black; 150 | break; 151 | } 152 | } 153 | 154 | /// 155 | /// Print the entire Screen, Use this to test your terminal 156 | /// 157 | public void TestSize(ColorSchema schema = ColorSchema.Info) 158 | { 159 | for (int i = 0; i < Height; i++) 160 | { 161 | for (int j = 0; j < Width; j++) 162 | { 163 | Console.SetCursorPosition(j, i); 164 | System.Console.Write("+"); 165 | } 166 | Console.SetCursorPosition((Width / 2) - 6, i); 167 | setColorSchema(schema); 168 | System.Console.Write($"Line {i}"); 169 | Console.ResetColor(); 170 | } 171 | } 172 | 173 | private void drawTitle() 174 | { 175 | Console.SetCursorPosition((Width / 2) - (Title.Length / 2), PosTop); 176 | Console.Write(Title); 177 | } 178 | 179 | /// 180 | /// Roughly break body text in pages, considering no line breaks. 181 | /// If there are line breaks, the window will not be complete. 182 | /// words may break abruptely 183 | /// 184 | /// 185 | private List separatePages() 186 | { 187 | var pages = new List(); 188 | int index = -1; 189 | int totalSpace = (Width - (2 * MarginLeft)) * (Height - (2 * MarginTop) - 2); 190 | 191 | foreach (var c in Body) 192 | { 193 | if (index == -1) 194 | { 195 | pages.Add(c.ToString()); 196 | index++; 197 | } 198 | else if (pages.Last().ToString().Count() - 1 < totalSpace) 199 | { 200 | pages[index] += c.ToString(); 201 | } 202 | else 203 | { 204 | pages.Add(c.ToString()); 205 | index++; 206 | } 207 | } 208 | 209 | return pages; 210 | } 211 | 212 | private void drawBody() 213 | { 214 | int usableSpace = Width - (2 * MarginLeft); 215 | //* TODO: Improve the way the split is done to stay inside the box 216 | //! TODO: "\n" Breaks the layout. Find a way to make this work correctly 217 | 218 | int tmpLine = 0; 219 | StringBuilder tmpText = new StringBuilder(usableSpace, usableSpace); 220 | string[] tmpBody = Body.Split(' '); 221 | foreach (string s in tmpBody) 222 | { 223 | try 224 | { 225 | if (s == "\n") 226 | { 227 | throw new ArgumentOutOfRangeException(); 228 | } 229 | tmpText.Append(s); 230 | tmpText.Append(" "); 231 | } 232 | catch (ArgumentOutOfRangeException) 233 | { 234 | Console.SetCursorPosition((PosLeft + MarginLeft), (PosTop + MarginTop + tmpLine)); 235 | System.Console.Write(tmpText); 236 | tmpLine++; 237 | tmpText.Clear(); 238 | } 239 | } 240 | Console.SetCursorPosition((PosLeft + MarginLeft), (PosTop + MarginTop + tmpLine)); 241 | LastBodyHeight = PosTop + MarginTop + tmpLine; 242 | System.Console.Write(tmpText); 243 | } 244 | 245 | private void DrawCorners() 246 | { 247 | Console.SetCursorPosition(PosLeft, PosTop); 248 | Console.Write(BorderStyle.TopLeftChar); 249 | 250 | Console.SetCursorPosition(PosLeft + Width - 1, PosTop); 251 | System.Console.Write(BorderStyle.TopRightChar); 252 | 253 | Console.SetCursorPosition(PosLeft, PosTop + Height - 1); 254 | System.Console.Write(BorderStyle.BottomLeftChar); 255 | 256 | Console.SetCursorPosition(PosLeft + Width - 1, PosTop + Height - 1); 257 | System.Console.Write(BorderStyle.BottomRightChar); 258 | } 259 | 260 | /// 261 | /// This Frame wraps the entire screen, printing spaces inside. 262 | /// 263 | /// Color Scheme to be used 264 | public void Draw(ColorSchema schema = ColorSchema.Regular) 265 | { 266 | setColorSchema(schema); 267 | 268 | var headLine = new Char[Width]; 269 | var bodyLine = new Char[Width]; 270 | 271 | for (var i = 0; i < Width; ++i) 272 | { 273 | headLine[i] = i == 0 || i == Width - 1 ? BorderStyle.VerticalChar : BorderStyle.HorizontalChar; 274 | bodyLine[i] = i == 0 || i == Width - 1 ? BorderStyle.VerticalChar : EmptyChar; 275 | } 276 | 277 | for (int i = PosTop; i < Height + PosTop; i++) 278 | { 279 | Console.SetCursorPosition(PosLeft, i); 280 | Console.Write(i == PosTop || i == Height + PosTop - 1 ? headLine : bodyLine); 281 | } 282 | 283 | DrawCorners(); 284 | if (!String.IsNullOrEmpty(Title)) drawTitle(); 285 | if (!String.IsNullOrEmpty(Body)) drawBody(); 286 | 287 | setColorSchema(ColorSchema.Regular); 288 | } 289 | 290 | /// 291 | /// This method Creates an input so the user can answer things 292 | /// 293 | /// 294 | /// string containing the user answer 295 | public string? DrawInput(ColorSchema schema = ColorSchema.Regular) 296 | { 297 | Draw(schema); 298 | setColorSchema(schema); 299 | Console.SetCursorPosition((PosLeft + MarginLeft), (PosTop + Height - MarginTop)); 300 | Console.Write($"{AnswerChar} "); 301 | string? answer = Console.ReadLine(); 302 | setColorSchema(ColorSchema.Regular); 303 | return answer; 304 | } 305 | 306 | /// 307 | /// Prints message as book pages, based on window size. 308 | /// Has three button options (next, previous, done) that are used to go forward, backward and exit scree 309 | /// 310 | /// Color Schema 311 | /// Text for Next option 312 | /// Text for Previous option 313 | /// Text for Quit option 314 | /// 0=Prev / 1=Next / 2=Done 315 | public void DrawBook(ColorSchema schema = ColorSchema.Regular, string txtNext = "next", string txtPrev = "previous", string txtDone = "Done", int defaultAnswer = 1) 316 | { 317 | setColorSchema(schema); 318 | int answer = defaultAnswer; 319 | int CursorPrev = PosLeft + MarginLeft; 320 | int CursorDone = PosLeft + Width - (2 * MarginLeft); 321 | int CursorNext = (PosLeft + Width) / 2; 322 | int Line = (PosTop + Height - MarginTop); 323 | int index = 0; 324 | string oldTitle = Title; 325 | 326 | List pages = separatePages(); 327 | int totalPages = pages.Count(); 328 | Body = pages[0]; 329 | 330 | ConsoleKeyInfo keypress; 331 | bool keepGoing = true; 332 | while (keepGoing) 333 | { 334 | Title = oldTitle + $@" [ {index + 1}/{totalPages} ]"; 335 | Draw(schema); 336 | Console.SetCursorPosition(CursorPrev + 1, Line); 337 | Console.Write(txtPrev); 338 | Console.SetCursorPosition(CursorNext + 1, Line); 339 | Console.Write(txtNext); 340 | Console.SetCursorPosition(CursorDone + 1, Line); 341 | Console.Write(txtDone); 342 | 343 | Console.SetCursorPosition(CursorPrev, Line); 344 | Console.Write(answer == 0 ? AnswerChar : EmptyChar); 345 | Console.SetCursorPosition(CursorNext, Line); 346 | Console.Write(answer == 1 ? AnswerChar : EmptyChar); 347 | Console.SetCursorPosition(CursorDone, Line); 348 | Console.Write(answer == 2 ? AnswerChar : EmptyChar); 349 | 350 | keypress = Console.ReadKey(false); 351 | 352 | switch (keypress.Key) 353 | { 354 | case ConsoleKey.LeftArrow: 355 | answer = answer - 1 >= 0 ? answer - 1 : 2; 356 | break; 357 | case ConsoleKey.RightArrow: 358 | answer = answer + 1 <= 2 ? answer + 1 : 0; 359 | break; 360 | case ConsoleKey.Enter: 361 | switch (answer) 362 | { 363 | case 0: 364 | index = index - 1 >= 0 ? index - 1 : pages.Count() - 1; 365 | break; 366 | case 1: 367 | index = index + 1 <= pages.Count() - 1 ? index + 1 : 0; 368 | break; 369 | case 2: 370 | keepGoing = false; 371 | break; 372 | 373 | } 374 | break; 375 | } 376 | Body = pages[index]; 377 | } 378 | 379 | setColorSchema(ColorSchema.Regular); 380 | } 381 | 382 | /// 383 | /// Draws a box with two options to answer (Yes/No) 384 | /// Left/Right arrows to move between options 385 | /// Enter to select option 386 | /// 387 | /// Color Schema 388 | /// Text to Yes option 389 | /// Text to No option 390 | /// true=yes/false=no 391 | /// true=yes/false=no 392 | public bool DrawYesNo(ColorSchema schema = ColorSchema.Regular, string txtYes = "Yes", string txtNo = "No", bool defaultAnswer = false) 393 | { 394 | Draw(schema); 395 | setColorSchema(schema); 396 | bool answer = defaultAnswer; 397 | int CursorYes = PosLeft + MarginLeft; 398 | int CursorNo = PosLeft + Width - (2 * MarginLeft); 399 | int Line = (PosTop + Height - MarginTop); 400 | 401 | ConsoleKeyInfo keypress; 402 | do 403 | { 404 | Console.SetCursorPosition(CursorYes + 1, Line); 405 | Console.Write(txtYes); 406 | Console.SetCursorPosition(CursorNo + 1, Line); 407 | Console.Write(txtNo); 408 | 409 | Console.SetCursorPosition(CursorYes, Line); 410 | Console.Write(answer ? AnswerChar : EmptyChar); 411 | Console.SetCursorPosition(CursorNo, Line); 412 | Console.Write(!answer ? AnswerChar : EmptyChar); 413 | keypress = Console.ReadKey(false); 414 | 415 | if ((keypress.Key == ConsoleKey.LeftArrow) || (keypress.Key == ConsoleKey.RightArrow)) 416 | { 417 | answer = !answer; 418 | } 419 | 420 | } while (keypress.Key != ConsoleKey.Enter); 421 | setColorSchema(ColorSchema.Regular); 422 | return answer; 423 | } 424 | 425 | /// 426 | /// This method draws the box, and wait the user press any key to continue 427 | /// 428 | /// Color schema 429 | /// Text to appear on the bottom of the box 430 | public void DrawOk(ColorSchema schema = ColorSchema.Regular, string txtOk = "Press any key to continue...") 431 | { 432 | Draw(schema); 433 | setColorSchema(schema); 434 | int CursorOk = PosLeft + MarginLeft; 435 | int Line = (PosTop + Height - MarginTop); 436 | Console.SetCursorPosition(CursorOk, Line); 437 | Console.Write($"{AnswerChar}{txtOk}"); 438 | Console.ReadKey(); 439 | } 440 | 441 | public List DrawCheckBox(List options, ColorSchema schema = ColorSchema.Regular, bool onlyChecked = true) 442 | { 443 | Draw(schema); 444 | setColorSchema(schema); 445 | int Line = LastBodyHeight + MarginTop; 446 | int tmpCursor = 0; 447 | List TmpOptions = options; 448 | //Continue Here 449 | foreach (CheckBoxOption o in TmpOptions) 450 | { 451 | char tmpSelected = o.IsSelected ? SelectedChar : EmptyChar; 452 | Console.SetCursorPosition(MarginLeft + PosLeft, Line); 453 | System.Console.Write($" [{tmpSelected}] {o.Name} - {o.Description}"); 454 | Line++; 455 | } 456 | 457 | Line -= options.Count; 458 | 459 | ConsoleKeyInfo keypress; 460 | do 461 | { 462 | 463 | Console.SetCursorPosition(MarginLeft + PosLeft, Line + tmpCursor); 464 | Console.Write(AnswerChar); 465 | keypress = Console.ReadKey(true); 466 | if (keypress.Key == ConsoleKey.UpArrow) 467 | { 468 | if (tmpCursor > 0) 469 | { 470 | Console.SetCursorPosition(MarginLeft + PosLeft, Line + tmpCursor); 471 | Console.Write(EmptyChar); 472 | tmpCursor--; 473 | } 474 | } 475 | if (keypress.Key == ConsoleKey.DownArrow) 476 | { 477 | if (tmpCursor < TmpOptions.Count - 1) 478 | { 479 | Console.SetCursorPosition(MarginLeft + PosLeft, Line + tmpCursor); 480 | Console.Write(EmptyChar); 481 | tmpCursor++; 482 | } 483 | } 484 | if (keypress.Key == ConsoleKey.Spacebar) 485 | { 486 | CheckBoxOption c = TmpOptions[tmpCursor]; 487 | c.IsSelected = !c.IsSelected; 488 | char ch = c.IsSelected ? SelectedChar : EmptyChar; 489 | Console.SetCursorPosition(MarginLeft + 2 + PosLeft, Line + tmpCursor); 490 | TmpOptions[tmpCursor] = c; 491 | Console.Write(ch); 492 | 493 | } 494 | 495 | } while (keypress.Key != ConsoleKey.Enter); 496 | 497 | if (onlyChecked) 498 | { 499 | TmpOptions = (from t in TmpOptions where t.IsSelected select t).ToList(); 500 | } 501 | 502 | setColorSchema(ColorSchema.Regular); 503 | return TmpOptions; 504 | } 505 | 506 | public string DrawList(List options, ColorSchema schema = ColorSchema.Regular) 507 | { 508 | Draw(schema); 509 | setColorSchema(schema); 510 | int Line = LastBodyHeight + MarginTop; 511 | int tmpCursor = 0; 512 | foreach (string s in options) 513 | { 514 | Console.SetCursorPosition(MarginLeft + PosLeft, Line); 515 | System.Console.Write($" {s}"); 516 | Line++; 517 | } 518 | 519 | Line -= options.Count; 520 | 521 | ConsoleKeyInfo keypress; 522 | do 523 | { 524 | 525 | Console.SetCursorPosition(MarginLeft + PosLeft, Line + tmpCursor); 526 | Console.Write(AnswerChar); 527 | keypress = Console.ReadKey(true); 528 | if (keypress.Key == ConsoleKey.UpArrow) 529 | { 530 | if (tmpCursor > 0) 531 | { 532 | Console.SetCursorPosition(MarginLeft + PosLeft, Line + tmpCursor); 533 | Console.Write(EmptyChar); 534 | tmpCursor--; 535 | } 536 | } 537 | if (keypress.Key == ConsoleKey.DownArrow) 538 | { 539 | if (tmpCursor < options.Count - 1) 540 | { 541 | Console.SetCursorPosition(MarginLeft + PosLeft, Line + tmpCursor); 542 | Console.Write(EmptyChar); 543 | tmpCursor++; 544 | } 545 | } 546 | 547 | } while (keypress.Key != ConsoleKey.Enter); 548 | setColorSchema(ColorSchema.Regular); 549 | return options[tmpCursor]; 550 | } 551 | } 552 | } -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect -------------------------------------------------------------------------------- /imgs/drawBook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcrozetta/tui-netcore/81eb78ee15ef40721bc62bd6d9e5e66afe1e51f5/imgs/drawBook.png -------------------------------------------------------------------------------- /imgs/drawlist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcrozetta/tui-netcore/81eb78ee15ef40721bc62bd6d9e5e66afe1e51f5/imgs/drawlist.png -------------------------------------------------------------------------------- /imgs/screen-tui-netcore-draw-input.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcrozetta/tui-netcore/81eb78ee15ef40721bc62bd6d9e5e66afe1e51f5/imgs/screen-tui-netcore-draw-input.gif -------------------------------------------------------------------------------- /imgs/screen-tui-netcore-draw-ok-box.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcrozetta/tui-netcore/81eb78ee15ef40721bc62bd6d9e5e66afe1e51f5/imgs/screen-tui-netcore-draw-ok-box.gif -------------------------------------------------------------------------------- /imgs/screen-tui-netcore-hello-world.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcrozetta/tui-netcore/81eb78ee15ef40721bc62bd6d9e5e66afe1e51f5/imgs/screen-tui-netcore-hello-world.gif -------------------------------------------------------------------------------- /imgs/screen-tui-netcore-yes-no.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcrozetta/tui-netcore/81eb78ee15ef40721bc62bd6d9e5e66afe1e51f5/imgs/screen-tui-netcore-yes-no.gif -------------------------------------------------------------------------------- /nuget/fc.tui-core.0.0.2-alpha.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcrozetta/tui-netcore/81eb78ee15ef40721bc62bd6d9e5e66afe1e51f5/nuget/fc.tui-core.0.0.2-alpha.nupkg -------------------------------------------------------------------------------- /tui-netcore.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | net5.0 12 | Simple TUI 13 | Simple Text Interface for .net Core 14 | fc.tui-core 15 | 0.0.7 16 | Fernando Crozetta 17 | czetta 18 | https://github.com/fcrozetta/tui-netcore/blob/master/LICENSE 19 | https://github.com/fcrozetta/tui-netcore/ 20 | https://github.com/fcrozetta/tui-netcore/ 21 | 22 | true 23 | true 24 | snupkg 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | --------------------------------------------------------------------------------