Skip to content

Commit

Permalink
Merge pull request #80 from Elius94:Elius94/issue79
Browse files Browse the repository at this point in the history
[Bug]: InputPopup can handle strings
  • Loading branch information
Elius94 authored Nov 22, 2023
2 parents d58c9a6 + 3c02872 commit bb56887
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/box.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConsoleManager,ConfirmPopup, Box, InPageWidgetBuilder } from "../dist/esm/ConsoleGui.mjs"

const opt = {
title: "Progress Bar Test",
title: "Box Test",
layoutOptions: {
type: "single"
},
Expand Down
114 changes: 114 additions & 0 deletions examples/inputpopup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { ConsoleManager,ConfirmPopup, Box, InPageWidgetBuilder, InputPopup } from "../dist/esm/ConsoleGui.mjs"

const opt = {
title: "Input Popup Test",
layoutOptions: {
type: "single"
},
logLocation: "popup",
enableMouse: true
}

const GUI = new ConsoleManager(opt)

GUI.on("exit", () => {
closeApp()
})

let nValue = 0
let sValue = ""

GUI.on("keypressed", (key) => {
switch (key.name) {
case "q":
new ConfirmPopup({
id: "popupQuit", title: "Are you sure you want to quit?"
}).show().on("confirm", () => closeApp())
break
case "n":
new InputPopup({
id: "popupInput",
title: "Enter a number:",
value: nValue,
numeric: true
}).show().on("confirm", (value) => {
console.log(`You entered: ${value}`)
nValue = value
refresh()
})
break
case "s":
new InputPopup({
id: "popupInput",
title: "Enter a string:",
value: sValue,
numeric: false
}).show().on("confirm", (value) => {
console.log(`You entered: ${value}`)
sValue = value
refresh()
})
break
default:
break
}
})

const closeApp = () => {
console.clear()
process.exit()
}

const b = new Box({
id: "box",
x: 2,
y: 3,
width: 45,
height: 4,
style: {
boxed: true,
}
})

const content = new InPageWidgetBuilder()

content.addRow({
text: "Press 'n' to open a Numeric Input Popup",
color: "rgb(255,0,0)",
bg: "rgb(0,0,255)",
})

content.addRow({
text: "Press 's' to open a String Input Popup",
color: "blue",
})

b.setContent(content)

const b1 = new Box({
id: "box1",
x: 2,
y: 7,
width: 45,
height: 4,
style: {
boxed: true,
}
})


const refresh = () => {
const content1 = new InPageWidgetBuilder()
content1.clear()
content1.addRow({
text: `Numeric value: ${nValue}`,
color: "rgb(255,0,0)",
bg: "rgb(0,0,255)",
})
content1.addRow({
text: `String value: ${sValue}`,
color: "blue",
})
b1.setContent(content1)
GUI.refresh()
}
2 changes: 1 addition & 1 deletion src/components/widgets/InputPopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export class InputPopup extends EventEmitter {
}

confirmDel() {
this.emit("confirm", Number(this.value))
this.emit("confirm", this.numeric ? Number(this.value) : this.value)
this.delete()
}

Expand Down

0 comments on commit bb56887

Please sign in to comment.