MyST-NB icon indicating copy to clipboard operation
MyST-NB copied to clipboard

Combine multiple stream output and maintain spacing like in Jupyter lab

Open bpuchala opened this issue 4 months ago • 4 comments

Context

I may be overlooking a configuration option, but it seems like there is no way to configure formatting output like the following to appear in a single output cell like in Jupyter lab:

{
   "cell_type": "code",
   "execution_count": 4,
   "id": "0d81eb38-8ea4-4856-be7e-1c2d335b81a8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-- Begin: Enumerating occupations by supercell --\n",
      "\n",
      "Enumerate configurations for: SCEL1_1_1_1_0_0_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL2_2_1_1_0_1_1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL2_2_1_1_0_0_1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL3_3_1_1_0_2_2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL3_3_1_1_0_2_1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL3_3_1_1_0_0_2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_0_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "36 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_1_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "27 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_0_2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "36 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_0_3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_4_1_1_0_2_1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_2_2_1_0_1_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "23 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enumerate configurations for: SCEL4_2_2_1_1_1_0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 configurations (0 new, 0 excluded by filter)\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  DONE\n",
      "\n",
      "-- Summary --\n",
      "\n",
      "  Initial number of configurations: 214\n",
      "  Final number of configurations: 214\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Committing...\n",
      "\n",
      "EnumData:\n",
      "- id: main\n",
      "- supercell_set: 13 supercells\n",
      "- configuration_set: 214 configurations\n",
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "overwrite: SiGe_occ/enumerations/enum.main/scel_set.json\n",
      "overwrite: SiGe_occ/enumerations/enum.main/config_set.json\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Enumerate configurations in supercells with volume 1 to 4\n",
    "# - Configurations are stored in the enumeration's ConfigurationSet\n",
    "enum = project.enum.get(id=\"main\")\n",
    "enum.occ_by_supercell(max=4, min=1)"
   ]
  },

I either get multiple outputs like this:

Image

Or, with nb_merge_streams = True I get a single output with missing newlines like this:

Image

What I want is like this from Jupyter lab:

Image

Proposal

No response

Tasks and updates

No response

bpuchala avatar Aug 28 '25 17:08 bpuchala

I recall this was fixed, what version do you use when you see this?

bsipocz avatar Aug 28 '25 17:08 bsipocz

myst-nb==1.3.0 myst-parser==4.0.1

bpuchala avatar Aug 28 '25 17:08 bpuchala

Ahh, my bad, I misremembered that issue and it was just about better documenting `nb_merge_streams

bsipocz avatar Aug 28 '25 18:08 bsipocz

It's related to #604 and #640 but I don't really understand why rstrip is needed for that case.

bpuchala avatar Aug 28 '25 20:08 bpuchala