Skip to content

Commit

Permalink
[FEATURE] Issue #5. The from-part of a transition only printed once, …
Browse files Browse the repository at this point in the history
…padding added.
  • Loading branch information
cepsdev committed Jun 14, 2021
1 parent 037aca6 commit 61a4a1b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
44 changes: 43 additions & 1 deletion core/src/docgen/docgenerator_statemachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ void ceps::docgen::Statemachine::print( std::ostream& os,
if (s1 == s2) return default_text_representation(lhs.to) <= default_text_representation(rhs.to);
else return s1 <= s2;
});
std::string last_from_state_name;
auto max_from_len = 0;
for(auto t : transitions){
auto s = default_text_representation(t.from);
if (s.length() > max_from_len) max_from_len = s.length();
}

for(auto t : transitions){
{
doc_writer->push_ctx();
Expand All @@ -185,7 +192,42 @@ void ceps::docgen::Statemachine::print( std::ostream& os,
doc_writer->out(os,"");
doc_writer->pop_ctx();
}
fmt_out_handle_expr(os,t.from, doc_writer);

auto st = default_text_representation(t.from);

if (st.length() > 0 && last_from_state_name.length() > 0 && st != last_from_state_name){
doc_writer->push_ctx();
doc_writer->top().suffix="";
doc_writer->out(os,"");
doc_writer->top().eol = "";
doc_writer->top().prefix ="";
doc_writer->out(os,"");
doc_writer->pop_ctx();
}

if (st != last_from_state_name) {
fmt_out_handle_expr(os,t.from, doc_writer);
doc_writer->push_ctx();
doc_writer->top().suffix = doc_writer->top().prefix = doc_writer->top().eol = "";
doc_writer->top().ignore_indent = true;
doc_writer->top().normal_intensity =true;
doc_writer->out(os, ([&](){std::string s = "";
for(size_t i = 0; i < max_from_len - st.length(); ++i) s.append(" ");
return s;})());
doc_writer->pop_ctx();
}
else {
doc_writer->push_ctx();
doc_writer->top().suffix = doc_writer->top().prefix = doc_writer->top().eol = "";
doc_writer->top().ignore_indent = true;
doc_writer->top().normal_intensity =true;
doc_writer->out(os, ([&](){std::string s = "";
for(size_t i = 0; i < max_from_len; ++i) s.append(" ");
return s;})());
doc_writer->pop_ctx();
}
last_from_state_name = st;

{
doc_writer->push_ctx();
doc_writer->top().ignore_indent=true;
Expand Down
3 changes: 2 additions & 1 deletion core/src/docgen/docgenerator_theme_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function.call.name -> 184*/
{ "keyword.state_machine",color{5}},
{ "state_machine.state_name",color{148}},
{ "keyword.state_machine_states", color{144}},
{ "keyword.state_machine_transitions", color{131}}
{ "keyword.state_machine_transitions", color{144}},
{ "keyword.state_machine_actions", color{144}}


}
Expand Down

0 comments on commit 61a4a1b

Please sign in to comment.