瀏覽代碼

fixed DBG nicePrint

Piotr Labudda 8 年之前
父節點
當前提交
56213a05a9
共有 2 個文件被更改,包括 8 次插入4 次删除
  1. 7 3
      SE/se-lib/DBG.php
  2. 1 1
      SE/se-lib/V.php

+ 7 - 3
SE/se-lib/DBG.php

@@ -200,7 +200,7 @@ class DBG {
 	public static function nicePrint($variable, $varName, $params = []) {
 		$col = ['green'=>'#96c178', 'red'=>'#de6b74', 'blue'=>'#55b5c1', 'bg-dark'=>'#282c34', 'white'=>'#abb2bf', 'orange'=>'#d19a66', 'violet'=>'#c476db'];
 		if (is_scalar($variable)) {
-			$outLines = [ substr((string)$variable, 0, 20) . (strlen((string)$variable) > 20 ? '...' : '' ), $variable ];
+			$outLines = [ V::strShort((string)$variable, 20), $variable ];
 		} else {
 			$cnt = '';
 			ob_start();
@@ -209,6 +209,7 @@ class DBG {
 
 			$outLines = array();
 			$lines = explode("\n", $cnt);
+			$firstLine = $lines[0];
 			foreach ($lines as $line) {
 				if ('(' == trim($line)) continue;
 				if (')' == trim($line)) continue;
@@ -229,10 +230,13 @@ class DBG {
 				$outLines[] = $line;
 			}
 		}
-		if ($varName) $outLines[0] = '<b style="color:'.$col['red'].'">' . $varName . "</b> => {$outLines[0]}";
 		$maxHeight = V::get('maxHeight', '400px', $params);
 		echo UI::h('details', ['style'=>"max-width:800px"], [
-			UI::h('summary', ['style'=>"padding:3px 8px;border:1px solid #ccc;background-color:{$col['bg-dark']};color:{$col['white']};font-size:small"], array_shift($outLines)),
+			UI::h('summary', ['style'=>"padding:3px 8px;border:1px solid #ccc;background-color:{$col['bg-dark']};color:{$col['white']};font-size:small"],
+				($varName)
+				?	'<b style="color:'.$col['red'].'">' . $varName . "</b> => " . htmlspecialchars(V::strShort($firstLine, 20))
+				: htmlspecialchars(V::strShort($firstLine, 20))
+			),
 			UI::h('pre', [
 				'style' => implode(";", [
 					'background-color:'.$col['bg-dark'],

+ 1 - 1
SE/se-lib/V.php

@@ -287,7 +287,7 @@ class V {
 		if (strlen($label) > $maxLength) {
 			$pos = strpos($label, ' - ');
 			if ($pos > $maxLength || $pos < 5) {
-				$label = substr($label, 0, $pos) . $suffix;
+				$label = substr($label, 0, $maxLength) . $suffix;
 			} else {
 				$label = substr($label, 0, $pos);
 			}