From 18362ec61d634138f92b5f3678b03997c01f91bc Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Tue, 15 Nov 2016 16:53:03 -0800 Subject: [PATCH] Improve the debugDumpFoo output (#6882) --- .../flutter/lib/src/foundation/print.dart | 25 +++++++++++-------- .../flutter/lib/src/rendering/object.dart | 2 +- packages/flutter/lib/src/rendering/view.dart | 7 ++++++ .../flutter/lib/src/widgets/framework.dart | 18 +++---------- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/packages/flutter/lib/src/foundation/print.dart b/packages/flutter/lib/src/foundation/print.dart index 2f8975cdee..79fcfb9738 100644 --- a/packages/flutter/lib/src/foundation/print.dart +++ b/packages/flutter/lib/src/foundation/print.dart @@ -80,24 +80,27 @@ final RegExp _indentPattern = new RegExp('^ *(?:[-+*] |[0-9]+[.):] )?'); enum _WordWrapParseMode { inSpace, inWord, atBreak } /// Wraps the given string at the given width. /// -/// Wrapping occurs at space characters (U+0020). Lines that start -/// with an octothorpe ("#", U+0023) are not wrapped (so for example, -/// Dart stack traces won't be wrapped). +/// Wrapping occurs at space characters (U+0020). Lines that start with an +/// octothorpe ("#", U+0023) are not wrapped (so for example, Dart stack traces +/// won't be wrapped). /// -/// This is not suitable for use with arbitrary Unicode text. For -/// example, it doesn't implement UAX #14, can't handle ideographic -/// text, doesn't hyphenate, and so forth. It is only intended for -/// formatting error messages. +/// Subsequent lines attempt to duplicate the indentation of the first line, for +/// example if the first line starts with multiple spaces. In addition, if a +/// `wrapIndent` argument is provided, each line after the first is prefixed by +/// that string. /// -/// The default [debugPrint] implementation uses this for its line -/// wrapping. -Iterable debugWordWrap(String message, int width) sync* { +/// This is not suitable for use with arbitrary Unicode text. For example, it +/// doesn't implement UAX #14, can't handle ideographic text, doesn't hyphenate, +/// and so forth. It is only intended for formatting error messages. +/// +/// The default [debugPrint] implementation uses this for its line wrapping. +Iterable debugWordWrap(String message, int width, { String wrapIndent: '' }) sync* { if (message.length < width || message[0] == '#') { yield message; return; } Match prefixMatch = _indentPattern.matchAsPrefix(message); - String prefix = ' ' * prefixMatch.group(0).length; + String prefix = wrapIndent + ' ' * prefixMatch.group(0).length; int start = 0; int startForLengthCalculations = 0; bool addPrefix = false; diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index ae46cdd424..8d0958c63a 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -2410,7 +2410,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { List description = []; debugFillDescription(description); result += description - .expand((String description) => description.split('\n')) + .expand((String description) => debugWordWrap(description, 65, wrapIndent: ' ')) .map/**/((String line) => "$descriptionPrefix$line\n") .join(); if (childrenDescription == '') diff --git a/packages/flutter/lib/src/rendering/view.dart b/packages/flutter/lib/src/rendering/view.dart index 248c9d657d..6d6d57b9e3 100644 --- a/packages/flutter/lib/src/rendering/view.dart +++ b/packages/flutter/lib/src/rendering/view.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:developer'; +import 'dart:io' show Platform; import 'dart:ui' as ui show Scene, SceneBuilder, window; import 'package:vector_math/vector_math_64.dart'; @@ -171,8 +172,14 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin @override void debugFillDescription(List description) { // call to ${super.debugFillDescription(prefix)} is omitted because the root superclasses don't include any interesting information for this class + assert(() { + description.add('debug mode enabled - ${Platform.operatingSystem}'); + return true; + }); description.add('window size: ${ui.window.physicalSize} (in physical pixels)'); description.add('device pixel ratio: ${ui.window.devicePixelRatio} (physical pixels per logical pixel)'); description.add('configuration: $configuration (in logical pixels)'); + if (ui.window.semanticsEnabled) + description.add('semantics enabled'); } } diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 4b24d6248b..7af0406cec 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -2578,19 +2578,7 @@ abstract class Element implements BuildContext { } if (node != null) chain.add('\u22EF'); - String result = ''; - String line = ''; - for (String link in chain) { - if (line != '') - line += ' \u2190 '; - if (link.length > 3 && line.length + link.length > 65) { - result += '$line\n'; - line = ' '; - } - line += link; - } - result += line; - return result; + return chain.join(' \u2190 '); } /// A short, textual description of this element. @@ -2637,8 +2625,8 @@ abstract class Element implements BuildContext { if (children.length > 0) { Element last = children.removeLast(); for (Element child in children) - result += '${child.toStringDeep("$prefixOtherLines \u251C", "$prefixOtherLines \u2502")}'; - result += '${last.toStringDeep("$prefixOtherLines \u2514", "$prefixOtherLines ")}'; + result += '${child.toStringDeep("$prefixOtherLines\u251C", "$prefixOtherLines\u2502")}'; + result += '${last.toStringDeep("$prefixOtherLines\u2514", "$prefixOtherLines ")}'; } return result; }