With this implementation the option ColumnWidths in fact determines the maximum column width, because when we reduce the window width, columns will become even narrower. Hence the minimal column width is actually determined by the minimal width of the whole Grid.
With this implementation the option ColumnWidths in fact determines the maximum column width, because when we reduce the window width, columns will become even narrower. Hence the minimal column width is actually determined by the minimal width of the whole Grid.
PrettyPrint[args__] := Print@Module[{tab, newline}, Grid[Map[RowGrid[Map[TextCell[Row[#]] &, Split[#, # =!= tab &] & /@ Split[Flatten[ Replace[{args}, {s_String :> StringSplit[s, {"\t" -> tab, "\n" -> newline}]}, 1], 1], # =!= newline &], {2}] /. {tab | newline -> Nothing}, Alignment -> Left]] If you reduce the width of the Notebook window, columns widths are automatically adapted and proper word-wrapping is applied to long rows of text:
With an example TSV file imported as "Text":
Options[PrettyPrint] = {ColumnWidths -> Automatic}; PrettyPrint[args__] := Print@Module[{tab, newline}, Grid[Map[Row[#Grid[Map[TextCell[Row[#], ImageSize PageWidth -> OptionValue[Options[PrettyPrint], ColumnWidths]] &, Split[#, # =!= tab &] & /@ Split[Flatten[ Replace[{args}, {s_String :> StringSplit[s, {"\t" -> tab, "\n" -> newline}]}, 1], 1], # =!= newline &], {2}] /. {tab | newline -> Nothing}, Alignment -> Left]] PrettyPrint[args__] := Print@Module[{tab, newline}, Grid[Map[Row, Split[#, # =!= tab &] & /@ Split[Flatten[ Replace[{args}, {s_String :> StringSplit[s, {"\t" -> tab, "\n" -> newline}]}, 1], 1], # =!= newline &], {2}] /. {tab | newline -> Nothing}, Alignment -> Left]] With an example TSV file:
Options[PrettyPrint] = {ColumnWidths -> Automatic}; PrettyPrint[args__] := Print@Module[{tab, newline}, Grid[Map[Row[#, ImageSize -> OptionValue[Options[PrettyPrint], ColumnWidths]] &, Split[#, # =!= tab &] & /@ Split[Flatten[ Replace[{args}, {s_String :> StringSplit[s, {"\t" -> tab, "\n" -> newline}]}, 1], 1], # =!= newline &], {2}] /. {tab | newline -> Nothing}, Alignment -> Left]] PrettyPrint[args__] := Print@Module[{tab, newline}, Grid[Map[TextCell[Row[#]] &, Split[#, # =!= tab &] & /@ Split[Flatten[ Replace[{args}, {s_String :> StringSplit[s, {"\t" -> tab, "\n" -> newline}]}, 1], 1], # =!= newline &], {2}] /. {tab | newline -> Nothing}, Alignment -> Left]] If you reduce the width of the Notebook window, columns widths are automatically adapted and proper word-wrapping is applied to long rows of text:
With an example TSV file imported as "Text":
Options[PrettyPrint] = {ColumnWidths -> Automatic}; PrettyPrint[args__] := Print@Module[{tab, newline}, Grid[Map[TextCell[Row[#], PageWidth -> OptionValue[Options[PrettyPrint], ColumnWidths]] &, Split[#, # =!= tab &] & /@ Split[Flatten[ Replace[{args}, {s_String :> StringSplit[s, {"\t" -> tab, "\n" -> newline}]}, 1], 1], # =!= newline &], {2}] /. {tab | newline -> Nothing}, Alignment -> Left]] You know that Print doesn't have options, because itsit must print arguments can be anythingof any type, including options. Hence if you want to handle options, you need either other syntax, or specify options separately.
You know that Print doesn't have options, because its arguments can be anything, including options. Hence if you want to handle options, you need either other syntax, or specify options separately.
You know that Print doesn't have options, because it must print arguments of any type, including options. Hence if you want to handle options, you need either other syntax, or specify options separately.



