simple-text-ui 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present U.N. Owen <void@some.where>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.5
2
+ Name: simple-text-ui
3
+ Version: 0.0.1
4
+ Summary: A package to imlement a commonly used textual UI
5
+ Author-email: Daniel Brusilovksy <brusilovskydaniel3@gmail.com>
6
+ License-Expression: MIT
7
+ License-File: LICENSE.txt
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: Implementation :: CPython
16
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Simple Text UI
21
+
22
+ [![PyPI - Version](https://img.shields.io/pypi/v/simple-text-ui.svg)](https://pypi.org/project/simple-text-ui)
23
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/simple-text-ui.svg)](https://pypi.org/project/simple-text-ui)
24
+
25
+ -----
26
+
27
+ ## Table of Contents
28
+
29
+ - [Installation](#installation)
30
+ - [License](#license)
31
+ - [Information](#information)
32
+
33
+ ## Installation
34
+
35
+ ```console
36
+ pip install simple-text-ui
37
+ ```
38
+
39
+ ## License
40
+
41
+ `simple-text-ui` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
42
+
43
+
44
+ ## Information
45
+
46
+ `simple-text-ui` is a package that creates an object-oriented interface for one kind of textual UI used by beginner programs. This package is designed to make coding that interface much easier.
@@ -0,0 +1,27 @@
1
+ # Simple Text UI
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/simple-text-ui.svg)](https://pypi.org/project/simple-text-ui)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/simple-text-ui.svg)](https://pypi.org/project/simple-text-ui)
5
+
6
+ -----
7
+
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [License](#license)
12
+ - [Information](#information)
13
+
14
+ ## Installation
15
+
16
+ ```console
17
+ pip install simple-text-ui
18
+ ```
19
+
20
+ ## License
21
+
22
+ `simple-text-ui` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
23
+
24
+
25
+ ## Information
26
+
27
+ `simple-text-ui` is a package that creates an object-oriented interface for one kind of textual UI used by beginner programs. This package is designed to make coding that interface much easier.
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "simple-text-ui"
7
+ dynamic = ["version"]
8
+ description = 'A package to imlement a commonly used textual UI'
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ keywords = []
13
+ authors = [
14
+ { name = "Daniel Brusilovksy", email = "brusilovskydaniel3@gmail.com" },
15
+ ]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Programming Language :: Python",
19
+ "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: Implementation :: CPython",
25
+ "Programming Language :: Python :: Implementation :: PyPy",
26
+ ]
27
+ dependencies = []
28
+
29
+ [tool.hatch.version]
30
+ path = "src/simple_text_ui/__about__.py"
31
+
32
+ [tool.hatch.envs.types]
33
+ extra-dependencies = [
34
+ "mypy>=1.0.0",
35
+ ]
36
+ [tool.hatch.envs.types.scripts]
37
+ check = "mypy --install-types --non-interactive {args:src/simple_text_ui tests}"
38
+
39
+ [tool.coverage.run]
40
+ source_pkgs = ["simple_text_ui", "tests"]
41
+ branch = true
42
+ parallel = true
43
+ omit = [
44
+ "src/simple_text_ui/__about__.py",
45
+ ]
46
+
47
+ [tool.coverage.paths]
48
+ simple_text_ui = ["src/simple_text_ui", "*/simple-text-ui/src/simple_text_ui"]
49
+ tests = ["tests", "*/simple-text-ui/tests"]
50
+
51
+ [tool.coverage.report]
52
+ exclude_lines = [
53
+ "no cov",
54
+ "if __name__ == .__main__.:",
55
+ "if TYPE_CHECKING:",
56
+ ]
@@ -0,0 +1,4 @@
1
+ # SPDX-FileCopyrightText: 2026-present Daniel Brusilovsky <brusilovskydaniel3@gmail.com>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ __version__ = "0.0.1"
@@ -0,0 +1,4 @@
1
+ # SPDX-FileCopyrightText: 2026-present Daniel Brusilovsky <brusilovskydaniel3@gmail.com>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ from text_ui import TextUI
@@ -0,0 +1,75 @@
1
+ import typing
2
+ import sys
3
+
4
+
5
+ class TextUI:
6
+ """A class to implement a commonly used format for textual GUI
7
+ This class uses __doc__(descriptions) as descriptions in the UI"""
8
+
9
+ options_template: str = "\n{title}\n\n{options}"
10
+
11
+ option_template: str = "{num}: {name}\n"
12
+
13
+ def __init__(self, title: str, auto_quit: bool = True):
14
+ """Takes a title and an optional auto_quit parameter,
15
+ default is to bind a basic quit method"""
16
+ self.title = title
17
+ self.auto_quit = auto_quit
18
+ self.bindings: typing.Dict[int, typing.Callable] = dict()
19
+ # Stores the next available integer option int
20
+ self._next_option: int = 0
21
+ # Binds default quit if specified
22
+ if self.auto_quit:
23
+ self.bind(self._quit)
24
+
25
+ def _quit(self):
26
+ "Quit"
27
+ sys.exit()
28
+
29
+ def bind(self, func: typing.Callable) -> None:
30
+ """Bind a callable object to an option integer.
31
+ Callable must have a description"""
32
+ if (not callable(func)) or (not func.__doc__):
33
+ raise TypeError("Invalid func. Did you forget a description?")
34
+ self.bindings[self._next_option] = func
35
+ self._next_option += 1
36
+
37
+ def loop(self) -> None:
38
+ """Main loop, builds table and runs chosen callable"""
39
+ while True:
40
+ self.build_table()
41
+ self.run_func(self.get_choice())
42
+
43
+ def build_table(self) -> None:
44
+ """Create a table of options to choose from"""
45
+ options: typing.List[str] = [
46
+ self.option_template.format(num=num, name=name.__doc__)
47
+ for num, name in self.bindings.items()
48
+ ]
49
+ print(self.options_template.format(title=self.title,\
50
+ options="".join(options)))
51
+
52
+ def get_choice(self) -> int:
53
+ """Get the user's chosen function"""
54
+ choice: str = "_invalid_string"
55
+ while self._invalid_choice(choice):
56
+ choice = input("Enter your choice: ")
57
+ if self._invalid_choice(choice):
58
+ print("Invalid choice. Please try again.\n")
59
+ else:
60
+ print()
61
+ return int(choice)
62
+
63
+ def run_func(self, choice: int) -> None:
64
+ """Run the chosen function"""
65
+ self.bindings[choice]()
66
+
67
+ def _invalid_choice(self, choice: str | int) -> bool:
68
+ """Check if a choice is invalid"""
69
+ try:
70
+ choice = int(choice)
71
+ except:
72
+ return True
73
+ if choice not in self.bindings.keys():
74
+ return True
75
+ return False
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2026-present Daniel Brusilovsky <brusilovskydaniel3@gmail.com>
2
+ #
3
+ # SPDX-License-Identifier: MIT