Component text can be truncated

- BaseComponentContext has new field terminalWidth.
- StringToStyleExpressionRenderer contains new format
  for "truncate-" prefixes and this is something
  what template can use to instruct max length based
  on terminal width.
- Change single/multi selectors to use this feature.
- Fixes #543
This commit is contained in:
Janne Valkealahti
2022-10-14 17:13:07 +01:00
parent 4c48017a97
commit feba345f00
11 changed files with 198 additions and 15 deletions

View File

@@ -1,10 +1,15 @@
// selector rows
truncate(name,model) ::= <%
<name; format={truncate-width:<model.terminalWidth>-prefix:5}>
%>
// used to select style if item is selected/unselected
selected_style(flag) ::= <%
<if(flag)>style-item-selected<else>style-item-unselected<endif>
%>
// selector rows
select_item(item) ::= <%
select_item(item,model) ::= <%
<if(item.onrow)>
<({<figures.rightPointingQuotation> }); format="style-item-selector">
<else>
@@ -13,16 +18,16 @@ select_item(item) ::= <%
<if(item.enabled)>
<if(item.selected)>
<({<figures.checkboxOn> }); format=selected_style(item.selected)> <item.name>
<({<figures.checkboxOn> }); format=selected_style(item.selected)> <truncate(item.name,model)>
<else>
<({<figures.checkboxOff> }); format=selected_style(item.selected)> <item.name>
<({<figures.checkboxOff> }); format=selected_style(item.selected)> <truncate(item.name,model)>
<endif>
<else>
<if(item.selected)>
<({<figures.checkboxOn> }); format="style-item-disabled"> <item.name; format="style-item-disabled">
<({<figures.checkboxOn> }); format="style-item-disabled"> <({<truncate(item.name,model)>}); format="style-item-disabled">
<else>
<({<figures.checkboxOff> }); format="style-item-disabled"> <item.name; format="style-item-disabled">
<endif>
<({<figures.checkboxOff> }); format="style-item-disabled"> <({<truncate(item.name,model)>}); format="style-item-disabled">
<endif>
<endif>
%>
@@ -58,7 +63,7 @@ result(model) ::= <<
// component is running
running(model) ::= <<
<question_name(model)> <info(model)>
<model.rows:{x|<select_item(x)>}; separator="\n">
<model.rows:{x|<select_item(x,model)>}; separator="\n">
>>
// main - hardcoded name

View File

@@ -1,9 +1,13 @@
// selector rows
select_item(item) ::= <%
truncate(name,model) ::= <%
<name; format={truncate-width:<model.terminalWidth>-prefix:2}>
%>
select_item(item,model) ::= <%
<if(item.selected)>
<({<figures.rightPointingQuotation> }); format="style-item-selector"><item.name; format="style-item-selector">
<({<figures.rightPointingQuotation> }); format="style-item-selector"><({<truncate(item.name,model)>}); format="style-item-selector">
<else>
<(" ")><item.name>
<(" ")><truncate(item.name,model)>
<endif>
%>
@@ -34,7 +38,7 @@ result(model) ::= <<
// component is running
running(model) ::= <<
<question_name(model)> <info(model)>
<model.rows:{x|<select_item(x)>}; separator="\n">
<model.rows:{x|<select_item(x,model)>}; separator="\n">
>>
// main - hardcoded name