binary-equalab 1.0.0__py3-none-any.whl → 2.0.1__py3-none-any.whl

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.
@@ -1,23 +1,23 @@
1
- """
2
- Binary EquaLab CLI
3
- Command-line CAS calculator with Spanish math functions.
4
- """
5
-
6
- __version__ = "1.0.0"
7
- __author__ = "BinaryEquaLab Team"
8
-
9
- from .engine import MathEngine
10
- from .functions import (
11
- derivar, integrar, limite, sumatoria,
12
- simplificar, expandir, factorizar, resolver,
13
- van, tir, depreciar, interes_simple, interes_compuesto,
14
- media, mediana, desviacion, varianza
15
- )
16
-
17
- __all__ = [
18
- "MathEngine",
19
- "derivar", "integrar", "limite", "sumatoria",
20
- "simplificar", "expandir", "factorizar", "resolver",
21
- "van", "tir", "depreciar", "interes_simple", "interes_compuesto",
22
- "media", "mediana", "desviacion", "varianza",
23
- ]
1
+ """
2
+ Binary EquaLab CLI
3
+ Command-line CAS calculator with Spanish math functions.
4
+ """
5
+
6
+ __version__ = "1.0.0"
7
+ __author__ = "BinaryEquaLab Team"
8
+
9
+ from .engine import MathEngine
10
+ from .functions import (
11
+ derivar, integrar, limite, sumatoria,
12
+ simplificar, expandir, factorizar, resolver,
13
+ van, tir, depreciar, interes_simple, interes_compuesto,
14
+ media, mediana, desviacion, varianza
15
+ )
16
+
17
+ __all__ = [
18
+ "MathEngine",
19
+ "derivar", "integrar", "limite", "sumatoria",
20
+ "simplificar", "expandir", "factorizar", "resolver",
21
+ "van", "tir", "depreciar", "interes_simple", "interes_compuesto",
22
+ "media", "mediana", "desviacion", "varianza",
23
+ ]
binary_equalab/cli.py CHANGED
@@ -1,180 +1,244 @@
1
- """
2
- Binary EquaLab CLI
3
- Interactive REPL and command-line interface.
4
- """
5
-
6
- import sys
7
- from typing import Optional
8
- from rich.console import Console
9
- from rich.panel import Panel
10
- from rich.markdown import Markdown
11
- from rich.text import Text
12
- from prompt_toolkit import PromptSession
13
- from prompt_toolkit.history import FileHistory
14
- from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
15
- from prompt_toolkit.styles import Style
16
- import os
17
-
18
- from .engine import MathEngine
19
-
20
- console = Console()
21
-
22
- BANNER = """
23
- [bold orange1]╔══════════════════════════════════════════════════════════╗
24
- ║ [white]Binary EquaLab CLI[/white] [dim]v1.0.0[/dim]
25
- ║ [dim italic]"El álgebra también siente"[/dim italic]
26
- ╚══════════════════════════════════════════════════════════╝[/bold orange1]
27
-
28
- [dim]Comandos:[/dim]
29
- [cyan]help[/cyan] - Lista de funciones disponibles
30
- [cyan]exit[/cyan] - Salir
31
- [cyan]cls[/cyan] - Limpiar pantalla
32
-
33
- [dim]Ejemplos:[/dim]
34
- derivar(x^2 + 3x, x)
35
- integrar(sin(x), x)
36
- van(0.10, -1000, 300, 400, 500)
37
- """
38
-
39
- HELP_TEXT = """
40
- ## Funciones Disponibles
41
-
42
- ### Cálculo
43
- | Función | Ejemplo |
44
- |---------|---------|
45
- | `derivar(expr, var)` | `derivar(x^2, x)` → `2*x` |
46
- | `integrar(expr, var)` | `integrar(sin(x), x)` → `-cos(x)` |
47
- | `limite(expr, var, punto)` | `limite(sin(x)/x, x, 0)` → `1` |
48
- | `sumatoria(expr, var, a, b)` | `sumatoria(n^2, n, 1, 10)` |
49
-
50
- ### Álgebra
51
- | Función | Ejemplo |
52
- |---------|---------|
53
- | `simplificar(expr)` | `simplificar((x^2-1)/(x-1))` |
54
- | `expandir(expr)` | `expandir((x+1)^2)` |
55
- | `factorizar(expr)` | `factorizar(x^2-1)` |
56
- | `resolver(expr, var)` | `resolver(x^2-4, x)` → `[-2, 2]` |
57
-
58
- ### Estadística
59
- | Función | Ejemplo |
60
- |---------|---------|
61
- | `media(...)` | `media(1, 2, 3, 4, 5)` → `3` |
62
- | `mediana(...)` | `mediana(1, 2, 3, 4, 5)` → `3` |
63
- | `desviacion(...)` | `desviacion(1, 2, 3, 4, 5)` |
64
- | `varianza(...)` | `varianza(1, 2, 3, 4, 5)` |
65
-
66
- ### Finanzas
67
- | Función | Ejemplo |
68
- |---------|---------|
69
- | `van(tasa, flujo0, flujo1, ...)` | `van(0.10, -1000, 300, 400)` |
70
- | `tir(flujo0, flujo1, ...)` | `tir(-1000, 300, 400, 500)` |
71
- | `depreciar(costo, residual, años)` | `depreciar(10000, 1000, 5)` |
72
- | `interes_simple(capital, tasa, tiempo)` | `interes_simple(1000, 0.05, 3)` |
73
- | `interes_compuesto(capital, tasa, n, tiempo)` | `interes_compuesto(1000, 0.05, 12, 3)` |
74
- """
75
-
76
-
77
- def get_prompt_style():
78
- return Style.from_dict({
79
- 'prompt': '#ff6b35 bold',
80
- })
81
-
82
-
83
- def repl():
84
- """Start the interactive REPL."""
85
- console.print(BANNER)
86
-
87
- engine = MathEngine()
88
-
89
- # Setup history file
90
- history_path = os.path.expanduser("~/.binary_math_history")
91
- session: PromptSession = PromptSession(
92
- history=FileHistory(history_path),
93
- auto_suggest=AutoSuggestFromHistory(),
94
- style=get_prompt_style(),
95
- )
96
-
97
- while True:
98
- try:
99
- # Read input
100
- user_input = session.prompt([('class:prompt', '>>> ')]).strip()
101
-
102
- if not user_input:
103
- continue
104
-
105
- # Handle special commands
106
- if user_input.lower() in ('exit', 'quit', 'q'):
107
- console.print("[dim]¡Hasta luego![/dim]")
108
- break
109
-
110
- if user_input.lower() in ('cls', 'clear'):
111
- console.clear()
112
- console.print(BANNER)
113
- continue
114
-
115
- if user_input.lower() == 'help':
116
- console.print(Markdown(HELP_TEXT))
117
- continue
118
-
119
- if user_input.lower() == 'history':
120
- for i, h in enumerate(engine.history[-10:], 1):
121
- console.print(f"[dim]{i}.[/dim] {h}")
122
- continue
123
-
124
- # Evaluate expression
125
- try:
126
- result = engine.evaluate(user_input)
127
-
128
- if result is None:
129
- continue
130
-
131
- # Format output
132
- if isinstance(result, (list, tuple)):
133
- console.print(f"[bold green]→[/bold green] {list(result)}")
134
- elif isinstance(result, dict):
135
- for key, value in result.items():
136
- console.print(f" [cyan]{key}:[/cyan] {value}")
137
- else:
138
- console.print(f"[bold green]→[/bold green] {result}")
139
-
140
- except Exception as e:
141
- console.print(f"[bold red]Error:[/bold red] {e}")
142
-
143
- except KeyboardInterrupt:
144
- console.print()
145
- continue
146
- except EOFError:
147
- console.print("\n[dim]¡Hasta luego![/dim]")
148
- break
149
-
150
-
151
- def one_liner(expression: str):
152
- """Evaluate a single expression from command line."""
153
- engine = MathEngine()
154
- try:
155
- result = engine.evaluate(expression)
156
- if isinstance(result, (list, tuple)):
157
- print(list(result))
158
- elif isinstance(result, dict):
159
- for key, value in result.items():
160
- print(f"{key}: {value}")
161
- else:
162
- print(result)
163
- except Exception as e:
164
- print(f"Error: {e}", file=sys.stderr)
165
- sys.exit(1)
166
-
167
-
168
- def main():
169
- """CLI entry point."""
170
- if len(sys.argv) > 1:
171
- # One-liner mode
172
- expression = " ".join(sys.argv[1:])
173
- one_liner(expression)
174
- else:
175
- # REPL mode
176
- repl()
177
-
178
-
179
- if __name__ == "__main__":
180
- main()
1
+ """
2
+ Binary EquaLab CLI
3
+ Interactive REPL and command-line interface.
4
+ """
5
+
6
+ import sys
7
+ from typing import Optional
8
+ from rich.console import Console
9
+ from rich.panel import Panel
10
+ from rich.markdown import Markdown
11
+ from rich.text import Text
12
+ from prompt_toolkit import PromptSession
13
+ from prompt_toolkit.history import FileHistory
14
+ from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
15
+ from prompt_toolkit.styles import Style
16
+ import os
17
+
18
+ from .engine import MathEngine
19
+
20
+ console = Console()
21
+
22
+ BANNER = """
23
+ [bold orange1]╔══════════════════════════════════════════════════════════╗
24
+ ║ [white]Binary EquaLab CLI[/white] [dim]Aurora v2.0[/dim]
25
+ ║ [dim italic]"Las matemáticas también sienten,[/dim italic]
26
+ [dim italic] pero estas no se equivocan."[/dim italic]
27
+ ╚══════════════════════════════════════════════════════════╝[/bold orange1]
28
+
29
+ [dim]Comandos:[/dim]
30
+ [cyan]help[/cyan] - Lista de funciones disponibles
31
+ [cyan]exit[/cyan] - Salir
32
+ [cyan]cls[/cyan] - Limpiar pantalla
33
+
34
+ [dim]Pro Tip:[/dim] Usa [bold]sonify(expr)[/bold] para escuchar funciones o [bold]recta(p1, p2)[/bold] para geometría.
35
+
36
+ [dim]Ejemplos:[/dim]
37
+ derivar(cos^2(2x))
38
+ sonify(sin(440*2*pi*t))
39
+ distancia((0,0), (1,1))
40
+ """
41
+
42
+ HELP_TEXT = """
43
+ ## Funciones Disponibles
44
+
45
+ ### Cálculo
46
+ | Función | Ejemplo |
47
+ |---------|---------|
48
+ | `derivar(expr, var)` | `derivar(x^2, x)` `2*x` |
49
+ | `integrar(expr, var)` | `integrar(sin(x), x)` → `-cos(x)` |
50
+
51
+ ### Audio & Geometría (NUEVO)
52
+ | Función | Ejemplo |
53
+ |---------|---------|
54
+ | `sonify(expr)` | `sonify(sin(440t))` (Genera output.wav) |
55
+ | `distancia(p1, p2)` | `distancia((0,0), (3,4))` → `5` |
56
+ | `recta(p1, p2)` | `recta((0,0), (1,1))` → `y=x` |
57
+ | `limite(expr, var, punto)` | `limite(sin(x)/x, x, 0)` → `1` |
58
+ | `sumatoria(expr, var, a, b)` | `sumatoria(n^2, n, 1, 10)` |
59
+
60
+ ### Álgebra
61
+ | Función | Ejemplo |
62
+ |---------|---------|
63
+ | `simplificar(expr)` | `simplificar((x^2-1)/(x-1))` |
64
+ | `expandir(expr)` | `expandir((x+1)^2)` |
65
+ | `factorizar(expr)` | `factorizar(x^2-1)` |
66
+ | `resolver(expr, var)` | `resolver(x^2-4, x)` → `[-2, 2]` |
67
+
68
+ ### Estadística
69
+ | Función | Ejemplo |
70
+ |---------|---------|
71
+ | `media(...)` | `media(1, 2, 3, 4, 5)` → `3` |
72
+ | `mediana(...)` | `mediana(1, 2, 3, 4, 5)` → `3` |
73
+ | `desviacion(...)` | `desviacion(1, 2, 3, 4, 5)` |
74
+ | `varianza(...)` | `varianza(1, 2, 3, 4, 5)` |
75
+
76
+ ### Finanzas
77
+ | Función | Ejemplo |
78
+ |---------|---------|
79
+ | `van(tasa, flujo0, flujo1, ...)` | `van(0.10, -1000, 300, 400)` |
80
+ | `tir(flujo0, flujo1, ...)` | `tir(-1000, 300, 400, 500)` |
81
+ | `depreciar(costo, residual, años)` | `depreciar(10000, 1000, 5)` |
82
+ | `interes_simple(capital, tasa, tiempo)` | `interes_simple(1000, 0.05, 3)` |
83
+ | `interes_compuesto(capital, tasa, n, tiempo)` | `interes_compuesto(1000, 0.05, 12, 3)` |
84
+
85
+ ### Aliases y Accesos Directos
86
+ - **Shell**: Puedes ejecutar el programa como `binary-equalab`, `bneqls`, `beq` o `binary-math`.
87
+ - **Trigonometría**: `seno`=`sin`, `coseno`=`cos`, `tangente`=`tan`.
88
+ - **General**: `sonificar`=`sonify`, `derivada`=`derivar`.
89
+
90
+ """
91
+
92
+
93
+ def get_prompt_style():
94
+ return Style.from_dict({
95
+ 'prompt': '#ff6b35 bold',
96
+ })
97
+
98
+
99
+ def print_banner():
100
+ """Print the CLI banner using Rich panels."""
101
+ title = Text("Binary EquaLab CLI", style="bold white")
102
+ version = Text("Aurora v2.0.0", style="dim")
103
+ slogan = Text('"Las matemáticas también sienten,\npero estas no se equivocan."', style="dim italic")
104
+
105
+ content = Text.assemble(title, " ", version, "\n\n", slogan, justify="center")
106
+ panel = Panel(
107
+ content,
108
+ border_style="bold orange1",
109
+ expand=False,
110
+ subtitle="[dim]Escribe 'help' para ver comandos[/dim]"
111
+ )
112
+ console.print(panel)
113
+
114
+ def repl():
115
+ """Start the interactive REPL."""
116
+ print_banner()
117
+
118
+ engine = MathEngine()
119
+
120
+ # Setup history file
121
+ history_path = os.path.expanduser("~/.binary_math_history")
122
+ session: PromptSession = PromptSession(
123
+ history=FileHistory(history_path),
124
+ auto_suggest=AutoSuggestFromHistory(),
125
+ style=get_prompt_style(),
126
+ )
127
+
128
+ while True:
129
+ try:
130
+ # Read input
131
+ user_input = session.prompt([('class:prompt', '>>> ')]).strip()
132
+
133
+ if not user_input:
134
+ continue
135
+
136
+ # Handle special commands
137
+ cmd = user_input.lower()
138
+ if cmd in ('exit', 'quit', 'q'):
139
+ console.print("[dim]¡Hasta luego![/dim]")
140
+ break
141
+
142
+ if cmd in ('cls', 'clear'):
143
+ console.clear()
144
+ print_banner()
145
+ continue
146
+
147
+ if cmd == 'help':
148
+ console.print(Markdown(HELP_TEXT))
149
+ continue
150
+
151
+ if cmd == 'history':
152
+ for i, h in enumerate(engine.history[-10:], 1):
153
+ console.print(f"[dim]{i}.[/dim] {h}")
154
+ continue
155
+
156
+ # --- Easter Eggs ---
157
+ if cmd == 'binary':
158
+ console.print(Panel("[bold cyan]Las matemáticas también sienten.[/bold cyan]", border_style="cyan"))
159
+ continue
160
+ if cmd == 'aldra':
161
+ console.print(Panel("[bold magenta]De Aldra para la gente, gratis y con alma.[/bold magenta]", border_style="magenta"))
162
+ continue
163
+ if cmd == 'lupe':
164
+ console.print(Panel("[bold white]In Memoriam.[/bold white]", border_style="white"))
165
+ continue
166
+ # -------------------
167
+
168
+ # Evaluate expression
169
+ try:
170
+ result = engine.evaluate(user_input)
171
+
172
+ if result is None:
173
+ continue
174
+
175
+ # Format output
176
+ if isinstance(result, (list, tuple)):
177
+ console.print(f"[bold green]→[/bold green] {list(result)}")
178
+ elif isinstance(result, dict):
179
+ for key, value in result.items():
180
+ console.print(f" [cyan]{key}:[/cyan] {value}")
181
+ else:
182
+ console.print(f"[bold green]→[/bold green] {result}")
183
+
184
+ except Exception as e:
185
+ console.print(f"[bold red]Error:[/bold red] {e}")
186
+
187
+ except KeyboardInterrupt:
188
+ console.print()
189
+ continue
190
+ except EOFError:
191
+ console.print("\n[dim]¡Hasta luego![/dim]")
192
+ break
193
+
194
+
195
+ def one_liner(expression: str):
196
+ """Evaluate a single expression from command line."""
197
+ engine = MathEngine()
198
+ try:
199
+ result = engine.evaluate(expression)
200
+ if isinstance(result, (list, tuple)):
201
+ print(list(result))
202
+ elif isinstance(result, dict):
203
+ for key, value in result.items():
204
+ print(f"{key}: {value}")
205
+ else:
206
+ print(result)
207
+ except Exception as e:
208
+ print(f"Error: {e}", file=sys.stderr)
209
+ sys.exit(1)
210
+
211
+
212
+ def main():
213
+ """CLI entry point."""
214
+ if len(sys.argv) > 1 and sys.argv[1] == 'setup-shell':
215
+ from .shell_setup import run_setup
216
+ run_setup()
217
+ elif len(sys.argv) > 1 and sys.argv[1] == 'feedback':
218
+ import webbrowser
219
+ print("""
220
+ ╔═══════════════════════════════════════╗
221
+ ║ 💬 Feedback & Soporte ║
222
+ ╚═══════════════════════════════════════╝
223
+
224
+ ¡Gracias por usar Binary EquaLab! ❤️
225
+
226
+ Estoy abierto a cualquier sugerencia, apoyo, financiamiento,
227
+ compañía, o reporte de errores.
228
+
229
+ 🐛 Bugs / Mejoras: https://github.com/Malexnnn/BinaryEqualab/issues
230
+ 📧 Contacto: Ver perfil de GitHub
231
+ """)
232
+ webbrowser.open("https://github.com/Malexnnn/BinaryEqualab")
233
+
234
+ elif len(sys.argv) > 1:
235
+ # One-liner mode
236
+ expression = " ".join(sys.argv[1:])
237
+ one_liner(expression)
238
+ else:
239
+ # REPL mode
240
+ repl()
241
+
242
+
243
+ if __name__ == "__main__":
244
+ main()