Improved handling of preformatted lines; other minor cleanups.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@848 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DefaultLogProvider.java,v 1.13 2002/09/23 20:33:04 mdb Exp $
|
// $Id: DefaultLogProvider.java,v 1.14 2002/09/24 07:57:40 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -109,36 +109,43 @@ public class DefaultLogProvider implements LogProvider
|
|||||||
// let the formatting continue to influence the module name and
|
// let the formatting continue to influence the module name and
|
||||||
// then it will be turned off when underlining is turned off
|
// then it will be turned off when underlining is turned off
|
||||||
|
|
||||||
// if we wrap, we include the module name in the wrapped text
|
// we include the module name on the first line
|
||||||
buf.append(_useVT100 ? TermUtil.UNDERLINE : "").append(moduleName);
|
buf.append(_useVT100 ? TermUtil.UNDERLINE : "").append(moduleName);
|
||||||
buf.append(_useVT100 ? TermUtil.PLAIN : "").append(": ");
|
buf.append(_useVT100 ? TermUtil.PLAIN : "").append(": ");
|
||||||
|
|
||||||
// we'll be wrapping the log lines
|
// if the text contains newlines, use those instead of wrapping
|
||||||
int wrapwid = _tdimens.width - GAP.length();
|
|
||||||
int remain = message.length(), offset = 0;
|
|
||||||
|
|
||||||
// if the text contains newlines, don't wrap it
|
|
||||||
if (message.indexOf("\n") != -1) {
|
if (message.indexOf("\n") != -1) {
|
||||||
wrapwid = Integer.MAX_VALUE;
|
String[] lines = StringUtil.split(message, "\n");
|
||||||
}
|
for (int ii = 0; ii < lines.length; ii++) {
|
||||||
|
if (ii > 0) {
|
||||||
|
buf.append("\n").append(GAP);
|
||||||
|
}
|
||||||
|
buf.append(lines[ii]);
|
||||||
|
}
|
||||||
|
|
||||||
// our first line contains additionally, the module name (and a
|
} else {
|
||||||
// colon and space) which must be accountded for when wrapping
|
// we'll be wrapping the log lines
|
||||||
int linewid = Math.min(wrapwid - moduleName.length() - 2, remain);
|
int wrapwid = _tdimens.width - GAP.length();
|
||||||
// int linewid = Math.min(wrapwid - moduleName.length() - 6, remain);
|
int remain = message.length(), offset = 0;
|
||||||
|
|
||||||
// append the first line
|
// our first line contains the module name (and a colon and
|
||||||
buf.append(message.substring(offset, offset+linewid));
|
// space) which must be accountded for when wrapping
|
||||||
remain -= linewid;
|
int lwid = Math.min(wrapwid - moduleName.length() - 2, remain);
|
||||||
offset += linewid;
|
// int lwid = Math.min(wrapwid - moduleName.length() - 6, remain);
|
||||||
|
|
||||||
// now append the wrapped lines (if there are any)
|
// append the first line
|
||||||
while (remain > 0) {
|
buf.append(message.substring(offset, offset+lwid));
|
||||||
buf.append("\n").append(GAP);
|
remain -= lwid;
|
||||||
linewid = Math.min(wrapwid, remain);
|
offset += lwid;
|
||||||
buf.append(message.substring(offset, offset+linewid));
|
|
||||||
remain -= linewid;
|
// now append the wrapped lines (if there are any)
|
||||||
offset += linewid;
|
while (remain > 0) {
|
||||||
|
buf.append("\n").append(GAP);
|
||||||
|
lwid = Math.min(wrapwid, remain);
|
||||||
|
buf.append(message.substring(offset, offset+lwid));
|
||||||
|
remain -= lwid;
|
||||||
|
offset += lwid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user