@icarusmx/creta 1.0.18 → 1.0.20

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.
package/bin/creta.js CHANGED
@@ -790,9 +790,9 @@ async function startEnunciadosSelectorInteractive() {
790
790
  process.stdout.write('\x1b[H')
791
791
 
792
792
  console.log("Los enunciados fundamentales son un conjunto de afirmaciones que tienen el propósito de ejercitar el pensamiento orientado a objetos de los estudiantes de Creta. Escogimos estos enunciados porque creemos que exhaustan los conceptos mínimos necesarios para entender el paradigma de la programación orientada a objetos.")
793
- console.log("")
794
- console.log("Elige qué enunciado te gustaría explorar:")
795
- console.log("")
793
+ console.log("")
794
+ console.log("Elige qué enunciado te gustaría explorar:")
795
+ console.log("")
796
796
 
797
797
  ENUNCIADOS.forEach((enunciado, index) => {
798
798
  const isSelected = index === selectedIndex
@@ -989,9 +989,9 @@ async function startEnunciadosSelectorFallback() {
989
989
 
990
990
  try {
991
991
  console.log("Los enunciados fundamentales son un conjunto de afirmaciones que tienen el propósito de ejercitar el pensamiento orientado a objetos de los estudiantes de Creta. Escogimos estos enunciados porque creemos que exhaustan los conceptos mínimos necesarios para entender el paradigma de la programación orientada a objetos.")
992
- console.log("")
993
- console.log("Elige qué enunciado te gustaría explorar:")
994
- console.log("")
992
+ console.log("")
993
+ console.log("Elige qué enunciado te gustaría explorar:")
994
+ console.log("")
995
995
 
996
996
  ENUNCIADOS.forEach((enunciado, index) => {
997
997
  // Format the enunciado text with proper indentation for lists
@@ -94,86 +94,84 @@ export class Lesson1SystemDecomposition {
94
94
  console.clear()
95
95
  console.log("Descomposición en objetos:")
96
96
 
97
- console.log("\n📄 Clase Book:")
98
- console.log("━".repeat(50))
99
- console.log("class Book {")
100
- console.log(" constructor(title, author, isbn) {")
101
- console.log(" this.title = title")
102
- console.log(" this.author = author")
103
- console.log(" this.isbn = isbn")
104
- console.log(" this.isLoaned = false")
105
- console.log(" }")
106
- console.log("")
107
- console.log(" isAvailable() {")
108
- console.log(" return !this.isLoaned")
109
- console.log(" }")
110
- console.log("")
111
- console.log(" markAsLoaned() {")
112
- console.log(" this.isLoaned = true")
113
- console.log(" }")
114
- console.log("")
115
- console.log(" markAsReturned() {")
116
- console.log(" this.isLoaned = false")
117
- console.log(" }")
118
- console.log("}")
119
- console.log("━".repeat(50))
97
+ const bookCode = `class Book {
98
+ constructor(title, author, isbn) {
99
+ this.title = title
100
+ this.author = author
101
+ this.isbn = isbn
102
+ this.isLoaned = false
103
+ }
104
+
105
+ isAvailable() {
106
+ return !this.isLoaned
107
+ }
108
+
109
+ markAsLoaned() {
110
+ this.isLoaned = true
111
+ }
112
+
113
+ markAsReturned() {
114
+ this.isLoaned = false
115
+ }
116
+ }`
117
+
118
+ this.printCodeWithOutline("📄 Clase Book", bookCode)
120
119
 
121
120
  await this.waitForEnter("\nPresiona Enter para ver User...")
122
121
 
123
- console.log("\n📄 Clase User:")
124
- console.log("━".repeat(50))
125
- console.log("class User {")
126
- console.log(" constructor(name, email, maxLoans = 3) {")
127
- console.log(" this.name = name")
128
- console.log(" this.email = email")
129
- console.log(" this.maxLoans = maxLoans")
130
- console.log(" this.currentLoans = []")
131
- console.log(" }")
132
- console.log("")
133
- console.log(" canBorrow() {")
134
- console.log(" return this.currentLoans.length < this.maxLoans")
135
- console.log(" }")
136
- console.log("")
137
- console.log(" addLoan(loan) {")
138
- console.log(" this.currentLoans.push(loan)")
139
- console.log(" }")
140
- console.log("")
141
- console.log(" removeLoan(loan) {")
142
- console.log(" const index = this.currentLoans.indexOf(loan)")
143
- console.log(" if (index > -1) this.currentLoans.splice(index, 1)")
144
- console.log(" }")
145
- console.log("}")
146
- console.log("━".repeat(50))
122
+ const userCode = `class User {
123
+ constructor(name, email, maxLoans = 3) {
124
+ this.name = name
125
+ this.email = email
126
+ this.maxLoans = maxLoans
127
+ this.currentLoans = []
128
+ }
129
+
130
+ canBorrow() {
131
+ return this.currentLoans.length < this.maxLoans
132
+ }
133
+
134
+ addLoan(loan) {
135
+ this.currentLoans.push(loan)
136
+ }
137
+
138
+ removeLoan(loan) {
139
+ const index = this.currentLoans.indexOf(loan)
140
+ if (index > -1) this.currentLoans.splice(index, 1)
141
+ }
142
+ }`
143
+
144
+ this.printCodeWithOutline("📄 Clase User", userCode)
147
145
 
148
146
  await this.waitForEnter("\nPresiona Enter para ver Loan...")
149
147
 
150
- console.log("\n📄 Clase Loan:")
151
- console.log("━".repeat(50))
152
- console.log("class Loan {")
153
- console.log(" constructor(user, book, durationDays = 14) {")
154
- console.log(" this.user = user")
155
- console.log(" this.book = book")
156
- console.log(" this.startDate = new Date()")
157
- console.log(" this.dueDate = new Date(Date.now() + durationDays * 24 * 60 * 60 * 1000)")
158
- console.log(" this.returned = false")
159
- console.log(" }")
160
- console.log("")
161
- console.log(" isOverdue() {")
162
- console.log(" return !this.returned && new Date() > this.dueDate")
163
- console.log(" }")
164
- console.log("")
165
- console.log(" calculateFine() {")
166
- console.log(" if (!this.isOverdue()) return 0")
167
- console.log(" const daysLate = Math.ceil((new Date() - this.dueDate) / (24 * 60 * 60 * 1000))")
168
- console.log(" return daysLate * 5 // $5 por día")
169
- console.log(" }")
170
- console.log("")
171
- console.log(" returnBook() {")
172
- console.log(" this.returned = true")
173
- console.log(" this.book.markAsReturned()")
174
- console.log(" this.user.removeLoan(this)")
175
- console.log(" }")
176
- console.log("}")
148
+ const loanCode = `class Loan {
149
+ constructor(user, book, durationDays = 14) {
150
+ this.user = user
151
+ this.book = book
152
+ this.startDate = new Date()
153
+ this.dueDate = new Date(Date.now() + durationDays * 24 * 60 * 60 * 1000)
154
+ this.returned = false
155
+ }
156
+
157
+ isOverdue() {
158
+ return !this.returned && new Date() > this.dueDate
159
+ }
160
+
161
+ calculateFine() {
162
+ if (!this.isOverdue()) return 0
163
+ const daysLate = Math.ceil((new Date() - this.dueDate) / (24 * 60 * 60 * 1000))
164
+ return daysLate * 5 // $5 por día
165
+ }
166
+
167
+ returnBook() {
168
+ this.returned = true
169
+ this.book.markAsReturned()
170
+ this.user.removeLoan(this)
171
+ }
172
+ }`
173
+
174
+ this.printCodeWithOutline("📄 Clase Loan", loanCode)
177
175
 
178
176
  await this.waitForEnter("\nPresiona Enter para ver Library...")
179
177
 
@@ -268,6 +266,42 @@ export class Lesson1SystemDecomposition {
268
266
  await this.waitForEnter("\n✨ ¡Lección 1 completada! Presiona Enter para continuar...")
269
267
  }
270
268
 
269
+ formatCode(code) {
270
+ // ANSI color codes
271
+ const colors = {
272
+ keyword: '\x1b[35m', // magenta for keywords like class, constructor
273
+ property: '\x1b[32m', // green for this.property
274
+ string: '\x1b[33m', // yellow for strings
275
+ comment: '\x1b[90m', // gray for comments
276
+ reset: '\x1b[0m' // reset color
277
+ }
278
+
279
+ return code
280
+ .replace(/\b(class|constructor|return|if|const|let|new)\b/g, `${colors.keyword}$1${colors.reset}`)
281
+ .replace(/\bthis\./g, `${colors.property}this.${colors.reset}`)
282
+ .replace(/'([^']*)'/g, `${colors.string}'$1'${colors.reset}`)
283
+ .replace(/"([^"]*)"/g, `${colors.string}"$1"${colors.reset}`)
284
+ .replace(/\/\/.*$/gm, `${colors.comment}$&${colors.reset}`)
285
+ }
286
+
287
+ printCodeWithOutline(title, code) {
288
+ const border = '┌' + '─'.repeat(60) + '┐'
289
+ const bottomBorder = '└' + '─'.repeat(60) + '┘'
290
+ const titleLine = `│ ${title}${' '.repeat(60 - title.length - 1)}│`
291
+
292
+ console.log(`\n${border}`)
293
+ console.log(titleLine)
294
+ console.log('├' + '─'.repeat(60) + '┤')
295
+
296
+ code.split('\n').forEach(line => {
297
+ const formattedLine = this.formatCode(line)
298
+ const padding = ' '.repeat(Math.max(0, 58 - line.length))
299
+ console.log(`│ ${formattedLine}${padding}│`)
300
+ })
301
+
302
+ console.log(bottomBorder)
303
+ }
304
+
271
305
  async waitForEnter(message) {
272
306
  return new Promise((resolve) => {
273
307
  this.rl.question(message, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icarusmx/creta",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "Salgamos de este laberinto.",
5
5
  "type": "module",
6
6
  "bin": {