提交 016dfc68 编写于 作者: O openharmony_ci 提交者: Gitee

!85 hb 产品选择界面优化

Merge pull request !85 from pilipala195/master
......@@ -51,7 +51,7 @@ class Device():
menu = Menuconfig()
kernel = menu.list_promt('kernel',
'Which kernel do you need?',
choices).get('kernel')
choices).get('kernel')[0]
return kernel_path_dict.get(kernel), kernel.split('@')[0],\
os.path.basename(cwd)
......
......@@ -21,6 +21,7 @@ from collections import defaultdict
from hb.common.utils import read_json_file
from hb.common.config import Config
from hb.cts.menuconfig import Menuconfig
from hb.cts.common import Separator
class Product():
......@@ -93,16 +94,25 @@ class Product():
@staticmethod
def product_menuconfig():
product_path_dict = {}
company_separator = None
for company, product, product_path in Product.get_products():
if company_separator is None or company_separator != company:
company_separator = company
product_key = Separator(company_separator)
product_path_dict[product_key] = None
product_path_dict['{}@{}'.format(product, company)] = product_path
if not len(product_path_dict):
raise Exception('no valid product found')
choices = [{'name': product} for product in product_path_dict.keys()]
choices = [product if isinstance(product, Separator)
else {'name': product.split('@')[0],
'value': product.split('@')[1]}
for product in product_path_dict.keys()]
menu = Menuconfig()
product = menu.list_promt('product',
'Which product do you need?',
choices).get('product')
return product_path_dict.get(product), product.split('@')[0]
product_key = f'{product[0]}@{product[1]}'
return product_path_dict.get(product_key), product[0]
......@@ -16,7 +16,6 @@
# limitations under the License.
import os
import json
try:
from queue import Queue
except ImportError:
......@@ -33,7 +32,7 @@ from hb.common.utils import read_json_file
def get_style(style_type):
if style_type == 'terminal':
return style_from_dict({
Token.Separator: '#6C6C6C',
Token.Separator: '#75c951',
Token.QuestionMark: '#5F819D',
Token.Selected: '', # default
Token.Pointer: '#FF9D00 bold', # AWS orange
......@@ -43,7 +42,7 @@ def get_style(style_type):
})
if style_type == 'answer':
return style_from_dict({
Token.Separator: '#cc5454',
Token.Separator: '#75c951',
Token.QuestionMark: '#E91E63 bold',
Token.Selected: '#cc5454', # default
Token.Pointer: '#ed9164 bold',
......@@ -189,7 +188,7 @@ class Separator(object):
def __init__(self, line=None):
if line:
self.line = line
self.line = f'\n{line}'
def __str__(self):
return self.line
......@@ -88,12 +88,17 @@ class InquirerControl(TokenListControl):
tokens.append((token.Selected if selected else token,
'- %s (%s)' % (choice[0], choice[2])))
else:
try:
tokens.append((token.Selected if selected else token,
str(choice[0]), select_item))
except Exception:
tokens.append((token.Selected if selected else
token, choice[0], select_item))
if isinstance(choice[0], Separator):
tokens.append((token.Separator,
str(choice[0]),
select_item))
else:
try:
tokens.append((token.Selected if selected else token,
str(choice[0]), select_item))
except Exception:
tokens.append((token.Selected if selected else
token, choice[0], select_item))
tokens.append((token, '\n'))
# prepare the select choices
......@@ -175,7 +180,7 @@ def question(message, **kwargs):
@manager.registry.add_binding(Keys.Enter, eager=True)
def set_answer(event):
inquirer_control.answered = True
event.cli.set_return_value(inquirer_control.get_selection()[1])
event.cli.set_return_value(inquirer_control.get_selection())
return Application(
layout=layout,
......
......@@ -15,12 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from hb.cts.prompt import prompt
from hb.cts.common import Separator
from hb.cts.common import get_style
from hb.cts.cts import CTS
from hb.common.utils import hb_info
class Menuconfig():
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册