-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for #1151 - Add line numbers and current line marker to secondary prompt #1152
base: master
Are you sure you want to change the base?
Changes from all commits
24495f2
b6edb29
6c5d4e9
0d18925
568990f
91033e6
c3ccc19
43fcfa6
225600a
096ac10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,6 +292,7 @@ protected enum BellType { | |
|
||
protected String alternateIn; | ||
protected String alternateOut; | ||
protected List<AttributedString> currentLines; | ||
|
||
public LineReaderImpl(Terminal terminal) throws IOException { | ||
this(terminal, terminal.getName(), null); | ||
|
@@ -4176,6 +4177,16 @@ private AttributedString expandPromptPattern(String pattern, int padToWidth, Str | |
case 'N': | ||
sb.append(getInt(LINE_OFFSET, 0) + line); | ||
break decode; | ||
case 'C': | ||
sb.append(getInt(LINE_OFFSET, 0) + (line + 1)); | ||
break decode; | ||
case '*': | ||
if (getCurrentLineNo(this.currentLines) == line) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can do this because, in a secondary prompt, the number of lines may change with each new user input. Therefore, I need to ensure that I always get the updated number of lines. |
||
sb.append("*"); | ||
} else { | ||
sb.append(" "); | ||
} | ||
break decode; | ||
case 'M': | ||
if (message != null) sb.append(message); | ||
break decode; | ||
|
@@ -4231,6 +4242,21 @@ private AttributedString expandPromptPattern(String pattern, int padToWidth, Str | |
return AttributedString.join(null, parts); | ||
} | ||
|
||
private int getCurrentLineNo(List<AttributedString> lines) { | ||
int currentLine = -1; | ||
int cursor = buf.cursor(); | ||
int start = 0; | ||
for (int l = 0; l < lines.size(); l++) { | ||
int end = start + lines.get(l).length(); | ||
if (cursor >= start && cursor <= end) { | ||
currentLine = l; | ||
break; | ||
} | ||
start = end + 1; | ||
} | ||
return currentLine; | ||
} | ||
|
||
private AttributedString fromAnsi(String str) { | ||
return AttributedString.fromAnsi(str, Collections.singletonList(0), alternateIn, alternateOut); | ||
} | ||
|
@@ -4277,6 +4303,7 @@ private AttributedString insertSecondaryPrompts( | |
buf.setLength(0); | ||
} | ||
int line = 0; | ||
this.currentLines = lines; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we compute the currentLine easier, maybe we can store only that information instead of the list of lines ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I'll compute directly the currentLine. |
||
while (line < lines.size() - 1) { | ||
sb.append(lines.get(line)).append("\n"); | ||
buf.append(lines.get(line)).append("\n"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this new
C
option ? it seems to me that settingLINE_OFFSET
to1
would achieve the same ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
C
option used to handle this pattern%5P %C%*
for numbering the new secondary prompt lines