How to align text elements of more lines [message #1697380] |
Wed, 03 June 2015 14:00 |
Jiang Li Messages: 27 Registered: November 2014 |
Junior Member |
|
|
I have text with following format:
dummy_command1 ? my_condition
dummy_command123 ? my_condition
dummy_command123456 ? my_condition
This demo text consists of more lines. Each line has the same format "command ? condition". Ich want to align the elements "? condition" for all lines
just like this:
dummy_command1 ? my_condition
dummy_command123 ? my_condition
dummy_command123456 ? my_condition
How can i do it ? Is there any better formatting api than "*.prepend/*.append/*.surround" ?
[Updated on: Wed, 03 June 2015 14:07] Report message to a moderator
|
|
|
|
Re: How to align text elements of more lines [message #1697394 is a reply to message #1697381] |
Wed, 03 June 2015 15:08 |
|
why not prepend/append
Model:
lines+=Line*;
Line:
name=ID '?' value=ID; def dispatch void format(Model model, extension IFormattableDocument document) {
val width = model.lines.map[regionFor.feature(MyDslPackage.Literals.LINE__NAME).length].max
for (Line line : model.getLines()) {
val region = line.regionFor.feature(MyDslPackage.Literals.LINE__NAME)
val s = Strings.repeat(" ", width-region.length+1)
region.append[space = s]
line.regionFor.keyword("?").append[space=" "]
line.regionFor.feature(MyDslPackage.Literals.LINE__VALUE).append[newLine]
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04624 seconds