Fix dialog display for yesno and msgbox prompts
This commit is contained in:
committed by
Brandon McGinty
parent
0098afc595
commit
d35dda68fc
+15
-7
@@ -81,11 +81,18 @@ class ConfigError(Exception):
|
|||||||
DIALOG_OPTS = ["--insecure", "--no-lines", "--visit-items"]
|
DIALOG_OPTS = ["--insecure", "--no-lines", "--visit-items"]
|
||||||
|
|
||||||
|
|
||||||
def run_dialog(args, stdout=False):
|
def run_dialog(args, capture_result=False):
|
||||||
|
"""Run dialog.
|
||||||
|
|
||||||
|
dialog draws its widgets on stderr and writes the selected value on stdout
|
||||||
|
when --stdout is used. Keep stderr attached to the terminal for display and
|
||||||
|
only capture stdout when a result is needed.
|
||||||
|
"""
|
||||||
cmd = ["dialog", "--clear"] + DIALOG_OPTS + args
|
cmd = ["dialog", "--clear"] + DIALOG_OPTS + args
|
||||||
if stdout:
|
if capture_result:
|
||||||
cmd.append("--stdout")
|
cmd.append("--stdout")
|
||||||
return subprocess.run(cmd, capture_output=True, text=True)
|
return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=None, text=True)
|
||||||
|
return subprocess.run(cmd)
|
||||||
|
|
||||||
|
|
||||||
def msgbox(message):
|
def msgbox(message):
|
||||||
@@ -101,7 +108,8 @@ def yesno(question):
|
|||||||
question,
|
question,
|
||||||
"10",
|
"10",
|
||||||
"80",
|
"80",
|
||||||
]
|
],
|
||||||
|
capture_result=False,
|
||||||
)
|
)
|
||||||
return proc.returncode == 0
|
return proc.returncode == 0
|
||||||
|
|
||||||
@@ -117,7 +125,7 @@ def inputbox(instructions, initial=""):
|
|||||||
"0",
|
"0",
|
||||||
initial,
|
initial,
|
||||||
],
|
],
|
||||||
stdout=True,
|
capture_result=True,
|
||||||
)
|
)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
return None
|
return None
|
||||||
@@ -135,7 +143,7 @@ def passwordbox(instructions, initial=""):
|
|||||||
"0",
|
"0",
|
||||||
initial,
|
initial,
|
||||||
],
|
],
|
||||||
stdout=True,
|
capture_result=True,
|
||||||
)
|
)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
return None
|
return None
|
||||||
@@ -161,7 +169,7 @@ def menulist(options):
|
|||||||
"0",
|
"0",
|
||||||
]
|
]
|
||||||
+ items,
|
+ items,
|
||||||
stdout=True,
|
capture_result=True,
|
||||||
)
|
)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user