[PDNCF] Python 3.12 compatibility
[platform/framework/web/chromium-efl.git] / tools / yes_no.py
1 # Copyright 2015 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from __future__ import print_function
6
7 import sys
8
9
10 def YesNo(prompt):
11   """Prompts with a yes/no question, returns True if yes."""
12   print(prompt, end=' ')
13   sys.stdout.flush()
14   # http://code.activestate.com/recipes/134892/
15   if sys.platform == 'win32':
16     import msvcrt
17     ch = msvcrt.getch()
18   else:
19     import termios
20     import tty
21     fd = sys.stdin.fileno()
22     old_settings = termios.tcgetattr(fd)
23     ch = 'n'
24     try:
25       tty.setraw(sys.stdin.fileno())
26       ch = sys.stdin.read(1)
27     finally:
28       termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
29   print(ch)
30   return ch in ('Y', 'y')